| 1 | package matchingscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.20 `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.20 fmt/" |
| 6 | "sortscip-go gomod github.com/golang/go/src go1.20 sort/" |
| 7 | "testingscip-go gomod github.com/golang/go/src go1.20 testing/" |
| 8 | |
| 9 | "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/" |
| 10 | ) |
| 11 | |
| 12 | func TestLeetCanCreateSubstitutionMapsFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestLeetCanCreateSubstitutionMapsFromTable().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 13 | table01 := map[string][]string{ |
| 14 | "a": {"@"}, |
| 15 | "b": {"8"}, |
| 16 | "g": {"6"}, |
| 17 | } |
| 18 | |
| 19 | table02 := map[string][]string{ |
| 20 | "a": {"@", "4"}, |
| 21 | "b": {"8"}, |
| 22 | } |
| 23 | |
| 24 | table03 := map[string][]string{ |
| 25 | "a": {"@", "4"}, |
| 26 | "b": {"8"}, |
| 27 | "g": {"6", "9"}, |
| 28 | } |
| 29 | |
| 30 | table04 := map[string][]string{ |
| 31 | "a": {"@", "4"}, |
| 32 | "b": {"8"}, |
| 33 | "g": {"6", "9"}, |
| 34 | "i": {"1", "!", "|"}, |
| 35 | } |
| 36 | |
| 37 | table05 := map[string][]string{ |
| 38 | "a": {"@", "4"}, |
| 39 | "b": {"8"}, |
| 40 | "g": {"6", "9"}, |
| 41 | "l": {"!", "1", "|", "7"}, |
| 42 | } |
| 43 | |
| 44 | tests := []struct { |
| 45 | name string |
| 46 | table map[string][]string |
| 47 | expectedListSize int |
| 48 | }{ |
| 49 | {"Empty map generates an empty substitution map", map[string][]string{}, 0}, |
| 50 | {"Table with single values for every key returns only one substititution map", table01, 1}, |
| 51 | {"Table with two values on one key returns two substititution maps", table02, 2}, |
| 52 | {"Table with two values on two keys returns four substititution maps", table03, 4}, |
| 53 | {"Table should generate a substititution map with exponential variation according to table values (2*2*3 = 12)", table04, 12}, |
| 54 | {"Table should generate a substititution map with exponential variation according to table values (2*2*4 = 16)", table05, 16}, |
| 55 | } |
| 56 | |
| 57 | for _, test := range tests { |
| 58 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 59 | result := createSubstitutionsMapsFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createSubstitutionsMapsFromTable().(test.table) |
| 60 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedListSize, len(result)) |
| 61 | }) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func TestSubstitutionWorksProperlyscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestSubstitutionWorksProperly().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 66 | tests := []struct { |
| 67 | name string |
| 68 | table map[string]string |
| 69 | word string |
| 70 | expectedWord string |
| 71 | }{ |
| 72 | {"Word generated properly using substitution map", map[string]string{}, "password", "password"}, |
| 73 | {"Word generated properly using substitution map", map[string]string{}, "p@ssword", "p@ssword"}, |
| 74 | {"Word generated properly using substitution map", map[string]string{}, "p@$$w0rd", "p@$$w0rd"}, |
| 75 | {"Word generated properly using substitution map", map[string]string{}, "p@$$w0rD", "p@$$w0rD"}, |
| 76 | {"Word generated properly using substitution map", map[string]string{"a": "4"}, "p@ssword", "p@ssword"}, |
| 77 | {"Word generated properly using substitution map", map[string]string{"a": "@"}, "p@ssword", "password"}, |
| 78 | {"Word generated properly using substitution map", map[string]string{"a": "@"}, "p@$$word", "pa$$word"}, |
| 79 | {"Word generated properly using substitution map", map[string]string{"a": "@", "s": "$"}, "p@$$word", "password"}, |
| 80 | {"Word generated properly using substitution map", map[string]string{"a": "@", "s": "$", "o": "0"}, "p@$$w0rd", "password"}, |
| 81 | {"Word generated properly using substitution map", map[string]string{"a": "@", "s": "$", "o": "0"}, "p@$$w0rD", "passworD"}, |
| 82 | {"Word generated properly using substitution map", map[string]string{"i": "|"}, "|1|1|1|1|1|1|1|1|", "i1i1i1i1i1i1i1i1i"}, |
| 83 | {"Word generated properly using substitution map", map[string]string{"i": "1"}, "|1|1|1|1|1|1|1|1|", "|i|i|i|i|i|i|i|i|"}, |
| 84 | {"Word generated properly using substitution map", map[string]string{"i": "|", "l": "1"}, "|1|1|1|1|1|1|1|1|", "ilililililililili"}, |
| 85 | } |
| 86 | |
| 87 | for _, test := range tests { |
| 88 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 89 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedWord, createWordForSubstitutionMapscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createWordForSubstitutionMap().(test.word, test.table)) |
| 90 | }) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | func TestLeetCanListConflictsOnTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestLeetCanListConflictsOnTable().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 95 | mapWithoutConflicts := map[string][]string{ |
| 96 | "a": {"@", "4"}, |
| 97 | "b": {"8"}, |
| 98 | "e": {"3"}, |
| 99 | "g": {"6", "9"}, |
| 100 | } |
| 101 | |
| 102 | mapWithOneConflictInTwoKeys := map[string][]string{ |
| 103 | "a": {"@", "4"}, |
| 104 | "b": {"8"}, |
| 105 | "g": {"6", "9"}, |
| 106 | "i": {"1", "!"}, |
| 107 | "l": {"1", "|"}, |
| 108 | } |
| 109 | |
| 110 | mapWithTwoConflicts := map[string][]string{ |
| 111 | "a": {"@", "4"}, |
| 112 | "b": {"8"}, |
| 113 | "g": {"6", "9"}, |
| 114 | "i": {"1", "!", "|"}, |
| 115 | "l": {"1", "|", "7"}, |
| 116 | } |
| 117 | |
| 118 | mapWithOneConflictInThreeKeys := map[string][]string{ |
| 119 | "a": {"@", "4"}, |
| 120 | "b": {"8"}, |
| 121 | "g": {"6", "9"}, |
| 122 | "i": {"1", "!"}, |
| 123 | "l": {"1", "|", "7"}, |
| 124 | "t": {"+", "1"}, |
| 125 | } |
| 126 | |
| 127 | regularMap := map[string][]string{ |
| 128 | "a": {"@", "4"}, |
| 129 | "b": {"8"}, |
| 130 | "c": {"(", "{", "[", "<"}, |
| 131 | "e": {"3"}, |
| 132 | "g": {"6", "9"}, |
| 133 | "i": {"1", "!", "|"}, |
| 134 | "l": {"1", "|", "7"}, |
| 135 | "o": {"0"}, |
| 136 | "s": {"$", "5"}, |
| 137 | "t": {"+", "7"}, |
| 138 | "x": {"%"}, |
| 139 | "z": {"2"}, |
| 140 | } |
| 141 | |
| 142 | tests := []struct { |
| 143 | name string |
| 144 | table map[string][]string |
| 145 | expectedList []string |
| 146 | }{ |
| 147 | {"Empty map generates an empty conflicts list", map[string][]string{}, []string{}}, |
| 148 | {"Map without conflicts generates an empty conflicts list", mapWithoutConflicts, []string{}}, |
| 149 | {"Map with one conflict generates the conflicts list properly", mapWithOneConflictInTwoKeys, []string{"1"}}, |
| 150 | {"Map with two conflicts generates the conflicts list properly", mapWithTwoConflicts, []string{"1", "|"}}, |
| 151 | {"Map with one conflict generates the conflicts list properly even for three keys", mapWithOneConflictInThreeKeys, []string{"1"}}, |
| 152 | {"Regular map generates the conflicts list properly", regularMap, []string{"1", "|", "7"}}, |
| 153 | } |
| 154 | |
| 155 | for _, test := range tests { |
| 156 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 157 | result := retrieveConflictsListFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/retrieveConflictsListFromTable().(test.table) |
| 158 | |
| 159 | // these sorts are necessary to make sure that the comparison will happen as expected |
| 160 | sortscip-go gomod github.com/golang/go/src go1.20 sort/.Stringsscip-go gomod github.com/golang/go/src go1.20 sort/Strings().(test.expectedList) |
| 161 | sortscip-go gomod github.com/golang/go/src go1.20 sort/.Stringsscip-go gomod github.com/golang/go/src go1.20 sort/Strings().(result) |
| 162 | |
| 163 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedList, result) |
| 164 | }) |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | func TestLeetCanListKeysWithSpecificValueOnTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestLeetCanListKeysWithSpecificValueOnTable().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 169 | mapWithoutConflicts := map[string][]string{ |
| 170 | "a": {"@", "4"}, |
| 171 | "b": {"8"}, |
| 172 | "e": {"3"}, |
| 173 | "g": {"6", "9"}, |
| 174 | } |
| 175 | |
| 176 | mapWithOneConflictInTwoKeys := map[string][]string{ |
| 177 | "a": {"@", "4"}, |
| 178 | "b": {"8"}, |
| 179 | "g": {"6", "9"}, |
| 180 | "i": {"1", "!"}, |
| 181 | "l": {"1", "|"}, |
| 182 | } |
| 183 | |
| 184 | mapWithTwoConflicts := map[string][]string{ |
| 185 | "a": {"@", "4"}, |
| 186 | "b": {"8"}, |
| 187 | "g": {"6", "9"}, |
| 188 | "i": {"1", "!", "|"}, |
| 189 | "l": {"1", "|", "7"}, |
| 190 | } |
| 191 | |
| 192 | mapWithOneConflictInThreeKeys := map[string][]string{ |
| 193 | "a": {"@", "4"}, |
| 194 | "b": {"8"}, |
| 195 | "g": {"6", "9"}, |
| 196 | "i": {"1", "!"}, |
| 197 | "l": {"1", "|", "7"}, |
| 198 | "t": {"+", "1"}, |
| 199 | } |
| 200 | |
| 201 | regularMap := map[string][]string{ |
| 202 | "a": {"@", "4"}, |
| 203 | "b": {"8"}, |
| 204 | "c": {"(", "{", "[", "<"}, |
| 205 | "e": {"3"}, |
| 206 | "g": {"6", "9"}, |
| 207 | "i": {"1", "!", "|"}, |
| 208 | "l": {"1", "|", "7"}, |
| 209 | "o": {"0"}, |
| 210 | "s": {"$", "5"}, |
| 211 | "t": {"+", "7"}, |
| 212 | "x": {"%"}, |
| 213 | "z": {"2"}, |
| 214 | } |
| 215 | |
| 216 | tests := []struct { |
| 217 | name string |
| 218 | table map[string][]string |
| 219 | valueToFind string |
| 220 | expectedList []string |
| 221 | }{ |
| 222 | {"Empty map generates an empty list", map[string][]string{}, "@", []string{}}, |
| 223 | {"Map without conflicts returns only one representation for leet char", mapWithoutConflicts, "@", []string{"a"}}, |
| 224 | {"Map without conflicts returns no representation for unknown leet char", mapWithoutConflicts, "&", []string{}}, |
| 225 | {"Map with one conflict generates the list properly for conflicting value", mapWithOneConflictInTwoKeys, "1", []string{"i", "l"}}, |
| 226 | {"Map with one conflict generates the list properly for non conflicting value", mapWithOneConflictInTwoKeys, "|", []string{"l"}}, |
| 227 | {"Map with two conflicts generates the list properly for conflicting value (1)", mapWithTwoConflicts, "1", []string{"i", "l"}}, |
| 228 | {"Map with two conflicts generates the list properly for conflicting value (|)", mapWithTwoConflicts, "|", []string{"i", "l"}}, |
| 229 | {"Map with two conflicts generates the list properly for non conflicting value in conflicting key (i)", mapWithTwoConflicts, "!", []string{"i"}}, |
| 230 | {"Map with two conflicts generates the list properly for non conflicting value in conflicting key (l)", mapWithTwoConflicts, "7", []string{"l"}}, |
| 231 | {"Map with one conflict generates the list properly even for three keys", mapWithOneConflictInThreeKeys, "1", []string{"i", "l", "t"}}, |
| 232 | {"Regular map generates the list properly for conflicting value (|)", regularMap, "|", []string{"i", "l"}}, |
| 233 | {"Regular map generates the list properly for conflicting value (7)", regularMap, "7", []string{"l", "t"}}, |
| 234 | {"Regular map generates the list properly for non conflicting value", regularMap, "@", []string{"a"}}, |
| 235 | {"Regular map generates the list properly for unknown value", regularMap, "&", []string{}}, |
| 236 | {"Regular map generates the list properly for empty value", regularMap, "", []string{}}, |
| 237 | } |
| 238 | |
| 239 | for _, test := range tests { |
| 240 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 241 | result := retrieveListOfKeysWithSpecificValueFromTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/retrieveListOfKeysWithSpecificValueFromTable().(test.table, test.valueToFind) |
| 242 | |
| 243 | // these sorts are necessary to make sure that the comparison will happen as expected |
| 244 | sortscip-go gomod github.com/golang/go/src go1.20 sort/.Stringsscip-go gomod github.com/golang/go/src go1.20 sort/Strings().(test.expectedList) |
| 245 | sortscip-go gomod github.com/golang/go/src go1.20 sort/.Stringsscip-go gomod github.com/golang/go/src go1.20 sort/Strings().(result) |
| 246 | |
| 247 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedList, result) |
| 248 | }) |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | func TestLeetCanCreateDifferentTablesForConflictingCharscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestLeetCanCreateDifferentTablesForConflictingChar().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 253 | mapWithoutConflicts := map[string][]string{ |
| 254 | "a": {"@", "4"}, |
| 255 | "b": {"8"}, |
| 256 | "e": {"3"}, |
| 257 | "g": {"6", "9"}, |
| 258 | } |
| 259 | |
| 260 | mapWithTwoConflicts := map[string][]string{ |
| 261 | "a": {"@", "4"}, |
| 262 | "b": {"8"}, |
| 263 | "g": {"6", "9"}, |
| 264 | "i": {"1", "!", "|"}, |
| 265 | "l": {"1", "|", "7"}, |
| 266 | } |
| 267 | |
| 268 | mapWithOneConflictInThreeKeys := map[string][]string{ |
| 269 | "a": {"@", "4"}, |
| 270 | "b": {"8"}, |
| 271 | "g": {"6", "9"}, |
| 272 | "i": {"1", "!"}, |
| 273 | "l": {"1", "|", "7"}, |
| 274 | "t": {"+", "1"}, |
| 275 | } |
| 276 | |
| 277 | tests := []struct { |
| 278 | name string |
| 279 | table map[string][]string |
| 280 | leetChar string |
| 281 | expectedListOfMapsSize int |
| 282 | }{ |
| 283 | {"Empty map must return no map on result", map[string][]string{}, "", 0}, |
| 284 | {"Map without conflicts generates the same map on result", mapWithoutConflicts, "4", 1}, |
| 285 | {"Map without conflicts generates no map on result for unknown char", mapWithoutConflicts, "&", 0}, |
| 286 | {"Map with two conflicts generates two maps using conflicting char", mapWithTwoConflicts, "|", 2}, |
| 287 | {"Map with two conflicts generates the same map using non conflicting char", mapWithTwoConflicts, "8", 1}, |
| 288 | {"Map with two conflicts generates no map using not existing char", mapWithTwoConflicts, "2", 0}, |
| 289 | {"Map with one conflict in three keys generates three maps", mapWithOneConflictInThreeKeys, "1", 3}, |
| 290 | } |
| 291 | |
| 292 | for _, test := range tests { |
| 293 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 294 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedListOfMapsSize, len(createDifferentMapsForLeetCharscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createDifferentMapsForLeetChar().(test.table, test.leetChar))) |
| 295 | }) |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | func TestLeetCanCreateTablesWithoutConflictscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestLeetCanCreateTablesWithoutConflict().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 300 | mapWithoutConflicts := map[string][]string{ |
| 301 | "a": {"@", "4"}, |
| 302 | "b": {"8"}, |
| 303 | "e": {"3"}, |
| 304 | "g": {"6", "9"}, |
| 305 | } |
| 306 | |
| 307 | mapWithTwoConflicts := map[string][]string{ |
| 308 | "a": {"@", "4"}, |
| 309 | "b": {"8"}, |
| 310 | "g": {"6", "9"}, |
| 311 | "i": {"1", "!", "|"}, |
| 312 | "l": {"1", "|", "7"}, |
| 313 | } |
| 314 | |
| 315 | mapWithOneConflictInThreeKeys := map[string][]string{ |
| 316 | "a": {"@", "4"}, |
| 317 | "b": {"8"}, |
| 318 | "g": {"6", "9"}, |
| 319 | "i": {"1", "!"}, |
| 320 | "l": {"1", "|", "7"}, |
| 321 | "t": {"+", "1"}, |
| 322 | } |
| 323 | |
| 324 | mapThatGeneratesTwelveOtherMaps := map[string][]string{ |
| 325 | "a": {"@", "4", "9"}, |
| 326 | "b": {"8"}, |
| 327 | "g": {"6", "9"}, |
| 328 | "i": {"1", "!"}, |
| 329 | "l": {"1", "|", "7"}, |
| 330 | "t": {"+", "1", "7"}, |
| 331 | } |
| 332 | |
| 333 | tests := []struct { |
| 334 | name string |
| 335 | table map[string][]string |
| 336 | expectedListOfMapsSize int |
| 337 | }{ |
| 338 | {"Empty map must return only the same map on result", map[string][]string{}, 1}, |
| 339 | {"Map without conflicts generates the same map on result", mapWithoutConflicts, 1}, |
| 340 | {"Map with two conflicts generates four maps", mapWithTwoConflicts, 4}, |
| 341 | {"Map with one conflict in three keys generates three maps", mapWithOneConflictInThreeKeys, 3}, |
| 342 | {"An specific map should generate twelve other maps", mapThatGeneratesTwelveOtherMaps, 12}, |
| 343 | } |
| 344 | |
| 345 | for _, test := range tests { |
| 346 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 347 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedListOfMapsSize, len(createListOfMapsWithoutConflictsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/createListOfMapsWithoutConflicts().(test.table))) |
| 348 | }) |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | func TestStringSliceContainsValueFunctionscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestStringSliceContainsValueFunction().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 353 | tests := []struct { |
| 354 | name string |
| 355 | slice []string |
| 356 | value string |
| 357 | expectedResult bool |
| 358 | }{ |
| 359 | {"Empty slice contains no value", []string{}, "a", false}, |
| 360 | {"Empty slice contains no value, even if it is empty string", []string{}, "", false}, |
| 361 | {"Empty string is a valid value", []string{""}, "", true}, |
| 362 | {"Empty string is a valid value among others", []string{"0", "1", "", "a", "b"}, "", true}, |
| 363 | {"Empty string can not be found among others if it is not on list", []string{"0", "1", "a", "b"}, "", false}, |
| 364 | {"Slice with one value contains the stored value", []string{"a"}, "a", true}, |
| 365 | {"Slice with one value does not contain wrong value", []string{"a"}, "b", false}, |
| 366 | {"Slice with many items contains the stored value", []string{"a", "b", "c", "d", "0"}, "c", true}, |
| 367 | {"Slice with many items does not contain wrong value", []string{"a", "b", "c", "d", "0"}, "2", false}, |
| 368 | {"Slice with many items does not contain a value that looks like one that is stored", []string{"a", "b", "c", "d", "0"}, "C", false}, |
| 369 | {"Slice with many items does not contain a value that includes an space character", []string{"a", "b", "c", "d", "0"}, "c ", false}, |
| 370 | } |
| 371 | |
| 372 | for _, test := range tests { |
| 373 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 374 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedResult, stringSliceContainsValuescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/stringSliceContainsValue().(test.slice, test.value)) |
| 375 | }) |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | func TestCopyMapRemovingSameValueFromOtherKeysFunctionscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestCopyMapRemovingSameValueFromOtherKeysFunction().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 380 | map01 := map[string][]string{ |
| 381 | "a": {"@", "4"}, |
| 382 | "b": {"8"}, |
| 383 | "g": {"6", "9"}, |
| 384 | "i": {"1", "!"}, |
| 385 | "l": {"1", "|"}, |
| 386 | } |
| 387 | |
| 388 | expectedMap01 := map[string][]string{ |
| 389 | "a": {"@", "4"}, |
| 390 | "b": {"8"}, |
| 391 | "g": {"6", "9"}, |
| 392 | "i": {"1", "!"}, |
| 393 | "l": {"|"}, |
| 394 | } |
| 395 | |
| 396 | map02 := map[string][]string{ |
| 397 | "a": {"@", "4"}, |
| 398 | "b": {"8"}, |
| 399 | "g": {"6", "9"}, |
| 400 | "i": {"1", "!", "|"}, |
| 401 | "l": {"1", "|", "7"}, |
| 402 | } |
| 403 | |
| 404 | expectedMap02 := map[string][]string{ |
| 405 | "a": {"@", "4"}, |
| 406 | "b": {"8"}, |
| 407 | "g": {"6", "9"}, |
| 408 | "i": {"1", "!"}, |
| 409 | "l": {"1", "|", "7"}, |
| 410 | } |
| 411 | |
| 412 | map03 := map[string][]string{ |
| 413 | "a": {"@", "4"}, |
| 414 | "b": {"8"}, |
| 415 | "g": {"6", "9"}, |
| 416 | "i": {"1", "!"}, |
| 417 | "l": {"1", "|", "7"}, |
| 418 | "t": {"+", "1"}, |
| 419 | } |
| 420 | |
| 421 | expectedMap03 := map[string][]string{ |
| 422 | "a": {"@", "4"}, |
| 423 | "b": {"8"}, |
| 424 | "g": {"6", "9"}, |
| 425 | "i": {"!"}, |
| 426 | "l": {"1", "|", "7"}, |
| 427 | "t": {"+"}, |
| 428 | } |
| 429 | |
| 430 | tests := []struct { |
| 431 | name string |
| 432 | table map[string][]string |
| 433 | keyToFix string |
| 434 | valueToFix string |
| 435 | expectedTable map[string][]string |
| 436 | }{ |
| 437 | {"Copy of map removing same value from other keys - test 01", map01, "i", "1", expectedMap01}, |
| 438 | {"Copy of map removing same value from other keys - test 02", map02, "l", "|", expectedMap02}, |
| 439 | {"Copy of map removing same value from other keys - test 03", map03, "l", "1", expectedMap03}, |
| 440 | } |
| 441 | |
| 442 | for _, test := range tests { |
| 443 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 444 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedTable, copyMapRemovingSameValueFromOtherKeysscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/copyMapRemovingSameValueFromOtherKeys().(test.table, test.keyToFix, test.valueToFix)) |
| 445 | }) |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | func TestLeetSubTablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestLeetSubTable().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 450 | subs := relevantL33tSubtablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/relevantL33tSubtable().("password") |
| 451 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Len().(t, subs, 0, "password should produce no leet subs") |
| 452 | |
| 453 | subs = relevantL33tSubtablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/relevantL33tSubtable().("p4ssw0rd") |
| 454 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Len().(t, subs, 2, "p4ssw0rd should produce 2 subs") |
| 455 | |
| 456 | subs = relevantL33tSubtablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/relevantL33tSubtable().("1eet") |
| 457 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Len().(t, subs, 2, "1eet should produce 2 subs") |
| 458 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, subs["i"][0], "1") |
| 459 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, subs["l"][0], "1") |
| 460 | |
| 461 | subs = relevantL33tSubtablescip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/relevantL33tSubtable().("4pple@pple") |
| 462 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Len().(t, subs, 1, "4pple@pple should produce 1 subs") |
| 463 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Len().(t, subs["a"], 2) |
| 464 | } |
| 465 | |
| 466 | func TestPermutationsOfLeetSubstitutionscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestPermutationsOfLeetSubstitution().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 467 | tests := []struct { |
| 468 | name string |
| 469 | word string |
| 470 | expectedWords []string |
| 471 | }{ |
| 472 | {"Permutation returns the expected list", "1337", []string{"1eel", "ieel", "ieet", "lee7", "leet"}}, |
| 473 | {"Permutation returns the expected list", "l33t", []string{"leet"}}, |
| 474 | {"Permutation returns the expected list", "password", []string{}}, |
| 475 | {"Permutation returns the expected list", "p@ssword", []string{"password"}}, |
| 476 | {"Permutation returns the expected list", "p@$$word", []string{"password"}}, |
| 477 | {"Permutation returns the expected list", "p@$$w0rd", []string{"password"}}, |
| 478 | {"Permutation returns the expected list", "p@4a$$w0rd", []string{"pa4assword", "p@aassword"}}, |
| 479 | {"Permutation returns the expected list", "|1|1|1|", []string{"i1i1i1i", "l1l1l1l", "|i|i|i|", "|l|l|l|", "lililil", "ililili"}}, |
| 480 | {"Permutation returns the expected list", "|1|1|@", []string{"i1i1ia", "l1l1la", "|i|i|a", "|l|l|a", "lilila", "ililia"}}, |
| 481 | {"Permutation returns the expected list", "1|1|@7", []string{"1i1ial", "1i1iat", "1l1la7", "1l1lat", "1|1|al", "ilila7", "ililat", "i|i|al", "i|i|at", "lilia7", "liliat", "l|l|a7", "l|l|at"}}, |
| 482 | {"Permutation returns the expected list", "1|1|@74", []string{"1i1ial4", "1i1iat4", "1l1la74", "1l1lat4", "1|1|al4", "ilila74", "ililat4", "i|i|al4", "i|i|at4", "lilia74", "liliat4", "l|l|a74", "l|l|at4", "1i1i@la", "1i1i@ta", "1l1l@7a", "1l1l@ta", "1|1|@la", "ilil@7a", "ilil@ta", "i|i|@la", "i|i|@ta", "lili@7a", "lili@ta", "l|l|@7a", "l|l|@ta"}}, |
| 483 | } |
| 484 | |
| 485 | for _, test := range tests { |
| 486 | t.Runscip-go gomod github.com/golang/go/src go1.20 testing/T#Run().(test.name, func(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 487 | result := getPermutationsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/getPermutations().(test.word) |
| 488 | |
| 489 | // these sorts are necessary to make sure that the comparison will happen as expected |
| 490 | sortscip-go gomod github.com/golang/go/src go1.20 sort/.Stringsscip-go gomod github.com/golang/go/src go1.20 sort/Strings().(result) |
| 491 | sortscip-go gomod github.com/golang/go/src go1.20 sort/.Stringsscip-go gomod github.com/golang/go/src go1.20 sort/Strings().(test.expectedWords) |
| 492 | |
| 493 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Equalscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Equal().(t, test.expectedWords, result) |
| 494 | }) |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | func TestPermutationsLenOfLeetSubstitutionsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestPermutationsLenOfLeetSubstitutions().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 499 | // scenarios with just one possible substitution must return only one human readable value |
| 500 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "p4ssw0rd", 1) |
| 501 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "p4$sw0rd", 1) |
| 502 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "p4$$w0rd", 1) |
| 503 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "p@$$w0rd", 1) |
| 504 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "l33t", 1) |
| 505 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "p@$$w0rdp@$$w0rdp@$$w0rdp@$$w0rdp@$$w0rdp@$$w0rdp@$$w0rdp@$$w0rdp@$$w0rdp@$$w0rd", 1) |
| 506 | |
| 507 | // number of variations are exponential if has more than one representation for same char |
| 508 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@", 1) |
| 509 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@4", 2) |
| 510 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@4(", 2) |
| 511 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@4({", 2*2) |
| 512 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@4({[", 2*3) |
| 513 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@4({[6", 2*3) |
| 514 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@4({[69", 2*3*2) |
| 515 | |
| 516 | // scenarios with no substitutions must return no result |
| 517 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "test some good pass with this", 0) |
| 518 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "no substitution should be made here", 0) |
| 519 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "no substitution even with > . , ] } º # &", 0) |
| 520 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "no SUBSTITUTION even with > . , ] } º # &", 0) |
| 521 | |
| 522 | // special characters without conflic should be replaced only by one human readable character |
| 523 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@@@@@@333333+++++(((((", 1) |
| 524 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@@@@@@333333+++++{{{{{", 1) |
| 525 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "@@@@@@333333+++++[[[[[", 1) |
| 526 | |
| 527 | // if there is a conflicting character, consider all available options (but only one per time) |
| 528 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "this_is_[[{{((hanging", 3) |
| 529 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "p@$$w0rd 4", 2) |
| 530 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "1337", 5) |
| 531 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "7331", 5) |
| 532 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "%6|a(+|<91%{s91![go0li0soe||", 56) // it was an out of memory scenarion |
| 533 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|", 6) // it was an out of memory scenarion |
| 534 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "7|1!7|1!7|1!7|1!7|1!69", 28) // it was an out of memory scenarion |
| 535 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "4@8({[<3691!|1|70$5+7%24@8({[<36", 544) // the worst scenario |
| 536 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "4@8({[<3691!|1|70$5+7%24@8({[<364@8({[<3691!|1|70$5+7%24@8({[<364@8({[<3691!|1|70$5+7%24@8({[<36", 544) // the worst scenario x3 times |
| 537 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "p4$$w0rd @1!|", 14) |
| 538 | checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t, "m&u]z^ou;\\!0o7t*x}uo)[s%kb618h#'gks|z\\!l3%8:z>pcq=!5w%\"%gs~@]5as`g&.'\\z4/\\`.nz$>yck.!%twu{})|%x8)$6\"", 112) |
| 539 | } |
| 540 | |
| 541 | func checkPermutationsLenscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/checkPermutationsLen().(t *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#, password string, permutationsLen int) { |
| 542 | permutations := getPermutationsscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/getPermutations().(password) |
| 543 | assertscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/.Lenscip-go gomod github.com/stretchr/testify v1.10.0 `github.com/stretchr/testify/assert`/Len().(t, permutations, permutationsLen) |
| 544 | } |
| 545 | |
| 546 | func TestLeetscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/TestLeet().(_ *testingscip-go gomod github.com/golang/go/src go1.20 testing/.Tscip-go gomod github.com/golang/go/src go1.20 testing/T#) { |
| 547 | password := "1337" |
| 548 | matches := l33tMatchscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/matching`/l33tMatch().(password) |
| 549 | bytes, _ := jsonscip-go gomod github.com/golang/go/src go1.20 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.20 `encoding/json`/Marshal().(matches) |
| 550 | fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.20 fmt/Println().(string(bytes)) |
| 551 | fmtscip-go gomod github.com/golang/go/src go1.20 fmt/.Printlnscip-go gomod github.com/golang/go/src go1.20 fmt/Println().(matches[0].Jscip-go gomod github.com/ccojocar/zxcvbn-go . `github.com/ccojocar/zxcvbn-go/match`/Match#J.) |
| 552 | } |