/
hmac_spec.rb
63 lines (53 loc) · 1.69 KB
/
hmac_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# frozen_string_literal: true
RSpec.describe JWT::JWK::HMAC do
let(:hmac_key) { 'secret-key' }
describe '.new' do
subject { described_class.new(key) }
context 'when a secret key given' do
let(:key) { hmac_key }
it 'creates an instance of the class' do
expect(subject).to be_a described_class
expect(subject.private?).to eq true
end
end
end
describe '#export' do
let(:kid) { nil }
context 'when key is exported' do
let(:key) { hmac_key }
subject { described_class.new(key, kid).export }
it 'returns a hash with the key' do
expect(subject).to be_a Hash
expect(subject).to include(:kty, :kid)
end
end
context 'when key is exported with private key' do
let(:key) { hmac_key }
subject { described_class.new(key, kid).export(include_private: true) }
it 'returns a hash with the key' do
expect(subject).to be_a Hash
expect(subject).to include(:kty, :kid, :k)
end
end
end
describe '.import' do
subject { described_class.import(params) }
let(:exported_key) { described_class.new(key).export(include_private: true) }
context 'when secret key is given' do
let(:key) { hmac_key }
let(:params) { exported_key }
it 'returns a key' do
expect(subject).to be_a described_class
expect(subject.export(include_private: true)).to eq(exported_key)
end
context 'with a custom "kid" value' do
let(:exported_key) {
super().merge(kid: 'custom_key_identifier')
}
it 'imports that "kid" value' do
expect(subject.kid).to eq('custom_key_identifier')
end
end
end
end
end