Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multivalued property to keycloak_protocol_mapper #336

Merged
merged 1 commit into from
Nov 26, 2024
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
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