Skip to content

Commit

Permalink
add http endpoint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Oct 12, 2023
1 parent ba7a90f commit a99bc5b
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions command/agent/keyring_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func TestHTTP_Keyring_CRUD(t *testing.T) {
})
}

// TestHTTP_Keyring_JWKS asserts the JWKS endpoint is enabled by default and
// caches relative to the key rotation threshold.
func TestHTTP_Keyring_JWKS(t *testing.T) {
ci.Parallel(t)

Expand Down Expand Up @@ -114,18 +116,47 @@ func TestHTTP_Keyring_JWKS(t *testing.T) {
})
}

// TestHTTP_Keyring_OIDCDisco_Disabled asserts that the OIDC Discovery endpoint
// is disabled by default.
func TestHTTP_Keyring_OIDCDisco_Disabled(t *testing.T) {
ci.Parallel(t)

httpTest(t, nil, func(s *TestAgent) {
t.Fatal("TODO")
respW := httptest.NewRecorder()

req, err := http.NewRequest(http.MethodGet, structs.JWKSPath, nil)
must.NoError(t, err)

_, err = s.Server.OIDCDiscoveryRequest(respW, req)
must.ErrorContains(t, err, "OIDC Discovery endpoint disabled")
codedErr := err.(HTTPCodedError)
must.Eq(t, http.StatusNotFound, codedErr.Code())
})
}

// TestHTTP_Keyring_OIDCDisco_Disabled asserts that the OIDC Discovery endpoint
// is enabled when OIDCIssuer is set.
func TestHTTP_Keyring_OIDCDisco_Enabled(t *testing.T) {
ci.Parallel(t)

httpTest(t, nil, func(s *TestAgent) {
t.Fatal("TODO")
// Set OIDCIssuer to a valid looking (but fake) issuer
const testIssuer = "https://oidc.test.nomadproject.io/"

cb := func(c *Config) {
c.Server.OIDCIssuer = testIssuer
}

httpTest(t, cb, func(s *TestAgent) {
respW := httptest.NewRecorder()

req, err := http.NewRequest(http.MethodGet, structs.JWKSPath, nil)
must.NoError(t, err)

obj, err := s.Server.OIDCDiscoveryRequest(respW, req)
must.NoError(t, err)

oidcConf := obj.(*structs.OIDCDiscoveryConfig)
must.Eq(t, testIssuer, oidcConf.Issuer)
must.StrHasPrefix(t, testIssuer, oidcConf.JWKS)
})
}

0 comments on commit a99bc5b

Please sign in to comment.