Skip to content

fix(secrets): validate redactor config based on added key count#45

Merged
hyp3rd merged 11 commits intomainfrom
feat/secrets
Jan 12, 2026
Merged

fix(secrets): validate redactor config based on added key count#45
hyp3rd merged 11 commits intomainfrom
feat/secrets

Conversation

@hyp3rd
Copy link
Owner

@hyp3rd hyp3rd commented Jan 12, 2026

  • Return ErrInvalidRedactorConfig when no keys are actually added during
    redactor setup.
  • Replace len(cfg.keys) pre-check with an addedCount tracked in the build
    loop to avoid accepting configs that result in zero patterns after
    filtering/deduplication.

tests(secrets): use errors.Is for assertions and tidy formatting
test(encoding): minor test cleanup (introduce result var)

Copilot AI and others added 4 commits January 12, 2026 12:35
Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
Expand test coverage for secrets detection and redaction package
- Return ErrInvalidRedactorConfig when no keys are actually added during
  redactor setup.
- Replace len(cfg.keys) pre-check with an addedCount tracked in the build
  loop to avoid accepting configs that result in zero patterns after
  filtering/deduplication.

tests(secrets): use errors.Is for assertions and tidy formatting
test(encoding): minor test cleanup (introduce result var)
Copilot AI review requested due to automatic review settings January 12, 2026 13:56
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 fixes validation logic in the redactor configuration to properly detect when no keys are actually added, and improves test assertions to use errors.Is for better error checking.

Changes:

  • Modified WithRedactionKeys to track added key count instead of checking final map length
  • Updated test assertions to use errors.Is instead of direct equality comparisons
  • Added comprehensive test coverage for edge cases and configuration validation

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/secrets/redact.go Introduced addedCount variable to track keys added during loop, replacing post-loop len(cfg.keys) check
pkg/secrets/secrets_test.go Updated error assertions to use errors.Is, added extensive test cases for invalid configs, edge cases, and various options
pkg/encoding/encoding_test.go Added blank line for better formatting
cspell.json Added "mysecret" to dictionary for test case

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

Comment on lines 148 to 188
// TestRedactorInvalidConfig tests invalid redactor configurations.
func TestRedactorInvalidConfig(t *testing.T) {
tests := []struct {
name string
opts []RedactorOption
}{
{
name: "empty redaction mask",
opts: []RedactorOption{WithRedactionMask("")},
},
{
name: "whitespace redaction mask",
opts: []RedactorOption{WithRedactionMask(" ")},
},
{
name: "nil detector",
opts: []RedactorOption{WithRedactionDetector(nil)},
},
{
name: "zero max depth",
opts: []RedactorOption{WithRedactionMaxDepth(0)},
},
{
name: "negative max depth",
opts: []RedactorOption{WithRedactionMaxDepth(-1)},
},
{
name: "empty keys",
opts: []RedactorOption{WithRedactionKeys()},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := NewRedactor(tt.opts...)
if err == nil {
t.Fatalf("expected error for %s, got nil", tt.name)
}
})
}
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

Consider adding a test case that verifies the behavior when duplicate keys are provided to WithRedactionKeys. For example, test WithRedactionKeys("duplicate_key", "duplicate_key") or WithRedactionKeys("password") where "password" is already in the default keys. This would help validate that the addedCount logic correctly handles these edge cases.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

hyp3rd and others added 2 commits January 12, 2026 15:00
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Jan 12, 2026

@hyp3rd I've opened a new pull request, #46, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 5 commits January 12, 2026 14:04
Add test cases to validate the behavior when duplicate keys are provided to
WithRedactionKeys, including:
- Duplicate keys in the same call
- Keys with different cases (normalized to same key)
- Keys already in default keys (should error)
- Multiple keys already in defaults (should error)
- Mix of duplicate and default keys (should error)

The new TestRedactorDuplicateKeys validates that duplicate keys are properly
handled by the addedCount logic, ensuring at least one unique key is added.

Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
[WIP] Address feedback on redactor config validation
- Update cspell.json to include mykey in the allowed word list
- Prevents spellcheck/lint failures in secrets-related code and docs
- No runtime or API changes
- Rename original job to `settings` to centralize project config
- Publish `go_version`, `buf_version`, and `proto_enabled` via
- Add `proto` job that `needs: settings` and runs only when `proto_enabled == 'true'`
- Switch references from `steps.settings.outputs.*` to `needs.settings.outputs.*`
- Remove env-based gating and per-step `if` checks in favor of job-level condition

This makes proto lint/format/generate deterministic, avoids env leakage, and fixes output wiring in the workflow.
@hyp3rd hyp3rd merged commit d1f1905 into main Jan 12, 2026
14 checks passed
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