Skip to content

Commit

Permalink
Update keycloak_flow_execution to handle script authenticators
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Nov 16, 2024
1 parent 8516850 commit 14082c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/puppet/provider/keycloak_flow_execution/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def self.instances
execution[:flow_alias] = parent_level[1][-1] if parent_level.size > 1
end
execution[:provider_id] = e['providerId']
if e['authenticationConfig'] =~ %r{^script-.+}
execution[:provider_id] = e['authenticationConfig']
end
execution[:alias] = e['alias']
execution[:name] = "#{execution[:provider_id]} under #{execution[:flow_alias]} on #{realm}"
if e['authenticationFlow']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,16 @@
"authenticationConfig" : "be93a426-077f-4235-9686-677ff0706bf8",
"level" : 1,
"index" : 1
}, {
"id" : "fe1692cb-5a30-4312-ac1a-25dce4cad7ef",
"requirement" : "DISABLED",
"displayName" : "User Enabled Authenticator",
"alias" : "User Enabled Authenticator",
"requirementChoices" : [ "REQUIRED", "ALTERNATIVE", "DISABLED" ],
"configurable" : true,
"providerId" : "ONRXE2LQOQWXK43FOIWWK3TBMJWGKZBNMF2XI2DFNZ2GSY3BORXXELTKOM",
"authenticationConfig" : "script-user-enabled-authenticator.js",
"level" : 0,
"index" : 3,
"priority" : 31
} ]
14 changes: 13 additions & 1 deletion spec/unit/puppet/provider/keycloak_flow_execution/kcadm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,29 @@
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows', 'test').and_return(my_fixture_read('get-test.out'))
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows/browser-with-duo/executions', 'test').and_return(my_fixture_read('get-executions.out'))
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/be93a426-077f-4235-9686-677ff0706bf8', 'test').and_return('{}')
expect(described_class.instances.length).to eq(4)
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/script-user-enabled-authenticator.js', 'test').and_return('{}')
expect(described_class.instances.length).to eq(5)
end

it 'returns the resource for a flow' do
allow(described_class).to receive(:realms).and_return(['test'])
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows', 'test').and_return(my_fixture_read('get-test.out'))
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows/browser-with-duo/executions', 'test').and_return(my_fixture_read('get-executions.out'))
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/be93a426-077f-4235-9686-677ff0706bf8', 'test').and_return('{}')
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/script-user-enabled-authenticator.js', 'test').and_return('{}')
property_hash = described_class.instances[0].instance_variable_get('@property_hash')
expect(property_hash[:name]).to eq('auth-cookie under browser-with-duo on test')
end

it 'returns script execution' do
allow(described_class).to receive(:realms).and_return(['test'])
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows', 'test').and_return(my_fixture_read('get-test.out'))
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows/browser-with-duo/executions', 'test').and_return(my_fixture_read('get-executions.out'))
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/be93a426-077f-4235-9686-677ff0706bf8', 'test').and_return('{}')
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/script-user-enabled-authenticator.js', 'test').and_return('{}')
property_hash = described_class.instances.last.instance_variable_get('@property_hash')
expect(property_hash[:provider_id]).to eq('script-user-enabled-authenticator.js')
end
end
# describe 'self.prefetch' do
# let(:instances) do
Expand Down

0 comments on commit 14082c3

Please sign in to comment.