Skip to content

Commit 14d5e1b

Browse files
committed
APIGOV-32516 - update tests
1 parent 92c3d69 commit 14d5e1b

3 files changed

Lines changed: 15 additions & 33 deletions

File tree

pkg/agent/idplifecycle_test.go

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,6 @@ func makeIDPConfig(metadataURL string) *config.IDPConfiguration {
8080
}
8181
}
8282

83-
// idpInstanceRI builds a *ResourceInstance that looks like a fetched IdentityProvider.
84-
func idpInstanceRI(name string) *apiv1.ResourceInstance {
85-
idp := management.NewIdentityProvider(name)
86-
ri, _ := idp.AsInstance()
87-
return ri
88-
}
89-
9083
// idpMetadataInstanceRI builds a *ResourceInstance that looks like a fetched IdentityProviderMetadata
9184
// with idpScopeName as the scope name — used to test the ManageIDPResource Engage query path.
9285
func idpMetadataInstanceRI(idpScopeName string) *apiv1.ResourceInstance {
@@ -839,16 +832,13 @@ func TestManageIDPResource(t *testing.T) {
839832
}
840833

841834
tests := map[string]struct {
842-
metadata *oauth.AuthorizationServerMetadata
843-
preloadCacheName string
844-
tokenEndpointInstances []*apiv1.ResourceInstance
845-
tokenEndpointErr error
846-
metadataURLInstances []*apiv1.ResourceInstance
847-
createErr error
848-
assertResult func(t *testing.T, result string)
849-
wantQueryCount int
850-
wantCreateCalled bool
851-
wantCachedAfter bool
835+
metadata *oauth.AuthorizationServerMetadata
836+
preloadCacheName string
837+
createErr error
838+
assertResult func(t *testing.T, result string)
839+
wantQueryCount int
840+
wantCreateCalled bool
841+
wantCachedAfter bool
852842
}{
853843
"nil metadata returns empty without any API call": {
854844
metadata: nil,
@@ -869,13 +859,6 @@ func TestManageIDPResource(t *testing.T) {
869859
wantCreateCalled: true,
870860
wantCachedAfter: true,
871861
},
872-
"creates and caches resource when not in cache": {
873-
metadata: testMeta,
874-
assertResult: func(t *testing.T, result string) { assert.NotEmpty(t, result) },
875-
wantQueryCount: 1,
876-
wantCreateCalled: true,
877-
wantCachedAfter: true,
878-
},
879862
"create failure returns empty name and nothing cached": {
880863
metadata: testMeta,
881864
createErr: errors.New("create failed"),
@@ -899,10 +882,7 @@ func TestManageIDPResource(t *testing.T) {
899882
apicClient := &mock.Client{
900883
GetAPIV1ResourceInstancesMock: func(_ map[string]string, _ string) ([]*apiv1.ResourceInstance, error) {
901884
queryCount++
902-
if queryCount == 1 {
903-
return tc.tokenEndpointInstances, tc.tokenEndpointErr
904-
}
905-
return tc.metadataURLInstances, nil
885+
return []*apiv1.ResourceInstance{}, nil
906886
},
907887
CreateOrUpdateResourceMock: func(ri apiv1.Interface) (*apiv1.ResourceInstance, error) {
908888
createCalled = true

pkg/authz/oauth/idplifecycle.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
const (
14-
defaultIdpClientTimeoutSeconds = 60
14+
defaultIDPClientTimeoutSeconds = 60
1515
)
1616

1717
// IDPClient is the subset of apic.Client used by the IdP lifecycle manager,
@@ -36,7 +36,7 @@ type IDPEngageLifecycle interface {
3636
// resources in Engage using pre-resolved metadata — no Provider or outbound HTTP fetch required.
3737
// idpCfg is optional (may be nil for the v7 path); when set it is passed to the IDPResourceBuilder.
3838
// Returns the Engage IdentityProvider resource name.
39-
CreateEngageResourcesFromMetadata(idpLogger log.FieldLogger, idpCfg corecfg.IDPConfig, idpType, idpName string, metadata *AuthorizationServerMetadata, baseUrl string, envPolicies management.EnvironmentPoliciesCredentials) (string, error)
39+
CreateEngageResourcesFromMetadata(idpLogger log.FieldLogger, idpCfg corecfg.IDPConfig, idpType, idpName string, metadata *AuthorizationServerMetadata, baseURL string, envPolicies management.EnvironmentPoliciesCredentials) (string, error)
4040
}
4141

4242
// LifecycleOption configures an idpEngageLifecycle.
@@ -61,13 +61,13 @@ func NewIDPEngageLifecycle(client IDPClient, opts ...LifecycleOption) IDPEngageL
6161
return l
6262
}
6363

64-
func (l *idpEngageLifecycle) CreateEngageResourcesFromMetadata(idpLogger log.FieldLogger, idpCfg corecfg.IDPConfig, idpType, idpName string, metadata *AuthorizationServerMetadata, baseUrl string, envPolicies management.EnvironmentPoliciesCredentials) (string, error) {
64+
func (l *idpEngageLifecycle) CreateEngageResourcesFromMetadata(idpLogger log.FieldLogger, idpCfg corecfg.IDPConfig, idpType, idpName string, metadata *AuthorizationServerMetadata, baseURL string, envPolicies management.EnvironmentPoliciesCredentials) (string, error) {
6565
tokenEndpoint := metadata.TokenEndpoint
6666

6767
idpLogger.Debug("querying Engage for existing IdentityProvider resource")
6868
existing, err := l.client.GetAPIV1ResourceInstances(
6969
map[string]string{"query": fmt.Sprintf("spec.tokenEndpoint==\"%s\"", tokenEndpoint)},
70-
baseUrl+"/"+management.NewIdentityProviderMetadata("", "").PluralName(),
70+
baseURL+"/"+management.NewIdentityProviderMetadata("", "").PluralName(),
7171
)
7272
if err != nil {
7373
return "", err
@@ -122,7 +122,7 @@ func (l *idpEngageLifecycle) buildIdentityProviderFromMetadata(idpLogger log.Fie
122122
res := management.NewIdentityProvider(name)
123123
res.Spec = management.IdentityProviderSpec{
124124
ProviderType: idpType,
125-
ClientTimeout: defaultIdpClientTimeoutSeconds,
125+
ClientTimeout: defaultIDPClientTimeoutSeconds,
126126
}
127127
return res, nil
128128
}

pkg/config/centralconfig_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ func TestDiscoveryAgentConfig(t *testing.T) {
6868
centralConfig.APIServerVersion = "v1alpha1"
6969

7070
assert.Equal(t, centralConfig.URL+"/apis/management/v1alpha1/environments/eee/apiservices", cfg.GetServicesURL())
71+
assert.Equal(t, centralConfig.URL+"/apis/management/v1alpha1", cfg.GetAPIServerVersionURL())
72+
assert.Equal(t, centralConfig.URL+"/apis/management/v1alpha1/environments/", cfg.GetAPIServerURL())
7173

7274
centralConfig.PollInterval = 0
7375
err = cfgValidator.ValidateCfg()

0 commit comments

Comments
 (0)