Skip to content

Commit 94bba3e

Browse files
committed
Update keycloak_flow_execution to handle script authenticators
1 parent 8516850 commit 94bba3e

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

lib/puppet/provider/keycloak_flow_execution/kcadm.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ def self.instances
5555
execution[:flow_alias] = parent_level[1][-1] if parent_level.size > 1
5656
end
5757
execution[:provider_id] = e['providerId']
58+
if e['authenticationConfig'] =~ %r{^script-.+}
59+
execution[:provider_id] = e['authenticationConfig']
60+
end
5861
execution[:alias] = e['alias']
5962
execution[:name] = "#{execution[:provider_id]} under #{execution[:flow_alias]} on #{realm}"
6063
if e['authenticationFlow']

spec/acceptance/9_flow_spec.rb

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ class { 'keycloak': }
1919
'Keycloak_flow_execution[duo-universal under form-browser-with-duo on test]',
2020
],
2121
}
22+
keycloak::spi_deployment { 'osc-keycloak-scripts':
23+
deployed_name => 'osc-keycloak-scripts-jar-with-dependencies.jar',
24+
source => "https://github.com/OSC/osc-keycloak-scripts/releases/download/1.1.0/osc-keycloak-scripts-jar-with-dependencies.jar",
25+
test_url => 'authentication/authenticator-providers',
26+
test_key => 'id',
27+
test_value => 'script-user-enabled-authenticator.js',
28+
test_realm => 'test',
29+
test_before => [
30+
'Keycloak_flow[form-browser-with-duo]',
31+
'Keycloak_flow_execution[script-user-enabled-authenticator.js under form-browser-with-duo on test]',
32+
],
33+
}
2234
keycloak_realm { 'test': ensure => 'present' }
2335
keycloak_flow { 'browser-with-duo on test':
2436
ensure => 'present',
@@ -52,6 +64,11 @@ class { 'keycloak': }
5264
priority => 10,
5365
requirement => 'REQUIRED',
5466
}
67+
keycloak_flow_execution { 'script-user-enabled-authenticator.js under form-browser-with-duo on test':
68+
ensure => 'present',
69+
requirement => 'REQUIRED',
70+
priority => 15,
71+
}
5572
keycloak_flow_execution { 'duo-universal under form-browser-with-duo on test':
5673
ensure => 'present',
5774
configurable => true,
@@ -93,8 +110,10 @@ class { 'keycloak': }
93110
expect(form['description']).to eq('Form Browser with DUO')
94111
auth_form = data.find { |d| d['providerId'] == 'auth-username-password-form' }
95112
expect(auth_form['index']).to eq(0)
113+
script = data.find { |d| d['authenticationConfig'] == 'script-user-enabled-authenticator.js' }
114+
expect(script['index']).to eq(1)
96115
duo = data.find { |d| d['providerId'] == 'duo-universal' }
97-
expect(duo['index']).to eq(1)
116+
expect(duo['index']).to eq(2)
98117
end
99118
end
100119
end
@@ -115,6 +134,18 @@ class { 'keycloak': }
115134
'Keycloak_flow_execution[duo-universal under form-browser-with-duo on test]',
116135
],
117136
}
137+
keycloak::spi_deployment { 'osc-keycloak-scripts':
138+
deployed_name => 'osc-keycloak-scripts-jar-with-dependencies.jar',
139+
source => "https://github.com/OSC/osc-keycloak-scripts/releases/download/1.1.0/osc-keycloak-scripts-jar-with-dependencies.jar",
140+
test_url => 'authentication/authenticator-providers',
141+
test_key => 'id',
142+
test_value => 'script-user-enabled-authenticator.js',
143+
test_realm => 'test',
144+
test_before => [
145+
'Keycloak_flow[form-browser-with-duo]',
146+
'Keycloak_flow_execution[script-user-enabled-authenticator.js under form-browser-with-duo on test]',
147+
],
148+
}
118149
keycloak_realm { 'test': ensure => 'present' }
119150
keycloak_flow { 'browser-with-duo on test':
120151
ensure => 'present',
@@ -161,6 +192,11 @@ class { 'keycloak': }
161192
priority => 25,
162193
requirement => 'REQUIRED',
163194
}
195+
keycloak_flow_execution { 'script-user-enabled-authenticator.js under form-browser-with-duo on test':
196+
ensure => 'present',
197+
requirement => 'REQUIRED',
198+
priority => 35,
199+
}
164200
PUPPET_PP
165201

