Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADDED] IsClaimRevoked to check user claim and fixed some comments. #113

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions account_claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,12 @@ func (a *AccountClaims) IsRevokedAt(pubKey string, timestamp time.Time) bool {
func (a *AccountClaims) IsRevoked(_ string) bool {
return true
}

// IsClaimRevoked checks if the account revoked the claim passed in.
// Invalid claims (nil, no Subject or IssuedAt) will return true.
func (a *AccountClaims) IsClaimRevoked(claim *UserClaims) bool {
if claim == nil || claim.IssuedAt == 0 || claim.Subject == "" {
return true
}
return a.Revocations.IsRevoked(claim.Subject, time.Unix(claim.IssuedAt, 0))
}
13 changes: 10 additions & 3 deletions account_claims_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,14 @@ func TestUserRevocation(t *testing.T) {
apk := publicKey(akp, t)
account := NewAccountClaims(apk)

pubKey := "bar"
ukp := createUserNKey(t)
pubKey := publicKey(ukp, t)
uc := NewUserClaims(pubKey)
uJwt, _ := uc.Encode(akp)
uc, err := DecodeUserClaims(uJwt)
if err != nil {
t.Errorf("Failed to decode user claim: %v", err)
}
now := time.Now()

// test that clear is safe before we add any
Expand Down Expand Up @@ -523,13 +530,13 @@ func TestUserRevocation(t *testing.T) {

account.ClearRevocation(pubKey)

if account.IsRevokedAt(pubKey, now) {
if account.IsClaimRevoked(uc) {
t.Errorf("revocations should be cleared")
}

account.RevokeAt(pubKey, now.Add(time.Second*1000))

if !account.IsRevoked(pubKey) {
if !account.IsClaimRevoked(uc) {
t.Errorf("revocation be true we revoked in the future")
}
}
2 changes: 1 addition & 1 deletion revocation_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (r RevocationList) ClearRevocation(pubKey string) {
}

// IsRevoked checks if the public key is in the revoked list with a timestamp later than
// the one passed in. Generally this method is called with time.Now() but other time's can
// the one passed in. Generally this method is called with an issue time but other time's can
// be used for testing.
func (r RevocationList) IsRevoked(pubKey string, timestamp time.Time) bool {
ts, ok := r[pubKey]
Expand Down