From 84b7c6d469c943aada2a1e702210ccbf6132397e Mon Sep 17 00:00:00 2001 From: treydock Date: Fri, 14 Jul 2023 15:15:39 -0400 Subject: [PATCH] Add cache_policy property to keycloal_ldap_user_provider (#296) Fixes #292 --- lib/puppet/type/keycloak_ldap_user_provider.rb | 6 ++++++ spec/acceptance/3_ldap_spec.rb | 3 +++ .../type/keycloak_ldap_user_provider_spec.rb | 14 ++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/lib/puppet/type/keycloak_ldap_user_provider.rb b/lib/puppet/type/keycloak_ldap_user_provider.rb index 0ff4fcfd..a0bbdb14 100644 --- a/lib/puppet/type/keycloak_ldap_user_provider.rb +++ b/lib/puppet/type/keycloak_ldap_user_provider.rb @@ -97,6 +97,12 @@ defaultto '0' end + newproperty(:cache_policy) do + desc 'cachePolicy' + newvalues('DEFAULT', 'EVICT_DAILY', 'EVICT_WEEKLY', 'MAX_LIFESPAN', 'NO_CACHE') + defaultto 'DEFAULT' + end + newproperty(:batch_size_for_sync) do desc 'batchSizeForSync' defaultto '1000' diff --git a/spec/acceptance/3_ldap_spec.rb b/spec/acceptance/3_ldap_spec.rb index 68239589..b6e4899d 100644 --- a/spec/acceptance/3_ldap_spec.rb +++ b/spec/acceptance/3_ldap_spec.rb @@ -52,6 +52,7 @@ class { 'keycloak': } expect(d['config']['trustEmail']).to eq(['false']) expect(d['config']['fullSyncPeriod']).to eq(['-1']) expect(d['config']['changedSyncPeriod']).to eq(['-1']) + expect(d['config']['cachePolicy']).to eq(['DEFAULT']) end end @@ -108,6 +109,7 @@ class { 'keycloak': } trust_email => true, full_sync_period => 60, changed_sync_period => 30, + cache_policy => 'EVICT_DAILY', } keycloak_ldap_mapper { 'full-name': realm => 'test', @@ -142,6 +144,7 @@ class { 'keycloak': } expect(d['config']['trustEmail']).to eq(['true']) expect(d['config']['fullSyncPeriod']).to eq(['60']) expect(d['config']['changedSyncPeriod']).to eq(['30']) + expect(d['config']['cachePolicy']).to eq(['EVICT_DAILY']) end end diff --git a/spec/unit/puppet/type/keycloak_ldap_user_provider_spec.rb b/spec/unit/puppet/type/keycloak_ldap_user_provider_spec.rb index 5d0456cb..0f2c7e18 100644 --- a/spec/unit/puppet/type/keycloak_ldap_user_provider_spec.rb +++ b/spec/unit/puppet/type/keycloak_ldap_user_provider_spec.rb @@ -182,6 +182,20 @@ expect { resource }.to raise_error(Puppet::Error, %r{must start with "\(" and end with "\)"}) end + it 'defaults cache_policy to default' do + expect(resource[:cache_policy]).to eq(:DEFAULT) + end + + it 'supports cache_policy to default' do + config[:cache_policy] = 'EVICT_DAILY' + expect(resource[:cache_policy]).to eq(:EVICT_DAILY) + end + + it 'does not allow invalid cache_policy' do + config[:cache_policy] = 'foo' + expect { resource }.to raise_error(Puppet::Error) + end + defaults = { enabled: :true, priority: '0',