Skip to content

Commit

Permalink
[FIX] added validation where auth user is required if accounts are sp…
Browse files Browse the repository at this point in the history
…ecified (#181)
  • Loading branch information
aricart authored Dec 2, 2022
1 parent 31baa55 commit 83b58fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions v2/account_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ func (a *Account) EnableExternalAuthorization(users ...string) {
}

func (ac *ExternalAuthorization) Validate(vr *ValidationResults) {
if len(ac.AllowedAccounts) > 0 && len(ac.AuthUsers) == 0 {
vr.AddError("External authorization cannot have accounts without users specified")
}
// Make sure users are all valid user nkeys.
// Make sure allowed accounts are all valid account nkeys.
for _, u := range ac.AuthUsers {
Expand Down
16 changes: 16 additions & 0 deletions v2/account_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,19 @@ func TestAccountExternalAuthorization(t *testing.T) {
t.Fatalf("Expected not to have authorization enabled")
}
}

func TestAccountExternalAuthorizationRequiresOneUser(t *testing.T) {
akp := createAccountNKey(t)
apk := publicKey(akp, t)

account := NewAccountClaims(apk)
account.Authorization.AllowedAccounts.Add(publicKey(createAccountNKey(t), t))

vr := &ValidationResults{}
account.Validate(vr)

AssertEquals(len(vr.Errors()), 1, t)
AssertEquals("External authorization cannot have accounts without users specified",
vr.Errors()[0].Error(),
t)
}

0 comments on commit 83b58fd

Please sign in to comment.