Skip to content

Commit

Permalink
Fix realm and other resources to handle names with spaces (#249)
Browse files Browse the repository at this point in the history
* Fix realm and other resources to handle names with spaces
Fixes #248

* Do not escape everything, just spaces
  • Loading branch information
treydock authored Jun 16, 2022
1 parent 59fc76e commit 8a6c0e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/puppet/provider/keycloak_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def camelize(*args)
self.class.camelize(*args)
end

def self.escape(str)
str.gsub(' ', '%20')
end

def convert_property_value(value)
case value
when :true
Expand All @@ -58,15 +62,15 @@ def self.kcadm(action, resource, realm = nil, file = nil, fields = nil, print_id
arguments = [action]

# get-roles does not accept a resource as its parameter
arguments << resource if resource
arguments << self.escape(resource) if resource

if ['create', 'update'].include?(action) && !print_id
arguments << '-o'
end

if realm
arguments << '-r'
arguments << realm
arguments << self.escape(realm)
end
if file
arguments << '-f'
Expand Down Expand Up @@ -96,7 +100,7 @@ def self.kcadm(action, resource, realm = nil, file = nil, fields = nil, print_id
auth_arguments = [
'--no-config',
'--server', server,
'--realm', self.realm,
'--realm', self.escape(self.realm),
'--user', user,
'--password', password
]
Expand Down
10 changes: 10 additions & 0 deletions spec/acceptance/2_realm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class { 'keycloak': }
offline_session_max_lifespan => 5184000,
offline_session_max_lifespan_enabled => true,
}
keycloak_realm { 'test realm':
ensure => 'present',
}
EOS

apply_manifest(pp, catch_failures: true)
Expand All @@ -54,6 +57,13 @@ class { 'keycloak': }
end
end

it 'created a realm with space in name' do
on hosts, '/opt/keycloak/bin/kcadm-wrapper.sh get realms/test%20realm' do
data = JSON.parse(stdout)
expect(data['id']).to eq('test realm')
end
end

it 'has left default-client-scopes' do
on hosts, '/opt/keycloak/bin/kcadm-wrapper.sh get realms/test/default-default-client-scopes' do
data = JSON.parse(stdout)
Expand Down

0 comments on commit 8a6c0e8

Please sign in to comment.