Skip to content

Add comprehensive test coverage for token generator/validator#41

Merged
hyp3rd merged 3 commits intofeat/tokensfrom
copilot/sub-pr-40
Jan 12, 2026
Merged

Add comprehensive test coverage for token generator/validator#41
hyp3rd merged 3 commits intofeat/tokensfrom
copilot/sub-pr-40

Conversation

Copy link
Contributor

Copilot AI commented Jan 11, 2026

Addresses missing test scenarios in the token package identified during code review of PR #40.

Added Test Coverage

  • Empty/whitespace token validation - Verifies ErrTokenEmpty for empty and whitespace-only inputs
  • Invalid encoding formats - Tests malformed base64 (invalid characters, padding) and hex strings (non-hex chars, odd-length)
  • GenerateBytes() method - Validates raw byte generation with default and custom minBytes configurations
  • Invalid configuration values - Tests negative/zero values for minEntropyBits, minBytes, and maxLength return ErrInvalidTokenConfig
  • Token randomness - Ensures consecutive generations produce unique tokens and byte sequences
  • Invalid encoding enum - Tests out-of-range TokenEncoding values

All tests follow existing package patterns and use bytes.Equal() for efficient byte comparison.

// Example test ensuring tokens are cryptographically random
func TestTokenRandomness(t *testing.T) {
    generator, err := NewGenerator()
    token1, _ := generator.Generate()
    token2, _ := generator.Generate()
    
    if token1 == token2 {
        t.Fatalf("expected different tokens, got identical: %s", token1)
    }
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Jan 11, 2026
Copilot AI and others added 2 commits January 11, 2026 23:15
Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on secure token generator/validator Add comprehensive test coverage for token generator/validator Jan 11, 2026
Copilot AI requested a review from hyp3rd January 11, 2026 23:18
@hyp3rd hyp3rd marked this pull request as ready for review January 11, 2026 23:44
Copilot AI review requested due to automatic review settings January 11, 2026 23:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds comprehensive test coverage for the token generator/validator package to address gaps identified in PR #40. The tests validate error handling for edge cases, configuration validation, encoding formats, and cryptographic randomness.

Changes:

  • Added 15 new test functions covering empty/whitespace validation, invalid encoding formats, raw byte generation, invalid configuration values, token randomness, and invalid encoding enums
  • Added bytes package import for efficient byte slice comparison in randomness tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

t.Fatalf("expected generator, got %v", err)
}

bytes, err := generator.GenerateBytes()
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name 'bytes' shadows the imported 'bytes' package. Consider renaming to 'data', 'result', or 'tokenBytes' to avoid confusion and potential issues if the bytes package methods need to be used later in this function.

Copilot uses AI. Check for mistakes.
t.Fatalf("expected generator, got %v", err)
}

bytes, err := generator.GenerateBytes()
Copy link

Copilot AI Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable name 'bytes' shadows the imported 'bytes' package. Consider renaming to 'data', 'result', or 'tokenBytes' to avoid confusion and potential issues if the bytes package methods need to be used later in this function.

Copilot uses AI. Check for mistakes.
@hyp3rd hyp3rd merged commit 48bead5 into feat/tokens Jan 12, 2026
19 checks passed
@hyp3rd hyp3rd deleted the copilot/sub-pr-40 branch January 12, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants