forked from titanous/yubikey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyubikey_otp_spec.rb
28 lines (21 loc) · 1.08 KB
/
yubikey_otp_spec.rb
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
require File.dirname(__FILE__) + '/spec_helper.rb'
describe 'Yubikey::OTP' do
it 'should parse a otp' do
token = Yubikey::OTP.new('dteffujehknhfjbrjnlnldnhcujvddbikngjrtgh', 'ecde18dbe76fbd0c33330f1c354871db')
token.public_id.should == 'dteffuje'
token.secret_id.should == '8792ebfe26cc'
token.insert_counter.should == 19
token.session_counter.should == 17
token.timestamp.should == 49712
token.random_number.should == 40904
end
it 'should raise if key or otp invalid' do
otp = 'hknhfjbrjnlnldnhcujvddbikngjrtgh'
key = 'ecde18dbe76fbd0c33330f1c354871db'
lambda { Yubikey::OTP.new(key, key) }.should raise_error(Yubikey::OTP::InvalidOTPError)
lambda { Yubikey::OTP.new(otp, otp) }.should raise_error(Yubikey::OTP::InvalidKeyError)
lambda { Yubikey::OTP.new(otp[0,31], key) }.should raise_error(Yubikey::OTP::InvalidOTPError)
lambda { Yubikey::OTP.new(otp, key[0,31]) }.should raise_error(Yubikey::OTP::InvalidKeyError)
lambda { Yubikey::OTP.new(otp[1,31]+'d', key) }.should raise_error(Yubikey::OTP::BadCRCError)
end
end