spec/base_spec.rb in rotp-1.4.5 vs spec/base_spec.rb in rotp-1.4.6

- old
+ new

@@ -1,7 +1,28 @@ require File.dirname(__FILE__) + '/spec_helper' +describe "the Base32 implementation" do + it "should be 16 characters by default" do + ROTP::Base32.random_base32.length.should == 16 + ROTP::Base32.random_base32.should match /\A[a-z2-7]+\z/ + end + it "should be allow a specific length" do + ROTP::Base32.random_base32(32).length.should == 32 + end + it "should correctly decode a string" do + ROTP::Base32.decode("F").unpack('H*').first.should == "28" + ROTP::Base32.decode("23").unpack('H*').first.should == "d6" + ROTP::Base32.decode("234").unpack('H*').first.should == "d6f8" + ROTP::Base32.decode("234A").unpack('H*').first.should == "d6f800" + ROTP::Base32.decode("234B").unpack('H*').first.should == "d6f810" + ROTP::Base32.decode("234BCD").unpack('H*').first.should == "d6f8110c" + ROTP::Base32.decode("234BCDE").unpack('H*').first.should == "d6f8110c80" + ROTP::Base32.decode("234BCDEFG").unpack('H*').first.should == "d6f8110c8530" + ROTP::Base32.decode("234BCDEFG234BCDEFG").unpack('H*').first.should == "d6f8110c8536b7c0886429" + end +end + describe "HOTP example values from the rfc" do it "should match the RFC" do # 12345678901234567890 in Bas32 # GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ hotp = ROTP::HOTP.new("GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ") @@ -54,9 +75,10 @@ end Timecop.freeze(Time.at(1297553958 + 30)) do totp.verify(102705).should be_false end end + it "should output its provisioning URI" do totp = ROTP::TOTP.new("wrn3pqx5uqxqvnqr") totp.provisioning_uri('mark@percival').should == "otpauth://totp/mark@percival?secret=wrn3pqx5uqxqvnqr" end