File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class HashedPassword
26
26
# @since 1.1.0
27
27
def initialize ( hashed_password , request_options = { } )
28
28
raise TypeError , "hashed_password must be of type String" unless hashed_password . is_a? String
29
- @hashed_password = hashed_password
29
+ @hashed_password = hashed_password . upcase
30
30
@request_options = Hash ( request_options ) . dup
31
31
@request_headers = Hash ( request_options . delete ( :headers ) )
32
32
@request_headers = DEFAULT_REQUEST_HEADERS . merge ( @request_headers )
Original file line number Diff line number Diff line change 1
1
RSpec . describe Pwned ::HashedPassword do
2
- subject ( :hashed_password ) { Pwned ::HashedPassword . new ( password_hash ) }
3
-
2
+ let ( :hashed_password ) { Pwned ::HashedPassword . new ( password_hash ) }
4
3
let ( :password ) { "password" }
5
4
let ( :password_hash ) { Pwned . hash_password ( password ) }
6
5
31
30
expect { hashed_password } . to raise_error ( TypeError )
32
31
end
33
32
end
33
+
34
+ describe "when pwned" , pwned_range : "5BAA6" do
35
+ it "reports it is pwned" do
36
+ expect ( hashed_password . pwned? ) . to be true
37
+ expect ( @stub ) . to have_been_requested
38
+ end
39
+
40
+ it "reports it has been pwned many times" do
41
+ expect ( hashed_password . pwned_count ) . to eq ( 3303003 )
42
+ expect ( @stub ) . to have_been_requested
43
+ end
44
+
45
+ describe "when given a lower case hash" do
46
+ let ( :hashed_password ) { Pwned ::HashedPassword . new ( password_hash ) }
47
+ let ( :password_hash ) { Pwned . hash_password ( password ) . downcase }
48
+
49
+ it "upcases the hashed password" do
50
+ expect ( hashed_password . hashed_password ) . to eq ( "5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8" )
51
+ end
52
+
53
+ it "reports it is pwned" do
54
+ expect ( hashed_password . pwned? ) . to be true
55
+ expect ( @stub ) . to have_been_requested
56
+ end
57
+ end
58
+ end
34
59
end
You can’t perform that action at this time.
0 commit comments