diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-12-20 17:22:11 +0300 |
commit | 0c872e02b2c822e3397515ec324051ff540f0cd5 (patch) | |
tree | ce2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/services/jira_connect | |
parent | f7e05a6853b12f02911494c4b3fe53d9540d74fc (diff) |
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/services/jira_connect')
-rw-r--r-- | spec/services/jira_connect/create_asymmetric_jwt_service_spec.rb | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/spec/services/jira_connect/create_asymmetric_jwt_service_spec.rb b/spec/services/jira_connect/create_asymmetric_jwt_service_spec.rb index f5359e5b643..bb96e327307 100644 --- a/spec/services/jira_connect/create_asymmetric_jwt_service_spec.rb +++ b/spec/services/jira_connect/create_asymmetric_jwt_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe JiraConnect::CreateAsymmetricJwtService do +RSpec.describe JiraConnect::CreateAsymmetricJwtService, feature_category: :integrations do describe '#execute' do let_it_be(:jira_connect_installation) { create(:jira_connect_installation) } @@ -19,27 +19,40 @@ RSpec.describe JiraConnect::CreateAsymmetricJwtService do let(:public_key_id) { Atlassian::Jwt.decode(jwt_token, nil, false, algorithm: 'RS256').last['kid'] } let(:public_key_cdn) { 'https://gitlab.com/-/jira_connect/public_keys/' } + let(:event_url) { 'https://gitlab.test/-/jira_connect/events/installed' } let(:jwt_verification_claims) do { aud: 'https://gitlab.test/-/jira_connect', iss: jira_connect_installation.client_key, - qsh: Atlassian::Jwt.create_query_string_hash('https://gitlab.test/-/jira_connect/events/installed', 'POST', 'https://gitlab.test/-/jira_connect') + qsh: Atlassian::Jwt.create_query_string_hash(event_url, 'POST', 'https://gitlab.test/-/jira_connect') } end subject(:jwt_token) { service.execute } + shared_examples 'produces a valid JWT' do + it 'produces a valid JWT' do + public_key = OpenSSL::PKey.read(JiraConnect::PublicKey.find(public_key_id).key) + options = jwt_verification_claims.except(:qsh).merge({ verify_aud: true, verify_iss: true, + algorithm: 'RS256' }) + + decoded_token = Atlassian::Jwt.decode(jwt_token, public_key, true, options).first + + expect(decoded_token).to eq(jwt_verification_claims.stringify_keys) + end + end + it 'stores the public key' do expect { JiraConnect::PublicKey.find(public_key_id) }.not_to raise_error end - it 'is produces a valid JWT' do - public_key = OpenSSL::PKey.read(JiraConnect::PublicKey.find(public_key_id).key) - options = jwt_verification_claims.except(:qsh).merge({ verify_aud: true, verify_iss: true, algorithm: 'RS256' }) + it_behaves_like 'produces a valid JWT' - decoded_token = Atlassian::Jwt.decode(jwt_token, public_key, true, options).first + context 'with uninstalled event option' do + let(:service) { described_class.new(jira_connect_installation, event: :uninstalled) } + let(:event_url) { 'https://gitlab.test/-/jira_connect/events/uninstalled' } - expect(decoded_token).to eq(jwt_verification_claims.stringify_keys) + it_behaves_like 'produces a valid JWT' end end end |