Skip to content

Commit 5c83479

Browse files
committed
CC refactors
1 parent e7d8b6e commit 5c83479

File tree

6 files changed

+21
-10
lines changed

6 files changed

+21
-10
lines changed

app/domain/authentication/authn_jwt/v2/data_objects/authenticator_contract.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class AuthenticatorContract < Dry::Validation::Contract
7777

7878
# Verify that a variable has been created for one of: `jwks-uri`, `public-keys`, or `provider-uri`
7979
rule(:jwks_uri, :public_keys, :provider_uri) do
80-
if %i[jwks_uri provider_uri public_keys].all? { |item| values[item].nil? }
80+
if all_are?(array: %i[jwks_uri provider_uri public_keys], values: values, check: :nil?)
8181
utils.failed_response(
8282
key: key,
8383
error: Errors::Authentication::AuthnJwt::InvalidSigningKeySettings.new(
@@ -89,7 +89,8 @@ class AuthenticatorContract < Dry::Validation::Contract
8989

9090
# Verify that a variable has been set for one of: `jwks-uri`, `public-keys`, or `provider-uri`
9191
rule(:jwks_uri, :public_keys, :provider_uri) do
92-
if %i[jwks_uri provider_uri public_keys].all? { |item| values[item].blank? }
92+
if all_are?(array: %i[jwks_uri provider_uri public_keys], values: values, check: :blank?)
93+
# if %i[jwks_uri provider_uri public_keys].all? { |item| values[item].blank? }
9394
utils.failed_response(
9495
key: key,
9596
error: Errors::Authentication::AuthnJwt::InvalidSigningKeySettings.new(
@@ -328,6 +329,12 @@ def variable_empty?(key:, values:, variable:)
328329
)
329330
)
330331
end
332+
333+
def all_are?(array:, values:, check:)
334+
array.all? { |item| values[item].send(check) }
335+
end
336+
337+
331338
end
332339
end
333340
end

app/domain/authentication/authn_oidc/v2/strategy.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ module Authentication
44
module AuthnOidc
55
module V2
66
class Strategy
7+
REQUIRED_PARAMS = %i[code nonce].freeze
8+
79
def initialize(
810
authenticator:,
911
client: Authentication::AuthnOidc::V2::Client,
@@ -16,7 +18,7 @@ def initialize(
1618

1719
def callback(parameters:, request_body: nil)
1820
# NOTE: `code_verifier` param is optional
19-
%i[code nonce].each do |param|
21+
REQUIRED_PARAMS.each do |param|
2022
unless parameters[param].present?
2123
raise Errors::Authentication::RequestBody::MissingRequestParam, param.to_s
2224
end

dev/start

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,9 @@ init_jwt() {
433433

434434
# OIDC is a special case on JWT, JWT automation tests contain scenarios with
435435
# OIDC providers.
436-
configure_oidc_providers
436+
# configure_oidc_providers
437+
configure_oidc_authenticators
438+
enable_oidc_authenticators
437439

438440
echo "Configure jwks provider"
439441
docker-compose exec jwks "/tmp/create_nginx_certificate.sh"

spec/app/db/repository/authenticator_repository_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
arguments.each do |variable|
6767
::Secret.create(
6868
resource_id: "rspec:variable:conjur/authn-oidc/#{service}/#{variable}",
69-
value: "#{variable}"
69+
value: variable.to_s
7070
)
7171
end
7272
end

spec/app/domain/authentication/authn-jwt/v2/data_objects/authenticator_contract_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'spec_helper'
44

55
RSpec.describe(Authentication::AuthnOidc::V2::DataObjects::AuthenticatorContract) do
6-
subject { Authentication::AuthnJwt::V2::DataObjects::AuthenticatorContract.new.call(**params) }
6+
subject { Authentication::AuthnJwt::V2::DataObjects::AuthenticatorContract.new(utils: ::Util::ContractUtils).call(**params) }
77
let(:default_args) { { account: 'foo', service_id: 'bar' } }
88
let(:public_keys) { '{"type":"jwks","value":{"keys":[{}]}}' }
99

@@ -238,7 +238,7 @@
238238
end
239239
end
240240
context 'with claims in reserved claim list' do
241-
let(:contract) { Authentication::AuthnJwt::V2::DataObjects::AuthenticatorContract.new }
241+
let(:contract) { Authentication::AuthnJwt::V2::DataObjects::AuthenticatorContract.new(utils: ::Util::ContractUtils) }
242242
%w[iss exp nbf iat jti aud].each do |reserved_claim|
243243
enforced_claims = "foo-bar/b, #{reserved_claim}"
244244
it 'is unsuccessful' do
@@ -312,7 +312,7 @@
312312
end
313313
end
314314
context 'with claim alias in reserved claim list' do
315-
let(:contract) { Authentication::AuthnJwt::V2::DataObjects::AuthenticatorContract.new }
315+
let(:contract) { Authentication::AuthnJwt::V2::DataObjects::AuthenticatorContract.new(utils: ::Util::ContractUtils) }
316316
%w[iss exp nbf iat jti aud].each do |reserved_claim|
317317
enforced_claims = "foo:bar/b, #{reserved_claim}:bing/baz"
318318
it 'is unsuccessful' do
@@ -325,7 +325,7 @@
325325
end
326326
end
327327
context 'with claim target in reserved claim list' do
328-
let(:contract) { Authentication::AuthnJwt::V2::DataObjects::AuthenticatorContract.new }
328+
let(:contract) { Authentication::AuthnJwt::V2::DataObjects::AuthenticatorContract.new(utils: ::Util::ContractUtils) }
329329
%w[iss exp nbf iat jti aud].each do |reserved_claim|
330330
enforced_claims = "foo:bar/b, bing:#{reserved_claim}"
331331
it 'is unsuccessful' do

spec/app/domain/authentication/authn-jwt/v2/resolve_identity_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@
275275
let(:allowed_roles) do
276276
[
277277
{ role_id: 'rspec:host:bill', annotations: {} },
278-
{ role_id: 'rspec:host:bob',
278+
{ role_id: 'rspec:user:bob',
279279
annotations: {
280280
'authn-jwt/bar/project_id' => 'test-1',
281281
'authn-jwt/bar/iss' => 'test-2'

0 commit comments

Comments
 (0)