Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/service_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def live?
active? && approved?
end

def piv_cac_available?
PivCacService.piv_cac_available_for_agency?(agency)
def piv_cac_available?(user = nil)
PivCacService.piv_cac_available_for_agency?(agency, user&.email)
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/presenters/two_factor_options_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def available_2fa_types

def piv_cac_if_available
return [] if current_user.piv_cac_enabled?
return [] unless current_user.piv_cac_available? || service_provider&.piv_cac_available?
return [] unless current_user.piv_cac_available? ||
service_provider&.piv_cac_available?(current_user)
%w[piv_cac]
end
end
1 change: 1 addition & 0 deletions config/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ production:
password_pepper: # generate via `rake secret`
password_strength_enabled: 'true'
piv_cac_agencies: '["DOD","NGA","EOP"]'
piv_cac_agencies_scoped_by_email: '["GSA"]'
piv_cac_email_domains: '[".mil"]'
piv_cac_enabled: 'false'
pkcs11_lib: '/opt/cloudhsm/lib/libcloudhsm_pkcs11.so'
Expand Down
23 changes: 14 additions & 9 deletions spec/models/service_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,30 @@
describe 'piv_cac_available?' do
context 'when the service provider is with an enabled agency' do
it 'is truthy' do
allow(Figaro.env).to receive(:piv_cac_agencies).and_return(
[service_provider.agency].to_json
)
PivCacService.send(:reset_piv_cac_avaialable_agencies)

allow(PivCacService).to receive(:piv_cac_available_for_agency?).and_return(true)
expect(service_provider.piv_cac_available?).to be_truthy
end
end

context 'when the service provider agency is not enabled' do
it 'is falsey' do
allow(Figaro.env).to receive(:piv_cac_agencies).and_return(
[service_provider.agency + 'X'].to_json
)
PivCacService.send(:reset_piv_cac_avaialable_agencies)
allow(PivCacService).to receive(:piv_cac_available_for_agency?).and_return(false)

expect(service_provider.piv_cac_available?).to be_falsey
end
end

context 'when the service provider setting depends on the user email' do
let(:user) { build(:user) }

it 'calls with the user email' do
expect(PivCacService).to receive(
:piv_cac_available_for_agency?
).with(service_provider.agency, user.email)

service_provider.piv_cac_available?(user)
end
end
end

describe '#encryption_opts' do
Expand Down