Skip to content

Commit

Permalink
Merge pull request #42 from synadia-io/fix-scope-deletion
Browse files Browse the repository at this point in the history
[FIX] scope deletion doesn't update the target account
  • Loading branch information
ripienaar committed Apr 23, 2024
2 parents 899e649 + 88cdb59 commit 567b5f8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions account_signingkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func (as *accountSigningKeys) Delete(key string) (bool, error) {
if ok {
delete(as.data.Claim.SigningKeys, key)
as.data.Operator.DeletedKeys = append(as.data.Operator.DeletedKeys, key)
err := as.data.update()
if err != nil {
return ok, err
}
}
err := as.data.Operator.update()
return ok, err
Expand Down
40 changes: 40 additions & 0 deletions tests/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,46 @@ func (t *ProviderSuite) Test_ScopeRotation() {
t.Nil(scope2)
}

func (t *ProviderSuite) Test_ScopeDeletion() {
auth, err := authb.NewAuth(t.Provider)
t.NoError(err)
o, err := auth.Operators().Add("O")
t.NoError(err)

a, err := o.Accounts().Add("A")
t.NoError(err)

scope, err := a.ScopedSigningKeys().AddScope("admin")
t.NoError(err)
t.NotNil(scope)
key := scope.Key()

t.NoError(auth.Commit())
t.NoError(auth.Reload())

o, err = auth.Operators().Get("O")
t.NoError(err)
a, err = o.Accounts().Get("A")
t.NoError(err)
ok, err := a.ScopedSigningKeys().Delete(key)
t.NoError(err)
t.True(ok)

t.Empty(a.ScopedSigningKeys().ListRoles())
t.Empty(a.ScopedSigningKeys().List())

t.NoError(auth.Commit())
t.NoError(auth.Reload())

o, err = auth.Operators().Get("O")
t.NoError(err)
a, err = o.Accounts().Get("A")
t.NoError(err)

t.Empty(a.ScopedSigningKeys().List())
t.Empty(a.ScopedSigningKeys().ListRoles())
}

func (t *ProviderSuite) Test_SigningKeyRotation() {
auth, err := authb.NewAuth(t.Provider)
t.NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion tests/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (t *ProviderSuite) Test_Export() {

data, err := json.MarshalIndent(auth, "", " ")
t.NoError(err)
t.T().Log(string(data))
// t.T().Log(string(data))

sdir, err := os.MkdirTemp("/tmp", "stores")
t.NoError(err)
Expand Down

0 comments on commit 567b5f8

Please sign in to comment.