Skip to content

Commit

Permalink
fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subinwalter committed Nov 7, 2018
1 parent 11d44b1 commit 63c5146
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions active_model_otp.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "rotp"

spec.add_development_dependency "activerecord"
spec.add_development_dependency "activemodel-serializers-xml"
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency "minitest", "~> 5.4.2"
Expand Down
26 changes: 13 additions & 13 deletions test/one_time_password_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ def test_otp_code

def test_otp_code_with_specific_length
assert_match(/^\d{4}$/, @visitor.otp_code(2160).to_s)
assert_operator(@visitor.otp_code(2160).to_s.length, :<= , 4)
assert_operator(@visitor.otp_code(2160).to_s.length, :<=, 4)
end

def test_otp_code_without_specific_length
assert_match(/^\d{6}$/, @user.otp_code(2160).to_s)
assert_operator(@user.otp_code(2160).to_s.length, :<= , 6)
assert_match(/^\d{6}$/, @user.otp_code(2160).to_s)
assert_operator(@user.otp_code(2160).to_s.length, :<=, 6)
end

def test_provisioning_uri_with_provided_account
assert_match %r{otpauth://totp/roberto\?secret=\w{16}}, @user.provisioning_uri("roberto")
assert_match %r{otpauth://totp/roberto\?secret=\w{16}}, @visitor.provisioning_uri("roberto")
assert_match %r{otpauth://hotp/roberto\?secret=\w{16}}, @member.provisioning_uri("roberto")
assert_match %r{^otpauth://totp/roberto\?secret=\w{32}$}, @user.provisioning_uri("roberto")
assert_match %r{^otpauth://totp/roberto\?secret=\w{32}$}, @visitor.provisioning_uri("roberto")
assert_match %r{^otpauth://hotp/roberto\?secret=\w{32}&counter=0$}, @member.provisioning_uri("roberto")
end

def test_provisioning_uri_with_email_field
assert_match %r{otpauth://totp/roberto@heapsource\.com\?secret=\w{16}}, @user.provisioning_uri
assert_match %r{otpauth://totp/roberto@heapsource\.com\?secret=\w{16}}, @visitor.provisioning_uri
assert_match %r{otpauth://hotp/\?secret=\w{16}&counter=0}, @member.provisioning_uri
assert_match %r{^otpauth://totp/roberto@heapsource\.com\?secret=\w{32}$}, @user.provisioning_uri
assert_match %r{^otpauth://totp/roberto@heapsource\.com\?secret=\w{32}$}, @visitor.provisioning_uri
assert_match %r{^otpauth://hotp/\?secret=\w{32}&counter=0$}, @member.provisioning_uri
end

def test_provisioning_uri_with_options
assert_match %r{otpauth://totp/roberto@heapsource\.com\?secret=\w{16}&issuer=Example}, @user.provisioning_uri(nil, issuer: "Example")
assert_match %r{otpauth://totp/roberto@heapsource\.com\?secret=\w{16}&issuer=Example}, @visitor.provisioning_uri(nil, issuer: "Example")
assert_match %r{otpauth://totp/roberto\?secret=\w{16}&issuer=Example}, @user.provisioning_uri("roberto", issuer: "Example")
assert_match %r{otpauth://totp/roberto\?secret=\w{16}&issuer=Example}, @visitor.provisioning_uri("roberto", issuer: "Example")
assert_match %r{^otpauth://totp/Example\:roberto@heapsource\.com\?secret=\w{32}&issuer=Example$}, @user.provisioning_uri(nil, issuer: "Example")
assert_match %r{^otpauth://totp/Example\:roberto@heapsource\.com\?secret=\w{32}&issuer=Example$}, @visitor.provisioning_uri(nil, issuer: "Example")
assert_match %r{^otpauth://totp/Example\:roberto\?secret=\w{32}&issuer=Example$}, @user.provisioning_uri("roberto", issuer: "Example")
assert_match %r{^otpauth://totp/Example\:roberto\?secret=\w{32}&issuer=Example$}, @visitor.provisioning_uri("roberto", issuer: "Example")
end

def test_regenerate_otp
Expand Down
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require "minitest/autorun"
require "minitest/unit"
require "active_record"
require "activemodel-serializers-xml"

ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
load "#{ File.dirname(__FILE__) }/schema.rb"
Expand Down

0 comments on commit 63c5146

Please sign in to comment.