Skip to content

Commit

Permalink
Implement password policy property
Browse files Browse the repository at this point in the history
  • Loading branch information
TuningYourCode committed Jun 19, 2024
1 parent 8f51082 commit 69ec356
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/puppet/type/keycloak_realm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ def should_to_s(_newvalue)
defaultto :false
end

newproperty(:password_policy) do
desc 'passwordPolicy'
end

newproperty(:roles, array_matching: :all, parent: PuppetX::Keycloak::ArrayProperty) do
desc 'roles'
defaultto ['offline_access', 'uma_authorization']
Expand Down
6 changes: 6 additions & 0 deletions spec/acceptance/2_realm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class { 'keycloak': }
otp_policy_digits => 8,
otp_policy_period => 30,
otp_policy_code_reusable => true,
password_policy => 'length(12) and notUsername(undefined) and notEmail(undefined) and forceExpiredPasswordChange(365) and hashIterations(27500) and passwordHistory(3) and regexPattern(^(?!\d+$)(?!.*test).*$) and specialChars(1) and upperCase(1) and lowerCase(1) and digits(1) and hashAlgorithm(pbkdf2-sha256) and maxLength(64)',
web_authn_policy_rp_entity_name => 'Keycloak',
web_authn_policy_signature_algorithms => ['ES256', 'ES384', 'ES512', 'RS256', 'RS384', 'RS512'],
web_authn_policy_rp_id => 'https://example.com',
Expand Down Expand Up @@ -258,6 +259,10 @@ class { 'keycloak': }

it 'has updated the realm' do
on hosts, '/opt/keycloak/bin/kcadm-wrapper.sh get realms/test' do
passwordPolicyValue = %w[length(12) and notUsername(undefined) and notEmail(undefined) and forceExpiredPasswordChange(365) and hashIterations(27_500] +

Check failure on line 262 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures.yml)

Naming/VariableName: Use snake_case for variable names. (https://rubystyle.guide#snake-case-symbols-methods-vars)

Check failure on line 262 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures.yml)

Style/WordArray: Use `['length(12)', 'and', 'notUsername(undefined)', 'and', 'notEmail(undefined)', 'and', 'forceExpiredPasswordChange(365)', 'and', 'hashIterations(27_500']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 262 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures-latest.yml)

Naming/VariableName: Use snake_case for variable names. (https://rubystyle.guide#snake-case-symbols-methods-vars)

Check failure on line 262 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures-latest.yml)

Style/WordArray: Use `['length(12)', 'and', 'notUsername(undefined)', 'and', 'notEmail(undefined)', 'and', 'forceExpiredPasswordChange(365)', 'and', 'hashIterations(27_500']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 262 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures.yml)

Naming/VariableName: Use snake_case for variable names. (https://rubystyle.guide#snake-case-symbols-methods-vars)

Check failure on line 262 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures.yml)

Style/WordArray: Use `['length(12)', 'and', 'notUsername(undefined)', 'and', 'notEmail(undefined)', 'and', 'forceExpiredPasswordChange(365)', 'and', 'hashIterations(27_500']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 262 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures-latest.yml)

Naming/VariableName: Use snake_case for variable names. (https://rubystyle.guide#snake-case-symbols-methods-vars)

Check failure on line 262 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures-latest.yml)

Style/WordArray: Use `['length(12)', 'and', 'notUsername(undefined)', 'and', 'notEmail(undefined)', 'and', 'forceExpiredPasswordChange(365)', 'and', 'hashIterations(27_500']` for an array of words. (https://rubystyle.guide#percent-w)
%w[ and passwordHistory(3) and regexPattern(^(?!\d+$)(?!.*test).*$) and specialChars(1) and upperCase(1)] +

Check failure on line 263 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures.yml)

Style/WordArray: Use `[ 'and', 'passwordHistory(3)', 'and', 'regexPattern(^(?!\\d+$)(?!.*test).*$)', 'and', 'specialChars(1)', 'and', 'upperCase(1)']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 263 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures.yml)

Layout/SpaceInsidePercentLiteralDelimiters: Do not use spaces inside percent literal delimiters.

Check failure on line 263 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures-latest.yml)

Style/WordArray: Use `[ 'and', 'passwordHistory(3)', 'and', 'regexPattern(^(?!\\d+$)(?!.*test).*$)', 'and', 'specialChars(1)', 'and', 'upperCase(1)']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 263 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures-latest.yml)

Layout/SpaceInsidePercentLiteralDelimiters: Do not use spaces inside percent literal delimiters.

Check failure on line 263 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures.yml)

Style/WordArray: Use `[ 'and', 'passwordHistory(3)', 'and', 'regexPattern(^(?!\\d+$)(?!.*test).*$)', 'and', 'specialChars(1)', 'and', 'upperCase(1)']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 263 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures.yml)

