Skip to content
This repository was archived by the owner on May 10, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/yubikey/otp_verify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def replayed?
@status == 'REPLAYED_OTP'
end

def otp
@otp
end

private

def verify(args)
Expand All @@ -61,6 +65,8 @@ def verify(args)
@status = 'BAD_RESPONSE'
return
end

@otp = result[/otp=(.*)$/,1].strip
end

def verify_response(result)
Expand Down
8 changes: 8 additions & 0 deletions spec/yubikey/otp_verify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
expect{ Yubikey::OTP::Verify.new({:api_id => 'foo'}) }.to raise_error(ArgumentError, "Must supply API Key")
end

it 'should parse the otp from the response' do
ok_response = "#{@response}status=OK"
hmac = Yubikey::OTP::Verify::generate_hmac(ok_response, @key)
@mock_http_get.should_receive(:body).and_return("h=#{hmac}\n#{ok_response}")
verify = Yubikey::OTP::Verify.new(:api_id => @id, :api_key => @key, :otp => @otp, :nonce => @nonce)
verify.otp.should == @otp
end

context "with module configuration" do
before do
Yubikey.configure do |config|
Expand Down