Conversation
Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
…rcase Co-authored-by: hyp3rd <62474964+hyp3rd@users.noreply.github.com>
Add comprehensive edge case tests for NoSQL operator detection
Add test coverage for NoSQL detector max length validation
There was a problem hiding this comment.
Pull request overview
This pull request adds a new test case for the NoSQL injection detector's maximum length validation feature. The test verifies that inputs exceeding the configured maximum length are properly rejected with the appropriate error.
Changes:
- Added
TestNoSQLInjectionDetectorMaxLengthtest function to validate the max length configuration option
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func TestNoSQLInjectionDetectorMaxLength(t *testing.T) { | ||
| detector, err := NewNoSQLInjectionDetector(WithNoSQLDetectMaxLength(1)) | ||
| if err != nil { | ||
| t.Fatalf("expected detector, got %v", err) | ||
| } | ||
|
|
||
| err = detector.Detect("ab") | ||
| if err != ErrNoSQLInputTooLong { | ||
| t.Fatalf("expected ErrNoSQLInputTooLong, got %v", err) | ||
| } | ||
| } |
There was a problem hiding this comment.
The test should include a boundary case where the input length equals the maxLength to verify that inputs at the exact limit are accepted. Consider adding a test case like detector.Detect("a") which should return nil since the length is exactly 1 and the maxLength is 1. This would ensure the boundary condition (len(input) > d.opts.maxLength) works correctly.
- Enable golangci-lint testpackage in .golangci.yaml to encourage black-box tests. - Switch assertions to use errors.Is across validators (filename, html, markdown, nosql, sql, email, url) for accurate error matching. - internal/io/write_fuzz_test.go: group boolean params in fuzz signature and add explicit err checks around os.WriteFile/os.Symlink with clearer failure messages; add t.Cleanup and minor formatting fixes. - Update imports to include errors where needed; small formatting/blank-line cleanups. No production code changes; improves test reliability and lint coverage.
No description provided.