Skip to content

Commit

Permalink
Add multivalued property to keycloak_protocol_mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Nov 26, 2024
1 parent 14c8f9b commit 0f41cf8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/puppet/provider/keycloak_protocol_mapper/kcadm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def self.instances
if ['saml-group-membership-mapper', 'saml-role-list-mapper'].include?(protocol_mapper[:type]) || protocol_mapper[:type] =~ %r{script-.+}
protocol_mapper[:single] = d['config']['single'].to_s.to_sym
end
protocol_mapper[:multivalued] = d['config']['multivalued'].to_s.to_sym if d['config']['multivalued']
protocol_mappers << new(protocol_mapper)
end
end
Expand Down Expand Up @@ -136,6 +137,9 @@ def create
if (['saml-group-membership-mapper', 'saml-role-list-mapper'].include?(resource[:type]) || (resource[:protocol] == 'saml' && resource[:type] =~ %r{script-.+})) && resource[:single]
data[:config][:single] = resource[:single].to_s
end
if resource[:multivalued]
data[:config][:multivalued] = resource[:multivalued].to_s
end

t = Tempfile.new('keycloak_protocol_mapper')
t.write(JSON.pretty_generate(data))
Expand Down Expand Up @@ -220,6 +224,9 @@ def flush
if (['saml-group-membership-mapper', 'saml-role-list-mapper'].include?(resource[:type]) || (resource[:protocol] == 'saml' && resource[:type] =~ %r{script-.+})) && resource[:single]
config[:single] = resource[:single].to_s
end
if resource[:multivalued]
config[:multivalued] = resource[:multivalued].to_s
end
data[:config] = config unless config.empty?

t = Tempfile.new('keycloak_protocol_mapper')
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/keycloak_protocol_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@
end
end

newproperty(:multivalued, boolean: true) do
desc 'multivalued'
newvalues(:true, :false)
end

newproperty(:included_client_audience) do
desc 'included.client.audience Required for `type` of `oidc-audience-mapper`'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@
end

it 'does not accept invalid value for multivalued' do
config[:single] = 'foo'
config[:multivalued] = 'foo'
expect {
resource
}.to raise_error(%r{foo})
Expand Down
21 changes: 21 additions & 0 deletions spec/unit/puppet/type/keycloak_protocol_mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,27 @@
expect(resource[:included_client_audience]).to eq('foo')
end

it 'accepts value for multivalued' do
config[:multivalued] = false
expect(resource[:multivalued]).to eq(:false)
end

it 'accepts value for multivalued string' do
config[:multivalued] = 'false'
expect(resource[:multivalued]).to eq(:false)
end

it 'has default for multivalued' do
expect(resource[:multivalued]).to be_nil
end

it 'does not accept invalid value for multivalued' do
config[:multivalued] = 'foo'
expect {
resource
}.to raise_error(%r{foo})
end

it 'accepts script' do
config[:protocol] = 'saml'
config[:type] = 'script-foo.js'
Expand Down

0 comments on commit 0f41cf8

Please sign in to comment.