* Filtering feature, minor logic changes +: Add IP validation (to properly log IP even when trusted proxy is missing) +: Added synchronization of decrypted organization, collection, and folder names (for filtering purposes) +: Changed sync behavior to prevent collapsing multiple logins with the same name +: Added possibility to filter logins based on organization, collection, and folder name/id in GetSecret +: Added support for space character in secret name validation (it is also properly URL-decoded) * Update README * Fixes related to issues reported by CodeRabbit: +: Changed british use of organisations in README +: Reduced line count in parseSecretFilters by including helper function for filter dimensions resolution +: Added comment clarifying absence of existence checking on dimension IDs as opposed to names +: Removed efensive comma split logic on IPs (redundant due to IPValidation setting on Fiber) +: Changed Query validator to align with name validator (mainly removing hard-coded values) +: Added comments to decryptVaultLabel for clarity +: Change empty SyncNameMaps instance with emptySyncNameMaps helper for consistency +: Add lexical sort for lookupIDByName for deterministic result in case of multiple matches * Bumped logging to warn and added entity metadata in log * Unit tests: +: Added unit tests for every newly introduced or changed function +: Rewrote NewClient constructor to accept optional preloaded data (so it can be used in test scenarios) * Changes requested by CodeRabbit
43 lines
1003 B
Go
43 lines
1003 B
Go
package validators
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func TestIsValidFilterQueryValue(t *testing.T) {
|
||
t.Parallel()
|
||
|
||
// Test allowed length of filter query values
|
||
longOK := strings.Repeat("a", SecretNameMaxLength)
|
||
tooLong := strings.Repeat("a", SecretNameMaxLength+1)
|
||
|
||
tests := []struct {
|
||
name string
|
||
input string
|
||
want bool
|
||
}{
|
||
// Add test cases here
|
||
{"simple name", "Acme Corp", true},
|
||
{"trimmed valid", " Dev Team ", true},
|
||
{"unicode printable", "Team-α", true},
|
||
{"max length", longOK, true},
|
||
{"empty", "", false},
|
||
{"whitespace only", " ", false},
|
||
{"too long", tooLong, false},
|
||
{"newline", "bad\nname", false},
|
||
{"tab", "bad\tname", false},
|
||
{"del control", "bad\x7fname", false},
|
||
{"null", "bad\x00name", false},
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
t.Run(tt.name, func(t *testing.T) {
|
||
t.Parallel()
|
||
if got := IsValidFilterQueryValue(tt.input); got != tt.want {
|
||
t.Errorf("IsValidFilterQueryValue(%q) = %v, want %v", tt.input, got, tt.want)
|
||
}
|
||
})
|
||
}
|
||
}
|