Skip to content

Commit

Permalink
Test for old way and new issuer to prevent breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdp committed Aug 30, 2023
1 parent 4b682fd commit 42ef301
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
24 changes: 20 additions & 4 deletions spec/lib/rotp/hotp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,22 @@
end

describe '#provisioning_uri' do
let(:hotp) { ROTP::HOTP.new('a' * 32, name: "[email protected]", issuer: "Example.com") }

let(:hotp) { ROTP::HOTP.new('a' * 32, name: "[email protected]") }

it 'created from the otp instance data' do
expect(hotp.provisioning_uri())
.to eq 'otpauth://hotp/Example.com:m%40mdp.im?secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&issuer=Example.com&counter=0'
.to eq 'otpauth://hotp/m%40mdp.im?secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&counter=0'
end

it 'allow passing a name to override the OTP name' do
expect(hotp.provisioning_uri('mark@percival'))
.to eq 'otpauth://hotp/Example.com:mark%40percival?secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&issuer=Example.com&counter=0'
.to eq 'otpauth://hotp/mark%40percival?secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&counter=0'
end

it 'also accepts a custom counter value' do
expect(hotp.provisioning_uri('mark@percival', 17))
.to eq 'otpauth://hotp/Example.com:mark%40percival?secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&issuer=Example.com&counter=17'
.to eq 'otpauth://hotp/mark%40percival?secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&counter=17'
end

context 'with non-standard provisioning_params' do
Expand All @@ -134,5 +135,20 @@
expect(params['image'].first).to eq 'https://example.com/icon.png'
end
end

context "with an issuer" do
let(:hotp) { ROTP::HOTP.new('a' * 32, name: "[email protected]", issuer: "Example.com") }

it 'created from the otp instance data' do
expect(hotp.provisioning_uri())
.to eq 'otpauth://hotp/Example.com:m%40mdp.im?secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&issuer=Example.com&counter=0'
end

it 'allow passing a name to override the OTP name' do
expect(hotp.provisioning_uri('mark@percival'))
.to eq 'otpauth://hotp/Example.com:mark%40percival?secret=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&issuer=Example.com&counter=0'
end
end

end
end
22 changes: 19 additions & 3 deletions spec/lib/rotp/totp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ def get_timecodes(at, b, a)


describe '#provisioning_uri' do
let(:totp) { ROTP::TOTP.new(TEST_SECRET, name: "[email protected]", issuer: "Example.com") }
let(:totp) { ROTP::TOTP.new(TEST_SECRET, name: "[email protected]") }

it 'creates a provisioning uri from the OTP instance' do
expect(totp.provisioning_uri())
.to eq 'otpauth://totp/Example.com:m%40mdp.im?secret=JBSWY3DPEHPK3PXP&issuer=Example.com'
.to eq 'otpauth://totp/m%40mdp.im?secret=JBSWY3DPEHPK3PXP'
end

it 'allow passing a name to override the OTP name' do
expect(totp.provisioning_uri('mark@percival'))
.to eq 'otpauth://totp/Example.com:mark%40percival?secret=JBSWY3DPEHPK3PXP&issuer=Example.com'
.to eq 'otpauth://totp/mark%40percival?secret=JBSWY3DPEHPK3PXP'
end

context 'with non-standard provisioning_params' do
Expand All @@ -249,6 +249,22 @@ def get_timecodes(at, b, a)
end

end

context "with an issuer" do
let(:totp) { ROTP::TOTP.new(TEST_SECRET, name: "[email protected]", issuer: "Example.com") }

it 'creates a provisioning uri from the OTP instance' do
expect(totp.provisioning_uri())
.to eq 'otpauth://totp/Example.com:m%40mdp.im?secret=JBSWY3DPEHPK3PXP&issuer=Example.com'
end

it 'allow passing a name to override the OTP name' do
expect(totp.provisioning_uri('mark@percival'))
.to eq 'otpauth://totp/Example.com:mark%40percival?secret=JBSWY3DPEHPK3PXP&issuer=Example.com'
end

end

end

describe '#now' do
Expand Down

0 comments on commit 42ef301

Please sign in to comment.