-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
zxcvbn_test.exs
94 lines (78 loc) · 3.32 KB
/
zxcvbn_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
defmodule ZXCVBNTest do
use ExUnit.Case
use ExUnitProperties
@node_script "#{File.cwd!()}/zxcvbn.js"
defp exec_node(string) do
{r, 0} = System.cmd(@node_script, [string])
Jason.decode!(r)
end
describe "zxcvbn/1" do
# TODO: add this test after fixing certain unicode characters handling
# property "handles given string" do
# check all str <- string(:printable, max_length: 10, min_length: 2),
# times <- integer(1..20),
# times >= 0 do
# Application.put_env(:zxcvbn, :mode, :default)
# %{calc_time: calc_time, password: password, score: score} = result = ZXCVBN.zxcvbn(str)
# assert password === str
# assert calc_time > 0
# assert score >= 0
#
# official_result = exec_node(str)
#
# assert Map.get(official_result, "guesses") == Map.get(result, :guesses)
#
# assert get_in(official_result, ["feedback", "suggestions"]) ===
# get_in(result, [:feedback, :suggestions])
#
# assert get_in(official_result, ["feedback", "warning"]) ===
# get_in(result, [:feedback, :warning])
#
# assert Map.get(official_result, "score") === Map.get(result, :score)
# end
# end
property "handles given ascii string in ascii mode" do
check all str <- string(:ascii, max_length: 10, min_length: 1),
times <- integer(1..20),
times >= 0 do
Application.put_env(:zxcvbn, :mode, :ascii)
%{calc_time: calc_time, password: password, score: score} = result = ZXCVBN.zxcvbn(str)
assert password === str
assert calc_time > 0
assert score >= 0
official_result = exec_node(str)
assert Map.get(official_result, "guesses") == Map.get(result, :guesses)
assert get_in(official_result, ["feedback", "suggestions"]) ===
get_in(result, [:feedback, :suggestions])
assert get_in(official_result, ["feedback", "warning"]) ===
get_in(result, [:feedback, :warning])
assert Map.get(official_result, "score") === Map.get(result, :score)
end
end
property "handles given ascii string in unicode mode" do
check all str <- string(:ascii, max_length: 10, min_length: 1),
times <- integer(1..20),
times >= 0 do
Application.put_env(:zxcvbn, :mode, :ascii)
%{calc_time: calc_time, password: password, score: score} = result = ZXCVBN.zxcvbn(str)
assert password === str
assert calc_time > 0
assert score >= 0
official_result = exec_node(str)
assert Map.get(official_result, "guesses") == Map.get(result, :guesses)
assert get_in(official_result, ["feedback", "suggestions"]) ===
get_in(result, [:feedback, :suggestions])
assert get_in(official_result, ["feedback", "warning"]) ===
get_in(result, [:feedback, :warning])
assert Map.get(official_result, "score") === Map.get(result, :score)
end
end
end
test "README.md version is up to date" do
app = :zxcvbn
app_version = Application.spec(:zxcvbn, :vsn) |> to_string()
readme = File.read!("README.md")
[_, readme_version] = Regex.run(~r/{:#{app}, "(.+)"}/, readme)
assert Version.match?(app_version, readme_version)
end
end