diff --git a/active_model_otp.gemspec b/active_model_otp.gemspec index 0bc9ced..7d2f97d 100644 --- a/active_model_otp.gemspec +++ b/active_model_otp.gemspec @@ -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" diff --git a/test/one_time_password_test.rb b/test/one_time_password_test.rb index a20514b..6f8cfa6 100644 --- a/test/one_time_password_test.rb +++ b/test/one_time_password_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 360c4fd..0a4a948 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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"