MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / TestNewTLSConfig

Function TestNewTLSConfig

main_test.go:1279–1312  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1277}
1278
1279func TestNewTLSConfig(t *testing.T) {
1280 cfg := &config.TLS{
1281 KeyFile: "testdata/example.com.key",
1282 CertFile: "testdata/example.com.cert",
1283 }
1284
1285 tlsCfg, err := cfg.BuildTLSConfig(autocertManager)
1286 if err != nil {
1287 panic(fmt.Sprintf("cannot build TLS config: %s", err))
1288 }
1289 if len(tlsCfg.Certificates) < 1 {
1290 t.Fatalf("expected tls certificate; got empty list")
1291 }
1292
1293 certCachePath := fmt.Sprintf("%s/certs_dir", testDir)
1294 cfg = &config.TLS{
1295 Autocert: config.Autocert{
1296 CacheDir: certCachePath,
1297 AllowedHosts: []string{"example.com"},
1298 },
1299 }
1300 autocertManager = newAutocertManager(cfg.Autocert)
1301 if err != nil {
1302 panic(fmt.Sprintf("cannot build TLS config: %s", err))
1303 }
1304 tlsCfg, _ = cfg.BuildTLSConfig(autocertManager)
1305 if tlsCfg.GetCertificate == nil {
1306 t.Fatalf("expected func GetCertificate be set; got nil")
1307 }
1308
1309 if _, err := os.Stat(certCachePath); err != nil {
1310 t.Fatalf("expected dir %s to be created", certCachePath)
1311 }
1312}
1313
1314func TestReloadConfig(t *testing.T) {
1315 *configFile = "testdata/http.yml"

Callers

nothing calls this directly

Calls 2

BuildTLSConfigMethod · 0.95
newAutocertManagerFunction · 0.85

Tested by

no test coverage detected