-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'spec_helper' | ||
|
||
describe LicenseKeyLookupService do | ||
context 'when key is a legacy encrypted key' do | ||
let(:key) { 'bdcecdc23c0f48229f77357151d1e67f-8e1ae3236636bfe57893b835871553eb-524ffec53ad05c14bbf3339eec741300-295512a0539cd0863abe42ddc29cf9v1' } | ||
let(:license_id) { key.split('-').first } | ||
let(:account) { create(:account) } | ||
|
||
context 'when key is a good key' do | ||
let(:digest) { '$2a$12$kh33FHu.TWYMZlWldcOMKet4YiVNqMHq8/A343/GTfPz.NRCPq2Q.' } | ||
|
||
let!(:license) { | ||
create(:license, id: license_id, key: digest, account:) | ||
} | ||
|
||
it 'should support authenticating' do | ||
l = described_class.call(key:, account:, legacy_encrypted: true) | ||
|
||
expect(l).to eq license | ||
end | ||
|
||
it 'should not rehash' do | ||
expect { described_class.call(key:, account:, legacy_encrypted: true) }.to_not( | ||
change { license.reload.key }, | ||
) | ||
end | ||
end | ||
|
||
context 'when key is a bad key' do | ||
let(:digest) { '$2a$12$kh33FHu.TWYMZlWldcOMKevM0Jj4VrN/8.EbfAj4cBEcS51A7hYUK' } | ||
|
||
let!(:license) { | ||
create(:license, id: license_id, key: digest, account:) | ||
} | ||
|
||
it 'should support authenticating' do | ||
l = described_class.call(key:, account:, legacy_encrypted: true) | ||
|
||
expect(l).to eq license | ||
end | ||
|
||
it 'should rehash' do | ||
expect { described_class.call(key:, account:, legacy_encrypted: true) }.to( | ||
change { license.reload.key }, | ||
) | ||
|
||
# sanity check | ||
ok = license.compare_hashed_token(:key, key, version: 'v1') | ||
expect(ok).to be true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'spec_helper' | ||
|
||
describe TokenLookupService do | ||
context 'when token is a legacy v1 token' do | ||
let(:token_value) { '1780aeccbbb14b4dad0cf8b8165faba2.52f61713fd0c49a2a6537e3142d043cb.3e2373c60b7df8514ff763dad707faad44956c2421fdb2588fff2a73099b07v1' } | ||
let(:account_id) { token_value.split('.').first } | ||
let(:token_id) { token_value.split('.').second } | ||
let(:account) { create(:account, id: account_id) } | ||
let(:product) { create(:product, account:) } | ||
|
||
context 'when token is a good token' do | ||
let(:digest) { '$2a$12$7sgr9E9ZURyXzttcuIl/muYRww.wHxNgCpgUHsKODV2ZXpPWiqLkq' } | ||
|
||
let!(:token) { | ||
t = create(:token, id: token_id, bearer: product, account:) | ||
t.update!(digest:) | ||
t | ||
} | ||
|
||
it 'should support authenticating' do | ||
t = described_class.call(token: token_value, account:) | ||
|
||
expect(t).to eq token | ||
end | ||
|
||
it 'should not rehash' do | ||
expect { described_class.call(token: token_value, account:) }.to_not( | ||
change { token.reload.digest }, | ||
) | ||
end | ||
end | ||
|
||
context 'when token is a bad token' do | ||
let(:digest) { '$2a$12$7sgr9E9ZURyXzttcuIl/muSl7JViEcBcytnbouQooX22PP43AzZ4C' } | ||
|
||
let!(:token) { | ||
t = create(:token, id: token_id, bearer: product, account:) | ||
t.update!(digest:) | ||
t | ||
} | ||
|
||
it 'should support authenticating' do | ||
t = described_class.call(token: token_value, account:) | ||
|
||
expect(t).to eq token | ||
end | ||
|
||
it 'should rehash' do | ||
expect { described_class.call(token: token_value, account:) }.to( | ||
change { token.reload.digest }, | ||
) | ||
|
||
# sanity check | ||
ok = token.compare_hashed_token(:digest, token_value, version: 'v1') | ||
expect(ok).to be true | ||
end | ||
end | ||
end | ||
end |