Skip to content

Commit

Permalink
Passwords must be strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
philnash committed Mar 6, 2018
1 parent 0f71a59 commit dbf7697
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/pwned/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Password
attr_reader :password

def initialize(password, request_options={})
raise TypeError, "password must be of type String" unless password.is_a? String
@password = password
@request_options = DEFAULT_REQUEST_OPTIONS.merge(request_options)
end
Expand Down
12 changes: 12 additions & 0 deletions spec/pwned/password_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
expect(password.password).to eq("password")
end

it "doesn't initialize with an integer" do
expect { Pwned::Password.new(123) }.to raise_error(TypeError)
end

it "doesn't initialize with an array" do
expect { Pwned::Password.new(["hello", "world"]) }.to raise_error(TypeError)
end

it "doesn't initialize with a hash" do
expect { Pwned::Password.new({ a: "b", c: "d" }) }.to raise_error(TypeError)
end

it "has a hashed version of the password" do
expect(password.hashed_password).to eq("5BAA61E4C9B93F3F0682250B6CF8331B7EE68FD8")
end
Expand Down

0 comments on commit dbf7697

Please sign in to comment.