diff --git a/.github/workflows/stale-issues.yml b/.github/workflows/stale-issues.yml new file mode 100644 index 0000000..f55ee85 --- /dev/null +++ b/.github/workflows/stale-issues.yml @@ -0,0 +1,15 @@ +name: 'Close stale issues and PRs' +on: + schedule: + - cron: '30 1 * * *' + workflow_dispatch: + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v9 + with: + stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.' + days-before-stale: 40 + days-before-close: 5 \ No newline at end of file diff --git a/config/configClient.go b/config/configClient.go index 754b6e7..fe94f9b 100644 --- a/config/configClient.go +++ b/config/configClient.go @@ -227,9 +227,7 @@ func (cs ConfiguredService) GetRequiredCredentialTypes(scope string) (types []st } func (cs ConfiguredService) GetScope(scope string) (scopeEntry ScopeEntry, err error) { - if scope != SERVICE_DEFAULT_SCOPE { - scope = cs.DefaultOidcScope - } + scopeEntry, exists := cs.ServiceScopes[scope] if !exists { return scopeEntry, ErrorNoSuchScope @@ -238,6 +236,7 @@ func (cs ConfiguredService) GetScope(scope string) (scopeEntry ScopeEntry, err e } func (cs ConfiguredService) GetCredentials(scope string) (credentials []Credential, err error) { + scopeEntry, err := cs.GetScope(scope) if err != nil { return credentials, err @@ -262,6 +261,7 @@ func (cs ConfiguredService) GetDcqlQuery(scope string) (dcql *DCQL, err error) { } func (cs ConfiguredService) GetCredential(scope, credentialType string) (Credential, bool) { + credentials, err := cs.GetCredentials(scope) if err == nil { for _, credential := range credentials { diff --git a/config/configClient_test.go b/config/configClient_test.go index 8dc2529..1b35bd1 100644 --- a/config/configClient_test.go +++ b/config/configClient_test.go @@ -7,7 +7,9 @@ import ( "testing" "net/http" + "reflect" + "github.com/fiware/VCVerifier/logging" "github.com/stretchr/testify/assert" ) @@ -27,6 +29,39 @@ func readFile(filename string, t *testing.T) string { return string(data) } +func Test_getScope(t *testing.T) { + + logging.Configure(true, "DEBUG", true, []string{}) + type test struct { + testName string + testScope string + expectedEntry ScopeEntry + expectedError error + mockServiceScopes map[string]ScopeEntry + } + + tests := []test{ + {testName: "For an existing scope, the correct entry should be returned.", testScope: "exists", mockServiceScopes: map[string]ScopeEntry{"exists": {Credentials: []Credential{{Type: "Test"}}}, "other": {Credentials: []Credential{{Type: "Other"}}}}, expectedEntry: ScopeEntry{Credentials: []Credential{{Type: "Test"}}}}, + {testName: "For an non-existing scope, an error should be returned.", testScope: "non-existing", mockServiceScopes: map[string]ScopeEntry{"exists": {Credentials: []Credential{{Type: "Test"}}}, "other": {Credentials: []Credential{{Type: "Other"}}}}, expectedError: ErrorNoSuchScope}, + } + for _, tc := range tests { + + t.Run(tc.testName, func(t *testing.T) { + testService := ConfiguredService{ServiceScopes: tc.mockServiceScopes} + scopeEntry, err := testService.GetScope(tc.testScope) + if tc.expectedError != err { + t.Errorf("%s - expected error %s but was %s.", tc.testName, tc.expectedError, err) + return + } + if !reflect.DeepEqual(tc.expectedEntry, scopeEntry) { + t.Errorf("%s - expected entry %s but was %s.", tc.testName, logging.PrettyPrintObject(tc.expectedEntry), logging.PrettyPrintObject(scopeEntry)) + return + } + }) + } + +} + func Test_getServices(t *testing.T) { mockedHttpClient := MockHttpClient{readFile("ccs_full.json", t)} ccsClient := HttpConfigClient{mockedHttpClient, "test.com"}