package authserver import ( "net/http" "testing" ) // Addr is address to listen. const Addr = "localhost:9000" // CACert is path to the CA certificate. // This should be generated by Makefile before test. const CACert = "authserver/testdata/ca.crt" // ServerCert is path to the server certificate. // This should be generated by Makefile before test. const ServerCert = "authserver/testdata/server.crt" // ServerKey is path to the server key. // This should be generated by Makefile before test. const ServerKey = "authserver/testdata/server.key" // Config represents server configuration. type Config struct { Issuer string Scope string Cert string Key string } // Start starts a HTTP server. func (c *Config) Start(t *testing.T) *http.Server { s := &http.Server{ Addr: Addr, Handler: newHandler(t, c), } go func() { var err error if c.Cert != "" && c.Key != "" { err = s.ListenAndServeTLS(c.Cert, c.Key) } else { err = s.ListenAndServe() } if err != nil && err != http.ErrServerClosed { t.Error(err) } }() return s }