diff --git a/lib/puppet/provider/keycloak_protocol_mapper/kcadm.rb b/lib/puppet/provider/keycloak_protocol_mapper/kcadm.rb index 231c0c93..ee033c9a 100644 --- a/lib/puppet/provider/keycloak_protocol_mapper/kcadm.rb +++ b/lib/puppet/provider/keycloak_protocol_mapper/kcadm.rb @@ -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 @@ -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)) @@ -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') diff --git a/lib/puppet/type/keycloak_protocol_mapper.rb b/lib/puppet/type/keycloak_protocol_mapper.rb index 7bbd9884..b06dfd71 100644 --- a/lib/puppet/type/keycloak_protocol_mapper.rb +++ b/lib/puppet/type/keycloak_protocol_mapper.rb @@ -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 diff --git a/spec/unit/puppet/type/keycloak_client_protocol_mapper_spec.rb b/spec/unit/puppet/type/keycloak_client_protocol_mapper_spec.rb index 42be10e8..fa0285dc 100644 --- a/spec/unit/puppet/type/keycloak_client_protocol_mapper_spec.rb +++ b/spec/unit/puppet/type/keycloak_client_protocol_mapper_spec.rb @@ -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}) diff --git a/spec/unit/puppet/type/keycloak_protocol_mapper_spec.rb b/spec/unit/puppet/type/keycloak_protocol_mapper_spec.rb index e7a437a3..c8517aaf 100644 --- a/spec/unit/puppet/type/keycloak_protocol_mapper_spec.rb +++ b/spec/unit/puppet/type/keycloak_protocol_mapper_spec.rb @@ -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'