From 404372e31703f08970d36753fafce918aac5f432 Mon Sep 17 00:00:00 2001 From: Ross Kaffenberger Date: Wed, 2 Apr 2014 15:44:12 -0400 Subject: [PATCH] specs for Model#provisioning_uri --- .../models/two_factor_authenticatable_spec.rb | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb b/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb index fe86422..bc34dd1 100644 --- a/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb +++ b/spec/lib/two_factor_authentication/models/two_factor_authenticatable_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' include AuthenticatedModelHelper - describe Devise::Models::TwoFactorAuthenticatable, '#otp_code' do let(:instance) { AuthenticatedModelHelper.create_new_user } subject { instance.otp_code(time) } @@ -67,4 +66,35 @@ describe Devise::Models::TwoFactorAuthenticatable, '#send_two_factor_authenticat instance = AuthenticatedModelHelper.create_new_user_with_overrides expect(instance.send_two_factor_authentication_code).to eq("Code sent") end -end \ No newline at end of file +end + +describe Devise::Models::TwoFactorAuthenticatable, '#provisioning_uri' do + let(:instance) { AuthenticatedModelHelper.create_new_user } + + before do + instance.email = "houdini@example.com" + instance.run_callbacks :create + end + + it "should return uri with user's email" do + expect(instance.provisioning_uri).to match(%r{otpauth://totp/houdini@example.com\?secret=\w{16}}) + end + + it "should return uri with issuer option" do + expect(instance.provisioning_uri("houdini")).to match(%r{otpauth://totp/houdini\?secret=\w{16}$}) + end + + it "should return uri with issuer option" do + require 'cgi' + + uri = URI.parse(instance.provisioning_uri("houdini", issuer: 'Magic')) + params = CGI::parse(uri.query) + + expect(uri.scheme).to eq("otpauth") + expect(uri.host).to eq("totp") + expect(uri.path).to eq("/houdini") + expect(params['issuer'].shift).to eq('Magic') + expect(params['secret'].shift).to match(%r{\w{16}}) + end + +end