Skip to content

Commit

Permalink
removed parsing of account for cluster traffic as that option will be…
Browse files Browse the repository at this point in the history
… delayed.
  • Loading branch information
aricart committed Sep 13, 2024
1 parent 0cca9a4 commit 97b1212
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 25 deletions.
22 changes: 3 additions & 19 deletions v2/account_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"sort"
"strings"
"time"

"github.com/nats-io/nkeys"
Expand Down Expand Up @@ -232,9 +231,8 @@ func (ac *ExternalAuthorization) Validate(vr *ValidationResults) {
}

const (
ClusterTrafficSystem = "system"
ClusterTrafficOwner = "owner"
ClusterTrafficOtherAccount = "account:"
ClusterTrafficSystem = "system"
ClusterTrafficOwner = "owner"
)

type ClusterTraffic string
Expand All @@ -243,21 +241,7 @@ func (ct ClusterTraffic) Valid() error {
if ct == "" || ct == ClusterTrafficSystem || ct == ClusterTrafficOwner {
return nil
}

if strings.HasPrefix(string(ct), ClusterTrafficOtherAccount) {
// so in JWT we would expect this to be an account ID
id := ct[len(ClusterTrafficOtherAccount):]
if !strings.HasPrefix(string(id), "A") {
return errors.New("cluster traffic should be an account public key")
}
_, err := nkeys.FromPublicKey(string(id))
if err != nil {
return errors.New("cluster traffic is not a public account key")
}
} else {
return fmt.Errorf("unknown cluster traffic option: %q", ct)
}
return nil
return fmt.Errorf("unknown cluster traffic option: %q", ct)
}

// Account holds account specific claims data
Expand Down
6 changes: 0 additions & 6 deletions v2/account_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,12 +1005,6 @@ func TestClusterTraffic_Valid(t *testing.T) {
{input: "OWNER", ok: false},
{input: "unknown", ok: false},
{input: "account", ok: false},
{input: "account:", ok: false},
{input: "account:A", ok: false},
{input: "account:B", ok: false},
// seed - reject
{input: "account:SAAEVKMPCBXPP5JG5J4DWQQJTL6TJJE35UCTYON4E2AMPMHOVJPTUSWIZY", ok: false},
{input: "account:ABDFLVEVLA2IOTEEP44IGMZE2SFRBNVCXH5DUGRQ36AUVB2I44TJTNIA", ok: true},
}

for _, test := range tests {
Expand Down

0 comments on commit 97b1212

Please sign in to comment.