166202
apply_manifest(pp, catch_failures: true)
@@ -187,6 +223,8 @@ class { 'keycloak': }
187223
expect(auth_form['index']).to eq(1)
188224
duo = data.find { |d| d['providerId'] == 'duo-universal' }
189225
expect(duo['index']).to eq(0)
226+
script = data.find { |d| d['authenticationConfig'] == 'script-user-enabled-authenticator.js' }
227+
expect(script['index']).to eq(2)
190228
end
191229
end
192230
end

spec/fixtures/unit/puppet/provider/keycloak_flow_execution/kcadm/get-executions.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,16 @@
4646
"authenticationConfig" : "be93a426-077f-4235-9686-677ff0706bf8",
4747
"level" : 1,
4848
"index" : 1
49+
}, {
50+
"id" : "fe1692cb-5a30-4312-ac1a-25dce4cad7ef",
51+
"requirement" : "DISABLED",
52+
"displayName" : "User Enabled Authenticator",
53+
"alias" : "User Enabled Authenticator",
54+
"requirementChoices" : [ "REQUIRED", "ALTERNATIVE", "DISABLED" ],
55+
"configurable" : true,
56+
"providerId" : "ONRXE2LQOQWXK43FOIWWK3TBMJWGKZBNMF2XI2DFNZ2GSY3BORXXELTKOM",
57+
"authenticationConfig" : "script-user-enabled-authenticator.js",
58+
"level" : 0,
59+
"index" : 3,
60+
"priority" : 31
4961
} ]

spec/spec_helper_acceptance_setup.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
keycloak::hostname: localhost
3636
keycloak::db: mariadb
3737
keycloak::proxy: edge
38+
keycloak::features:
39+
- scripts
3840
# Force only listen on IPv4 for testing
3941
keycloak::java_opts: '-Djava.net.preferIPv4Stack=true'
4042
postgresql::server::service_status: 'service postgresql status 2>/dev/null 1>/dev/null'

spec/unit/puppet/provider/keycloak_flow_execution/kcadm_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,29 @@
2020
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows', 'test').and_return(my_fixture_read('get-test.out'))
2121
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows/browser-with-duo/executions', 'test').and_return(my_fixture_read('get-executions.out'))
2222
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/be93a426-077f-4235-9686-677ff0706bf8', 'test').and_return('{}')
23-
expect(described_class.instances.length).to eq(4)
23+
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/script-user-enabled-authenticator.js', 'test').and_return('{}')
24+
expect(described_class.instances.length).to eq(5)
2425
end
2526

2627
it 'returns the resource for a flow' do
2728
allow(described_class).to receive(:realms).and_return(['test'])
2829
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows', 'test').and_return(my_fixture_read('get-test.out'))
2930
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows/browser-with-duo/executions', 'test').and_return(my_fixture_read('get-executions.out'))
3031
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/be93a426-077f-4235-9686-677ff0706bf8', 'test').and_return('{}')
32+
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/script-user-enabled-authenticator.js', 'test').and_return('{}')
3133
property_hash = described_class.instances[0].instance_variable_get('@property_hash')
3234
expect(property_hash[:name]).to eq('auth-cookie under browser-with-duo on test')
3335
end
36+
37+
it 'returns script execution' do
38+
allow(described_class).to receive(:realms).and_return(['test'])
39+
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows', 'test').and_return(my_fixture_read('get-test.out'))
40+
allow(described_class).to receive(:kcadm).with('get', 'authentication/flows/browser-with-duo/executions', 'test').and_return(my_fixture_read('get-executions.out'))
41+
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/be93a426-077f-4235-9686-677ff0706bf8', 'test').and_return('{}')
42+
allow(described_class).to receive(:kcadm).with('get', 'authentication/config/script-user-enabled-authenticator.js', 'test').and_return('{}')
43+
property_hash = described_class.instances.last.instance_variable_get('@property_hash')
44+
expect(property_hash[:provider_id]).to eq('script-user-enabled-authenticator.js')
45+
end
3446
end
3547
# describe 'self.prefetch' do
3648
# let(:instances) do

0 commit comments

Comments
 (0)