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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Atlassian::JiraConnect::Jwt::Symmetric, feature_category: :integrations do
let(:shared_secret) { 'secret' }
describe '#iss_claim' do
let(:jwt) { Atlassian::Jwt.encode({ iss: '123' }, shared_secret) }
subject { described_class.new(jwt).iss_claim }
it { is_expected.to eq('123') }
context 'invalid JWT' do
let(:jwt) { '123' }
it { is_expected.to eq(nil) }
end
end
describe '#sub_claim' do
let(:jwt) { Atlassian::Jwt.encode({ sub: '123' }, shared_secret) }
subject { described_class.new(jwt).sub_claim }
it { is_expected.to eq('123') }
context 'invalid JWT' do
let(:jwt) { '123' }
it { is_expected.to eq(nil) }
end
end
describe '#valid?' do
subject { described_class.new(jwt).valid?(shared_secret) }
context 'invalid JWT' do
let(:jwt) { '123' }
it { is_expected.to eq(false) }
end
context 'valid JWT' do
let(:jwt) { Atlassian::Jwt.encode({}, shared_secret) }
it { is_expected.to eq(true) }
end
end
describe '#verify_qsh_claim' do
let(:jwt) { Atlassian::Jwt.encode({ qsh: qsh_claim }, shared_secret) }
let(:qsh_claim) do
Atlassian::Jwt.create_query_string_hash('https://gitlab.test/subscriptions', 'GET', 'https://gitlab.test')
end
subject(:verify_qsh_claim) do
described_class.new(jwt).verify_qsh_claim('https://gitlab.test/subscriptions', 'GET', 'https://gitlab.test')
end
it { is_expected.to eq(true) }
context 'qsh does not match' do
let(:qsh_claim) do
Atlassian::Jwt.create_query_string_hash('https://example.com/foo', 'POST', 'https://example.com')
end
it { is_expected.to eq(false) }
end
context 'creating query string hash raises an error' do
let(:qsh_claim) { '123' }
specify do
expect(Atlassian::Jwt).to receive(:create_query_string_hash).and_raise(StandardError)
expect(verify_qsh_claim).to eq(false)
end
end
end
describe '#verify_context_qsh_claim' do
let(:jwt) { Atlassian::Jwt.encode({ qsh: qsh_claim }, shared_secret) }
let(:qsh_claim) { 'context-qsh' }
subject(:verify_context_qsh_claim) { described_class.new(jwt).verify_context_qsh_claim }
it { is_expected.to eq(true) }
context 'jwt does not contain a context qsh' do
let(:qsh_claim) { '123' }
it { is_expected.to eq(false) }
end
end
end
|