Sha256: c700bf69500b516a1e21d3c7badacc8ed265085730dbc4fff55249bbec270246
Contents?: true
Size: 1.52 KB
Versions: 4
Compression:
Stored size: 1.52 KB
Contents
require 'spec_helper' describe ROTP::TOTP do before(:all) { @now = Time.utc(2012,1,1) } subject { ROTP::TOTP.new("JBSWY3DPEHPK3PXP") } it "should generate a number given a number" do subject.at(@now).should == 68212 end it "should generate a number as a padded string" do subject.at(@now, true).should == "068212" end it "should verify a number" do subject.verify(68212, @now).should be_true end it "should verify a string" do subject.verify("68212", @now).should be_true end context "with drift" do it "should verify a number" do subject.verify_with_drift(68212, 0, @now).should be_true end it "should verify a string" do subject.verify_with_drift("68212", 0, @now).should be_true end it "should verify a slightly old number" do subject.verify_with_drift(subject.at(@now - 30), 60, @now).should be_true end it "should verify a slightly new number" do subject.verify_with_drift(subject.at(@now + 60), 60, @now).should be_true end it "should reject a number that is outside the allowed drift" do subject.verify_with_drift(subject.at(@now - 60), 30, @now).should be_false end context "with drift that is not a multiple of the TOTP interval" do it "should verify a slightly old number" do subject.verify_with_drift(subject.at(@now - 45), 45, @now).should be_true end it "should verify a slightly new number" do subject.verify_with_drift(subject.at(@now + 40), 40, @now).should be_true end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rotp-1.4.6 | spec/totp_spec.rb |
rotp-1.4.5 | spec/totp_spec.rb |
rotp-1.4.4 | spec/totp_spec.rb |
rotp-1.4.3 | spec/totp_spec.rb |