Layout/SpaceInsidePercentLiteralDelimiters: Do not use spaces inside percent literal delimiters.

Check failure on line 263 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures-latest.yml)

Style/WordArray: Use `[ 'and', 'passwordHistory(3)', 'and', 'regexPattern(^(?!\\d+$)(?!.*test).*$)', 'and', 'specialChars(1)', 'and', 'upperCase(1)']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 263 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures-latest.yml)

Layout/SpaceInsidePercentLiteralDelimiters: Do not use spaces inside percent literal delimiters.
%w[ and lowerCase(1) and digits(1) and hashAlgorithm(pbkdf2-sha256) and maxLength(64)]

Check failure on line 264 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures.yml)

Style/WordArray: Use `[ 'and', 'lowerCase(1)', 'and', 'digits(1)', 'and', 'hashAlgorithm(pbkdf2-sha256)', 'and', 'maxLength(64)']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 264 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures.yml)

Layout/SpaceInsidePercentLiteralDelimiters: Do not use spaces inside percent literal delimiters.

Check failure on line 264 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures-latest.yml)

Style/WordArray: Use `[ 'and', 'lowerCase(1)', 'and', 'digits(1)', 'and', 'hashAlgorithm(pbkdf2-sha256)', 'and', 'maxLength(64)']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 264 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures-latest.yml)

Layout/SpaceInsidePercentLiteralDelimiters: Do not use spaces inside percent literal delimiters.

Check failure on line 264 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures.yml)

Style/WordArray: Use `[ 'and', 'lowerCase(1)', 'and', 'digits(1)', 'and', 'hashAlgorithm(pbkdf2-sha256)', 'and', 'maxLength(64)']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 264 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures.yml)

Layout/SpaceInsidePercentLiteralDelimiters: Do not use spaces inside percent literal delimiters.

Check failure on line 264 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures-latest.yml)

Style/WordArray: Use `[ 'and', 'lowerCase(1)', 'and', 'digits(1)', 'and', 'hashAlgorithm(pbkdf2-sha256)', 'and', 'maxLength(64)']` for an array of words. (https://rubystyle.guide#percent-w)

Check failure on line 264 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures-latest.yml)

Layout/SpaceInsidePercentLiteralDelimiters: Do not use spaces inside percent literal delimiters.

data = JSON.parse(stdout)
expect(data['rememberMe']).to eq(true)
expect(data['registrationAllowed']).to eq(true)
Expand Down Expand Up @@ -311,6 +316,7 @@ class { 'keycloak': }
expect(data['otpPolicyDigits']).to eq(8)
expect(data['otpPolicyPeriod']).to eq(30)
expect(data['otpPolicyCodeReusable']).to eq(true)
expect(data['passwordPolicy']).to eq(passwordPolicyValue)

Check failure on line 319 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures.yml)

Naming/VariableName: Use snake_case for variable names. (https://rubystyle.guide#snake-case-symbols-methods-vars)

Check failure on line 319 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures-latest.yml)

Naming/VariableName: Use snake_case for variable names. (https://rubystyle.guide#snake-case-symbols-methods-vars)

Check failure on line 319 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 7 (Ruby 2.7.7 fixtures=.fixtures.yml)

Naming/VariableName: Use snake_case for variable names. (https://rubystyle.guide#snake-case-symbols-methods-vars)

Check failure on line 319 in spec/acceptance/2_realm_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet 8 (Ruby 3.2.2 fixtures=.fixtures-latest.yml)

Naming/VariableName: Use snake_case for variable names. (https://rubystyle.guide#snake-case-symbols-methods-vars)
expect(data['webAuthnPolicyRpEntityName']).to eq('Keycloak')
expect(data['webAuthnPolicySignatureAlgorithms']).to eq(['ES256', 'ES384', 'ES512', 'RS256', 'RS384', 'RS512'])
expect(data['webAuthnPolicyRpId']).to eq('https://example.com')
Expand Down
1 change: 1 addition & 0 deletions spec/unit/puppet/type/keycloak_realm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
:smtp_server_reply_to,
:smtp_server_reply_to_display_name,
:default_locale,
:password_policy,
:web_authn_policy_rp_entity_name,
:web_authn_policy_rp_id,
:web_authn_policy_passwordless_rp_entity_name,
Expand Down

0 comments on commit 69ec356

Please sign in to comment.