mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-29 18:33:05 +00:00
Make sure mockoidc is up, has unique name and removed if exist
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
4904ccc3c3
commit
201f81ce00
3 changed files with 39 additions and 4 deletions
|
@ -61,7 +61,7 @@ func mockOIDC() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
listener, err := net.Listen("tcp", fmt.Sprintf("mockoidc:%d", port))
|
listener, err := net.Listen("tcp", fmt.Sprintf("headscale-mock-oidc:%d", port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -191,6 +191,17 @@ func (s *IntegrationTestSuite) tailscaleContainer(
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = s.pool.RemoveContainerByName(hostname)
|
||||||
|
if err != nil {
|
||||||
|
s.FailNow(
|
||||||
|
fmt.Sprintf(
|
||||||
|
"Could not remove existing container before building test: %s",
|
||||||
|
err,
|
||||||
|
),
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pts, err := s.pool.BuildAndRunWithBuildOptions(
|
pts, err := s.pool.BuildAndRunWithBuildOptions(
|
||||||
tailscaleBuildOptions,
|
tailscaleBuildOptions,
|
||||||
tailscaleOptions,
|
tailscaleOptions,
|
||||||
|
|
|
@ -144,7 +144,6 @@ func (s *IntegrationOIDCTestSuite) SetupSuite() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if pmockoidc, err := s.pool.BuildAndRunWithBuildOptions(
|
if pmockoidc, err := s.pool.BuildAndRunWithBuildOptions(
|
||||||
headscaleBuildOptions,
|
headscaleBuildOptions,
|
||||||
mockOidcOptions,
|
mockOidcOptions,
|
||||||
|
@ -154,6 +153,31 @@ func (s *IntegrationOIDCTestSuite) SetupSuite() {
|
||||||
s.FailNow(fmt.Sprintf("Could not start mockOIDC container: %s", err), "")
|
s.FailNow(fmt.Sprintf("Could not start mockOIDC container: %s", err), "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.Suite.T().Logf("Waiting for headscale mock oidc to be ready for tests")
|
||||||
|
hostEndpoint := fmt.Sprintf("localhost:%s", s.mockOidc.GetPort("10000/tcp"))
|
||||||
|
|
||||||
|
if err := s.pool.Retry(func() error {
|
||||||
|
url := fmt.Sprintf("http://%s/oidc/.well-known/openid-configuration", hostEndpoint)
|
||||||
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("headscale mock OIDC tests is not ready: %s\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode != http.StatusOK {
|
||||||
|
return fmt.Errorf("status code not OK")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
// TODO(kradalby): If we cannot access headscale, or any other fatal error during
|
||||||
|
// test setup, we need to abort and tear down. However, testify does not seem to
|
||||||
|
// support that at the moment:
|
||||||
|
// https://github.com/stretchr/testify/issues/849
|
||||||
|
return // fmt.Errorf("Could not connect to headscale: %s", err)
|
||||||
|
}
|
||||||
|
s.Suite.T().Log("headscale-mock-oidc container is ready for embedded OIDC tests")
|
||||||
|
|
||||||
oidcCfg := fmt.Sprintf(`
|
oidcCfg := fmt.Sprintf(`
|
||||||
oidc:
|
oidc:
|
||||||
issuer: http://%s:10000/oidc
|
issuer: http://%s:10000/oidc
|
||||||
|
@ -228,10 +252,10 @@ oidc:
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Suite.T().Logf("Waiting for headscale to be ready for embedded OIDC tests")
|
s.Suite.T().Logf("Waiting for headscale to be ready for embedded OIDC tests")
|
||||||
hostEndpoint := fmt.Sprintf("localhost:%s", s.headscale.GetPort("8443/tcp"))
|
hostMockEndpoint := fmt.Sprintf("localhost:%s", s.headscale.GetPort("8443/tcp"))
|
||||||
|
|
||||||
if err := s.pool.Retry(func() error {
|
if err := s.pool.Retry(func() error {
|
||||||
url := fmt.Sprintf("https://%s/health", hostEndpoint)
|
url := fmt.Sprintf("https://%s/health", hostMockEndpoint)
|
||||||
insecureTransport := http.DefaultTransport.(*http.Transport).Clone()
|
insecureTransport := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
insecureTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
insecureTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
client := &http.Client{Transport: insecureTransport}
|
client := &http.Client{Transport: insecureTransport}
|
||||||
|
|
Loading…
Reference in a new issue