|
101 | 101 | (is (= 1 |
102 | 102 | @(shared/future* {:env "prod"} |
103 | 103 | 1))))) |
| 104 | + |
| 105 | +(deftest obfuscate-test |
| 106 | + (testing "nil and empty inputs" |
| 107 | + (is (nil? (shared/obfuscate nil))) |
| 108 | + (is (= "" (shared/obfuscate "")))) |
| 109 | + |
| 110 | + (testing "length <= 4 is fully obfuscated" |
| 111 | + (is (= "*" (shared/obfuscate "a"))) |
| 112 | + (is (= "**" (shared/obfuscate "ab"))) |
| 113 | + (is (= "****" (shared/obfuscate "abcd")))) |
| 114 | + |
| 115 | + (testing "default preserve-num=3 with various lengths" |
| 116 | + ;; length 5: middle forced to at least 5 stars, preserve shrinks to floor(len/2) |
| 117 | + (is (= "ab*****de" (shared/obfuscate "abcde"))) |
| 118 | + ;; length 6: prefix 3, 5 stars, suffix 3 => 11 chars |
| 119 | + (is (= "abc*****def" (shared/obfuscate "abcdef"))) |
| 120 | + ;; length 7: prefix 3, 5 stars, suffix 3 => 11 chars |
| 121 | + (is (= "abc*****efg" (shared/obfuscate "abcdefg"))) |
| 122 | + ;; length 10: prefix 3, 5 stars, suffix 3 => 11 chars |
| 123 | + (is (= "abc*****hij" (shared/obfuscate "abcdefghij")))) |
| 124 | + |
| 125 | + (testing "respect (bounded) preserve-num" |
| 126 | + ;; preserve-num smaller than half the length |
| 127 | + (is (= "a*****f" (shared/obfuscate "abcdef" :preserve-num 1))) |
| 128 | + ;; preserve-num larger than half the length is capped |
| 129 | + (is (= "abc*****def" (shared/obfuscate "abcdef" :preserve-num 10))))) |
0 commit comments