debian-mirror-gitlab/spec/requests/jwks_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.5 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-05-27 22:25:52 +05:30
RSpec.describe JwksController, feature_category: :system_access do
2021-12-11 22:18:48 +05:30
describe 'Endpoints from the parent Doorkeeper::OpenidConnect::DiscoveryController' do
it 'respond successfully' do
[
"/oauth/discovery/keys",
"/.well-known/openid-configuration",
"/.well-known/webfinger?resource=#{create(:user).email}"
].each do |endpoint|
get endpoint
expect(response).to have_gitlab_http_status(:ok)
end
end
end
2021-03-08 18:12:59 +05:30
describe 'GET /-/jwks' do
2022-08-13 15:12:31 +05:30
let_it_be(:ci_jwt_signing_key) { OpenSSL::PKey::RSA.generate(3072) }
let_it_be(:ci_jwk) { ci_jwt_signing_key.to_jwk }
let_it_be(:oidc_jwk) { OpenSSL::PKey::RSA.new(Rails.application.secrets.openid_connect_signing_key).to_jwk }
2021-01-29 00:20:46 +05:30
before do
stub_application_setting(ci_jwt_signing_key: ci_jwt_signing_key.to_s)
end
it 'returns signing keys used to sign CI_JOB_JWT' do
2021-03-08 18:12:59 +05:30
get jwks_url
2021-01-29 00:20:46 +05:30
expect(response).to have_gitlab_http_status(:ok)
ids = json_response['keys'].map { |jwk| jwk['kid'] }
expect(ids).to contain_exactly(ci_jwk['kid'], oidc_jwk['kid'])
end
it 'does not leak private key data' do
2021-03-08 18:12:59 +05:30
get jwks_url
2021-01-29 00:20:46 +05:30
aggregate_failures do
json_response['keys'].each do |jwk|
expect(jwk.keys).to contain_exactly('kty', 'kid', 'e', 'n', 'use', 'alg')
expect(jwk['use']).to eq('sig')
expect(jwk['alg']).to eq('RS256')
end
end
end
end
end