| 616 | } |
| 617 | |
| 618 | func TestAPIKey_IsValid(t *testing.T) { |
| 619 | t.Run("Valid key - not revoked and not expired", func(t *testing.T) { |
| 620 | apiKey := &APIKey{ |
| 621 | IsRevoked: false, |
| 622 | ExpiresAt: time.Now().Add(24 * time.Hour), |
| 623 | } |
| 624 | assert.True(t, apiKey.IsValid()) |
| 625 | }) |
| 626 | |
| 627 | t.Run("Invalid key - revoked", func(t *testing.T) { |
| 628 | apiKey := &APIKey{ |
| 629 | IsRevoked: true, |
| 630 | ExpiresAt: time.Now().Add(24 * time.Hour), |
| 631 | } |
| 632 | assert.False(t, apiKey.IsValid()) |
| 633 | }) |
| 634 | |
| 635 | t.Run("Invalid key - expired", func(t *testing.T) { |
| 636 | apiKey := &APIKey{ |
| 637 | IsRevoked: false, |
| 638 | ExpiresAt: time.Now().Add(-24 * time.Hour), |
| 639 | } |
| 640 | assert.False(t, apiKey.IsValid()) |
| 641 | }) |
| 642 | |
| 643 | t.Run("Invalid key - revoked and expired", func(t *testing.T) { |
| 644 | apiKey := &APIKey{ |
| 645 | IsRevoked: true, |
| 646 | ExpiresAt: time.Now().Add(-24 * time.Hour), |
| 647 | } |
| 648 | assert.False(t, apiKey.IsValid()) |
| 649 | }) |
| 650 | } |
| 651 | |
| 652 | func TestAPIKey_HasScope(t *testing.T) { |
| 653 | apiKey := &APIKey{ |