CBG-1599
(t *testing.T)
| 1529 | |
| 1530 | // CBG-1599 |
| 1531 | func TestClientTLSMissing(t *testing.T) { |
| 1532 | base.SetUpTestLogging(t, base.LevelInfo, base.KeyAll) |
| 1533 | errorTLSOneMissing := "both TLS Key Path and TLS Cert Path must be provided when using client TLS. Disable client TLS by not providing either of these options" |
| 1534 | testCases := []struct { |
| 1535 | name string |
| 1536 | tlsKey bool |
| 1537 | tlsCert bool |
| 1538 | expectError bool |
| 1539 | }{ |
| 1540 | { |
| 1541 | name: "No TLS", |
| 1542 | expectError: false, |
| 1543 | }, |
| 1544 | { |
| 1545 | name: "TLS Key but no cert provided", |
| 1546 | tlsKey: true, |
| 1547 | expectError: true, |
| 1548 | }, |
| 1549 | { |
| 1550 | name: "TLS Cert but no key provided", |
| 1551 | tlsCert: true, |
| 1552 | expectError: true, |
| 1553 | }, |
| 1554 | { |
| 1555 | name: "TLS Cert and key provided", |
| 1556 | tlsKey: true, |
| 1557 | tlsCert: true, |
| 1558 | expectError: false, |
| 1559 | }, |
| 1560 | } |
| 1561 | for _, test := range testCases { |
| 1562 | t.Run(test.name, func(t *testing.T) { |
| 1563 | config := StartupConfig{} |
| 1564 | if test.tlsKey { |
| 1565 | config.API.HTTPS.TLSKeyPath = "test.key" |
| 1566 | } |
| 1567 | if test.tlsCert { |
| 1568 | config.API.HTTPS.TLSCertPath = "test.cert" |
| 1569 | } |
| 1570 | err := config.Validate(base.TestCtx(t), base.IsEnterpriseEdition()) |
| 1571 | if test.expectError { |
| 1572 | require.Error(t, err) |
| 1573 | assert.Contains(t, err.Error(), errorTLSOneMissing) |
| 1574 | } else { |
| 1575 | if err != nil { // If validate fails, make sure it's not due to TLS |
| 1576 | assert.NotContains(t, err.Error(), errorTLSOneMissing) |
| 1577 | } |
| 1578 | } |
| 1579 | }) |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | // missingJavaScriptFilePath represents a nonexistent JavaScript file path on the disk. |
| 1584 | // It is used to cover the negative test scenario for loading JavaScript from a file that is missing. |
nothing calls this directly
no test coverage detected