|
41 | 41 | end |
42 | 42 |
|
43 | 43 | context 'when the ID token indicates domain verification' do |
44 | | - # Sign a fake ID token with our own local key |
45 | | - let(:mock_key) do |
46 | | - optional_parameters = { kid: 'mock-kid', use: 'sig', alg: 'RS256' } |
| 44 | + let(:mock_oidc_key) do |
| 45 | + optional_parameters = { kid: 'mock_oidc_key', use: 'sig', alg: 'RS256' } |
47 | 46 | JWT::JWK.new(OpenSSL::PKey::RSA.new(2048), optional_parameters) |
48 | 47 | end |
49 | | - let(:id_token) do |
50 | | - payload = { email: email, xms_edov: true } |
51 | | - JWT.encode(payload, mock_key.signing_key, mock_key[:alg], kid: mock_key[:kid]) |
| 48 | + |
| 49 | + let(:mock_common_key) do |
| 50 | + optional_parameters = { kid: 'mock_common_key', use: 'sig', alg: 'RS256' } |
| 51 | + JWT::JWK.new(OpenSSL::PKey::RSA.new(2048), optional_parameters) |
52 | 52 | end |
53 | 53 |
|
54 | | - # Mock the API responses to return the local key |
| 54 | + # Mock the API responses to return the mock keys |
55 | 55 | before do |
56 | 56 | allow(access_token).to receive(:get) |
57 | 57 | .with(OmniAuth::MicrosoftGraph::OIDC_CONFIG_URL) |
58 | 58 | .and_return( |
59 | | - double('OAuth2::Response', parsed: { |
60 | | - 'id_token_signing_alg_values_supported' => ['RS256'], |
61 | | - 'jwks_uri' => 'https://example.com/jwks-keys' |
62 | | - }) |
| 59 | + double( |
| 60 | + 'OAuth2::Response', |
| 61 | + parsed: { |
| 62 | + 'id_token_signing_alg_values_supported' => ['RS256'], |
| 63 | + 'jwks_uri' => 'https://example.com/jwks-keys', |
| 64 | + } |
| 65 | + ) |
63 | 66 | ) |
64 | 67 | allow(access_token).to receive(:get) |
65 | 68 | .with('https://example.com/jwks-keys') |
66 | 69 | .and_return( |
67 | | - double('OAuth2::Response', parsed: JWT::JWK::Set.new(mock_key).export) |
| 70 | + double( |
| 71 | + 'OAuth2::Response', |
| 72 | + parsed: JWT::JWK::Set.new(mock_oidc_key).export |
| 73 | + ) |
| 74 | + ) |
| 75 | + allow(access_token).to receive(:get) |
| 76 | + .with(OmniAuth::MicrosoftGraph::COMMON_JWKS_URL) |
| 77 | + .and_return( |
| 78 | + double( |
| 79 | + 'OAuth2::Response', |
| 80 | + parsed: JWT::JWK::Set.new(mock_common_key).export, |
| 81 | + body: JWT::JWK::Set.new(mock_common_key).export.to_json |
| 82 | + ) |
68 | 83 | ) |
69 | 84 | end |
70 | 85 |
|
71 | | - it { is_expected.to be_truthy } |
| 86 | + context 'when the kid exists in the oidc key' do |
| 87 | + let(:id_token) do |
| 88 | + payload = { email: email, xms_edov: true } |
| 89 | + JWT.encode(payload, mock_oidc_key.signing_key, mock_oidc_key[:alg], kid: mock_oidc_key[:kid]) |
| 90 | + end |
| 91 | + |
| 92 | + it { is_expected.to be_truthy } |
| 93 | + end |
| 94 | + |
| 95 | + context "when the kid exists in the common key" do |
| 96 | + let(:id_token) do |
| 97 | + payload = { email: email, xms_edov: true } |
| 98 | + JWT.encode(payload, mock_common_key.signing_key, mock_common_key[:alg], kid: mock_common_key[:kid]) |
| 99 | + end |
| 100 | + |
| 101 | + it { is_expected.to be_truthy } |
| 102 | + end |
72 | 103 | end |
73 | 104 |
|
74 | 105 | context 'when all verification strategies fail' do |
|
0 commit comments