keycloak-admin 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +54 -2
- data/keycloak-admin.gemspec +14 -5
- data/lib/keycloak-admin/client/client.rb +30 -11
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +1 -1
- data/lib/keycloak-admin/client/configurable_token_client.rb +2 -1
- data/lib/keycloak-admin/client/group_client.rb +4 -6
- data/lib/keycloak-admin/client/organization_client.rb +7 -7
- data/lib/keycloak-admin/client/resource.rb +98 -0
- data/lib/keycloak-admin/client/response.rb +36 -0
- data/lib/keycloak-admin/client/role_mapper_client.rb +2 -1
- data/lib/keycloak-admin/client/user_client.rb +22 -11
- data/lib/keycloak-admin/configuration.rb +22 -0
- data/lib/keycloak-admin/error.rb +62 -0
- data/lib/keycloak-admin/version.rb +1 -1
- data/lib/keycloak-admin.rb +1 -0
- metadata +38 -53
- data/.github/workflows/Dockerfile +0 -24
- data/.github/workflows/ci.yml +0 -94
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/Dockerfile +0 -13
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -52
- data/bin/console +0 -9
- data/spec/client/attack_detection_client_spec.rb +0 -102
- data/spec/client/client_authz_permission_client_spec.rb +0 -170
- data/spec/client/client_authz_policy_client_spec.rb +0 -170
- data/spec/client/client_authz_resource_client_spec.rb +0 -150
- data/spec/client/client_authz_scope_client_spec.rb +0 -134
- data/spec/client/client_client_spec.rb +0 -133
- data/spec/client/client_role_mappings_client_spec.rb +0 -82
- data/spec/client/client_scope_client_spec.rb +0 -220
- data/spec/client/client_scope_protocol_mapper_client_spec.rb +0 -230
- data/spec/client/client_spec.rb +0 -48
- data/spec/client/configurable_token_client_spec.rb +0 -34
- data/spec/client/group_client_spec.rb +0 -328
- data/spec/client/identity_provider_client_spec.rb +0 -92
- data/spec/client/organization_client_spec.rb +0 -595
- data/spec/client/realm_client_spec.rb +0 -155
- data/spec/client/role_client_spec.rb +0 -79
- data/spec/client/role_mapper_client_spec.rb +0 -113
- data/spec/client/token_client_spec.rb +0 -68
- data/spec/client/user_client_spec.rb +0 -418
- data/spec/configuration_spec.rb +0 -113
- data/spec/gemspec_spec.rb +0 -25
- data/spec/integration/client_authorization_spec.rb +0 -93
- data/spec/representation/attack_detection_representation_spec.rb +0 -16
- data/spec/representation/client_authz_permission_representation_spec.rb +0 -52
- data/spec/representation/client_authz_policy_representation_spec.rb +0 -47
- data/spec/representation/client_authz_resource_representation_spec.rb +0 -33
- data/spec/representation/client_authz_scope_representation_spec.rb +0 -19
- data/spec/representation/client_representation_spec.rb +0 -119
- data/spec/representation/client_scope_representation_spec.rb +0 -125
- data/spec/representation/credential_representation_spec.rb +0 -68
- data/spec/representation/group_representation_spec.rb +0 -22
- data/spec/representation/identity_provider_mapper_representation_spec.rb +0 -24
- data/spec/representation/identity_provider_representation_spec.rb +0 -113
- data/spec/representation/impersonation_representation_spec.rb +0 -163
- data/spec/representation/organization_representation_spec.rb +0 -64
- data/spec/representation/protocol_mapper_representation_spec.rb +0 -57
- data/spec/representation/role_representation_spec.rb +0 -37
- data/spec/representation/session_representation_spec.rb +0 -16
- data/spec/representation/user_representation_spec.rb +0 -15
- data/spec/resource/group_resource_spec.rb +0 -14
- data/spec/resource/user_resource_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -29
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::ClientClient do
|
|
2
|
-
describe "#clients_url" do
|
|
3
|
-
let(:realm_name) { "valid-realm" }
|
|
4
|
-
let(:client_id) { nil }
|
|
5
|
-
|
|
6
|
-
before(:each) do
|
|
7
|
-
@built_url = KeycloakAdmin.realm(realm_name).clients.clients_url(client_id)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "when client_id is not defined" do
|
|
11
|
-
let(:client_id) { nil }
|
|
12
|
-
it "return a proper url without client id" do
|
|
13
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients"
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context "when client_id is defined" do
|
|
18
|
-
let(:client_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
|
|
19
|
-
it "return a proper url with the client id" do
|
|
20
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/95985b21-d884-4bbd-b852-cb8cd365afc2"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe "#get" do
|
|
26
|
-
let(:realm_name) { "valid-realm" }
|
|
27
|
-
let(:id) { "test_client_id" }
|
|
28
|
-
let(:client_name) { "test_client_name" }
|
|
29
|
-
|
|
30
|
-
before(:each) do
|
|
31
|
-
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
32
|
-
|
|
33
|
-
stub_token_client
|
|
34
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"test_client_id","name":"test_client_name"}'
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "finds a client" do
|
|
38
|
-
client = @client_client.get(id)
|
|
39
|
-
expect(client.name).to eq client_name
|
|
40
|
-
expect(client.id).to eq id
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe "#find_by_client_id" do
|
|
45
|
-
let(:realm_name) { "valid-realm" }
|
|
46
|
-
let(:client_id) { "my_client_id" }
|
|
47
|
-
let(:client_name) { "test_client_name" }
|
|
48
|
-
|
|
49
|
-
before(:each) do
|
|
50
|
-
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
51
|
-
|
|
52
|
-
stub_token_client
|
|
53
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_client_id","clientId": "my_client_id","name":"test_client_name"},{"id":"test_client_id_2","clientId":"client_id_2","name":"test_client_name_2"}]'
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "finds a client it has" do
|
|
57
|
-
client = @client_client.find_by_client_id(client_id)
|
|
58
|
-
expect(client.name).to eq client_name
|
|
59
|
-
expect(client.client_id).to eq client_id
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "returns nil if it doesn't have the client" do
|
|
63
|
-
client = @client_client.find_by_client_id("client_id_3")
|
|
64
|
-
expect(client).to be_nil
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
describe "#list" do
|
|
69
|
-
let(:realm_name) { "valid-realm" }
|
|
70
|
-
|
|
71
|
-
before(:each) do
|
|
72
|
-
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
73
|
-
|
|
74
|
-
stub_token_client
|
|
75
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_client_id","name":"test_client_name"}]'
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "lists clients" do
|
|
79
|
-
clients = @client_client.list
|
|
80
|
-
expect(clients.length).to eq 1
|
|
81
|
-
expect(clients[0].name).to eq "test_client_name"
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it "passes rest client options" do
|
|
85
|
-
faraday_options = {timeout: 10}
|
|
86
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
87
|
-
|
|
88
|
-
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
89
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/clients", faraday_options).and_call_original
|
|
90
|
-
|
|
91
|
-
clients = @client_client.list
|
|
92
|
-
expect(clients.length).to eq 1
|
|
93
|
-
expect(clients[0].name).to eq "test_client_name"
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
describe "#update" do
|
|
98
|
-
let(:realm_name) { "valid-realm" }
|
|
99
|
-
let(:client) { KeycloakAdmin::ClientRepresentation.from_hash({ "id" => "test_client_id", "clientId" => "my-client", "name" => "old_name" }) }
|
|
100
|
-
|
|
101
|
-
before(:each) do
|
|
102
|
-
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
103
|
-
|
|
104
|
-
stub_token_client
|
|
105
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return ''
|
|
106
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"test_client_id", "clientId": "my-client","name":"new_name"}'
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
it "updates a client" do
|
|
110
|
-
updated_client = @client_client.update(client)
|
|
111
|
-
|
|
112
|
-
expect(updated_client.name).to eq "new_name"
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
describe "#delete" do
|
|
117
|
-
let(:realm_name) { "valid-realm" }
|
|
118
|
-
|
|
119
|
-
before(:each) do
|
|
120
|
-
@client_client = KeycloakAdmin.realm(realm_name).clients
|
|
121
|
-
stub_token_client
|
|
122
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ''
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it "passes rest client options" do
|
|
126
|
-
faraday_options = {timeout: 10}
|
|
127
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
128
|
-
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
129
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/clients/95b45037-3980-404c-ba12-784fa1baf2c2", faraday_options).and_call_original
|
|
130
|
-
@client_client.delete("95b45037-3980-404c-ba12-784fa1baf2c2")
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
end
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::ClientRoleMappingsClient do
|
|
2
|
-
describe "#available_url" do
|
|
3
|
-
let(:realm_name) { "valid-realm" }
|
|
4
|
-
let(:user_id) { "test_user" }
|
|
5
|
-
let(:client_id) { "test_client" }
|
|
6
|
-
|
|
7
|
-
before(:each) do
|
|
8
|
-
@built_url = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id).list_available_url
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "return a proper url" do
|
|
12
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client/available"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe "#list_available" do
|
|
17
|
-
let(:realm_name) { "valid-realm" }
|
|
18
|
-
let(:user_id) { "test_user" }
|
|
19
|
-
let(:client_id) { "test_client" }
|
|
20
|
-
|
|
21
|
-
before(:each) do
|
|
22
|
-
@client_role_mappings_client = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id)
|
|
23
|
-
|
|
24
|
-
stub_token_client
|
|
25
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"test_role_id","name":"test_role_name"}]'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it "lists roles" do
|
|
29
|
-
roles = @client_role_mappings_client.list_available
|
|
30
|
-
expect(roles.length).to eq 1
|
|
31
|
-
expect(roles[0].name).to eq "test_role_name"
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it "passes rest client options" do
|
|
35
|
-
faraday_options = {timeout: 10}
|
|
36
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
37
|
-
|
|
38
|
-
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
39
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client/available",
|
|
40
|
-
faraday_options
|
|
41
|
-
).and_call_original
|
|
42
|
-
|
|
43
|
-
roles = @client_role_mappings_client.list_available
|
|
44
|
-
expect(roles.length).to eq 1
|
|
45
|
-
expect(roles[0].name).to eq "test_role_name"
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
describe "#save" do
|
|
50
|
-
let(:realm_name) { "valid-realm" }
|
|
51
|
-
let(:user_id) { "test_user" }
|
|
52
|
-
let(:client_id) { "test_client" }
|
|
53
|
-
let(:role_list) { [
|
|
54
|
-
KeycloakAdmin::RoleRepresentation.from_hash(
|
|
55
|
-
"name" => "test_role_name",
|
|
56
|
-
"composite" => false,
|
|
57
|
-
"clientRole" => false
|
|
58
|
-
)
|
|
59
|
-
] }
|
|
60
|
-
|
|
61
|
-
before(:each) do
|
|
62
|
-
@client_role_mappings_client = KeycloakAdmin.realm(realm_name).user(user_id).client_role_mappings(client_id)
|
|
63
|
-
|
|
64
|
-
stub_token_client
|
|
65
|
-
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:post).with(role_list.to_json, anything)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it "saves client role mappings" do
|
|
69
|
-
@client_role_mappings_client.save(role_list)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "passes rest client options" do
|
|
73
|
-
faraday_options = {timeout: 10}
|
|
74
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:faraday_options).and_return faraday_options
|
|
75
|
-
|
|
76
|
-
expect(KeycloakAdmin::Resource).to receive(:new).with(
|
|
77
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client", faraday_options).and_call_original
|
|
78
|
-
|
|
79
|
-
@client_role_mappings_client.save(role_list)
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
end
|
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::ClientScopeClient do
|
|
2
|
-
let(:realm_name) { "valid-realm" }
|
|
3
|
-
let(:client_scope_id) { "valid-scope-id" }
|
|
4
|
-
|
|
5
|
-
let(:scope_json) do
|
|
6
|
-
<<~JSON
|
|
7
|
-
{"id":"valid-scope-id","name":"my-scope","description":"A test scope","protocol":"openid-connect","attributes":{"display.on.consent.screen":"true","include.in.token.scope":"true"}}
|
|
8
|
-
JSON
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
let(:scope_with_mappers_json) do
|
|
12
|
-
<<~JSON
|
|
13
|
-
{"id":"valid-scope-id","name":"my-scope","description":"A test scope","protocol":"openid-connect","attributes":{},"protocolMappers":[{"id":"mapper-id","name":"my-claim","protocol":"openid-connect","protocolMapper":"oidc-hardcoded-claim-mapper","config":{"claim.name":"my_claim","claim.value":"bar","access.token.claim":"true"}}]}
|
|
14
|
-
JSON
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
describe "#initialize" do
|
|
18
|
-
context "when realm_name is defined" do
|
|
19
|
-
it "does not raise any error" do
|
|
20
|
-
expect { KeycloakAdmin.realm(realm_name).client_scopes }.to_not raise_error
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
context "when realm_name is not defined" do
|
|
25
|
-
it "raises an argument error" do
|
|
26
|
-
expect { KeycloakAdmin.realm(nil).client_scopes }.to raise_error(ArgumentError)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe "#list" do
|
|
32
|
-
before(:each) do
|
|
33
|
-
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
34
|
-
stub_token_client
|
|
35
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
context "with one scope" do
|
|
39
|
-
let(:stub_response) { "[#{scope_json}]" }
|
|
40
|
-
|
|
41
|
-
it "returns one scope" do
|
|
42
|
-
expect(@client.list.size).to eq 1
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it "returns the correct scope attributes" do
|
|
46
|
-
expect(@client.list.first).to have_attributes(
|
|
47
|
-
id: "valid-scope-id",
|
|
48
|
-
name: "my-scope",
|
|
49
|
-
description: "A test scope",
|
|
50
|
-
protocol: "openid-connect"
|
|
51
|
-
)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "returns attributes map" do
|
|
55
|
-
expect(@client.list.first.attributes).to include(
|
|
56
|
-
"display.on.consent.screen" => "true",
|
|
57
|
-
"include.in.token.scope" => "true"
|
|
58
|
-
)
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
context "with multiple scopes" do
|
|
63
|
-
let(:second_scope_json) { '{"id":"other-scope-id","name":"other-scope","protocol":"openid-connect"}' }
|
|
64
|
-
let(:stub_response) { "[#{scope_json},#{second_scope_json}]" }
|
|
65
|
-
|
|
66
|
-
it "returns two scopes" do
|
|
67
|
-
expect(@client.list.size).to eq 2
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "includes both scope names" do
|
|
71
|
-
expect(@client.list.map(&:name)).to include("my-scope", "other-scope")
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe "#get" do
|
|
77
|
-
before(:each) do
|
|
78
|
-
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
79
|
-
stub_token_client
|
|
80
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context "without protocol mappers" do
|
|
84
|
-
let(:stub_response) { scope_json }
|
|
85
|
-
|
|
86
|
-
it "returns the correct id" do
|
|
87
|
-
expect(@client.get(client_scope_id).id).to eq "valid-scope-id"
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "returns the correct name" do
|
|
91
|
-
expect(@client.get(client_scope_id).name).to eq "my-scope"
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "returns the correct description" do
|
|
95
|
-
expect(@client.get(client_scope_id).description).to eq "A test scope"
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "returns the correct protocol" do
|
|
99
|
-
expect(@client.get(client_scope_id).protocol).to eq "openid-connect"
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it "returns an empty protocolMappers list" do
|
|
103
|
-
expect(@client.get(client_scope_id).protocol_mappers).to eq []
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
context "with protocol mappers" do
|
|
108
|
-
let(:stub_response) { scope_with_mappers_json }
|
|
109
|
-
|
|
110
|
-
it "returns protocol mappers" do
|
|
111
|
-
expect(@client.get(client_scope_id).protocol_mappers.size).to eq 1
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "returns the correct mapper name" do
|
|
115
|
-
expect(@client.get(client_scope_id).protocol_mappers.first.name).to eq "my-claim"
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe "#create!" do
|
|
121
|
-
before(:each) do
|
|
122
|
-
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
123
|
-
stub_token_client
|
|
124
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return ""
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
let(:scope_representation) do
|
|
128
|
-
scope = KeycloakAdmin::ClientScopeRepresentation.new
|
|
129
|
-
scope.name = "my-scope"
|
|
130
|
-
scope.description = "A test scope"
|
|
131
|
-
scope.protocol = "openid-connect"
|
|
132
|
-
scope.attributes = { "display.on.consent.screen" => "true", "include.in.token.scope" => "true" }
|
|
133
|
-
scope
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it "creates successfully" do
|
|
137
|
-
expect(@client.create!(scope_representation)).to be true
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
describe "#save" do
|
|
142
|
-
before(:each) do
|
|
143
|
-
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
144
|
-
stub_token_client
|
|
145
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return ""
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
let(:scope_representation) { KeycloakAdmin::ClientScopeRepresentation.from_hash(JSON.parse(scope_json)) }
|
|
149
|
-
|
|
150
|
-
it "calls put on the scope url" do
|
|
151
|
-
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
|
|
152
|
-
@client.save(scope_representation)
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
it "returns true" do
|
|
156
|
-
expect(@client.save(scope_representation)).to be true
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
describe "#search" do
|
|
161
|
-
let(:second_scope_json) { '{"id":"other-scope-id","name":"other-scope","protocol":"openid-connect"}' }
|
|
162
|
-
|
|
163
|
-
before(:each) do
|
|
164
|
-
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
165
|
-
stub_token_client
|
|
166
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return "[#{scope_json},#{second_scope_json}]"
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
context "when the name matches one scope" do
|
|
170
|
-
it "returns only the matching scope" do
|
|
171
|
-
expect(@client.search("my-scope").size).to eq 1
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
it "returns the correct scope" do
|
|
175
|
-
expect(@client.search("my-scope").first).to have_attributes(id: "valid-scope-id", name: "my-scope")
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
context "when the name is a partial match" do
|
|
180
|
-
it "returns all scopes containing the substring" do
|
|
181
|
-
expect(@client.search("scope").size).to eq 2
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
context "when no scope matches" do
|
|
186
|
-
it "returns an empty array" do
|
|
187
|
-
expect(@client.search("unknown")).to eq []
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
describe "#delete" do
|
|
193
|
-
before(:each) do
|
|
194
|
-
@client = KeycloakAdmin.realm(realm_name).client_scopes
|
|
195
|
-
stub_token_client
|
|
196
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ""
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
it "returns true" do
|
|
200
|
-
expect(@client.delete(client_scope_id)).to eq true
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
describe "#client_scopes_url" do
|
|
205
|
-
let(:client) { KeycloakAdmin.realm(realm_name).client_scopes }
|
|
206
|
-
let(:base_url) { "http://auth.service.io/auth/admin/realms/valid-realm/client-scopes" }
|
|
207
|
-
|
|
208
|
-
context "without a client_scope_id" do
|
|
209
|
-
it "returns the base url" do
|
|
210
|
-
expect(client.client_scopes_url).to eq base_url
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
context "with a client_scope_id" do
|
|
215
|
-
it "returns the url with client_scope_id appended" do
|
|
216
|
-
expect(client.client_scopes_url(client_scope_id)).to eq "#{base_url}/valid-scope-id"
|
|
217
|
-
end
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::ClientScopeProtocolMapperClient do
|
|
2
|
-
let(:realm_name) { "valid-realm" }
|
|
3
|
-
let(:client_scope_id) { "valid-scope-id" }
|
|
4
|
-
let(:mapper_id) { "valid-mapper-id" }
|
|
5
|
-
|
|
6
|
-
let(:mapper_json) do
|
|
7
|
-
<<~JSON
|
|
8
|
-
{"id":"valid-mapper-id","name":"my-claim","protocol":"openid-connect","protocolMapper":"oidc-hardcoded-claim-mapper","config":{"claim.name":"my_claim","claim.value":"bar","access.token.claim":"true"}}
|
|
9
|
-
JSON
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
let(:audience_mapper_json) do
|
|
13
|
-
<<~JSON
|
|
14
|
-
{"protocol":"openid-connect","protocolMapper":"oidc-audience-mapper","name":"audience-config-rvw-123","config":{"included.client.audience":"","included.custom.audience":"https://api.example.com","id.token.claim":"false","access.token.claim":"true","lightweight.claim":"false","introspection.token.claim":"true"}}
|
|
15
|
-
JSON
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe "#initialize" do
|
|
19
|
-
context "when realm_name is defined" do
|
|
20
|
-
it "does not raise any error" do
|
|
21
|
-
expect { KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id) }.to_not raise_error
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
context "when realm_name is not defined" do
|
|
26
|
-
it "raises an argument error" do
|
|
27
|
-
expect { KeycloakAdmin.realm(nil).client_scope_protocol_mappers(client_scope_id) }.to raise_error(ArgumentError)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "#list" do
|
|
33
|
-
before(:each) do
|
|
34
|
-
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
35
|
-
stub_token_client
|
|
36
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context "with a hardcoded claim mapper" do
|
|
40
|
-
let(:stub_response) { "[#{mapper_json}]" }
|
|
41
|
-
|
|
42
|
-
it "returns one mapper" do
|
|
43
|
-
expect(@client.list.size).to eq 1
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "returns the correct mapper attributes" do
|
|
47
|
-
expect(@client.list.first).to have_attributes(id: "valid-mapper-id", name: "my-claim", protocol: "openid-connect", protocolMapper: "oidc-hardcoded-claim-mapper")
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context "with an audience mapper" do
|
|
52
|
-
let(:stub_response) { "[#{audience_mapper_json}]" }
|
|
53
|
-
|
|
54
|
-
it "returns one mapper" do
|
|
55
|
-
expect(@client.list.size).to eq 1
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "returns the correct mapper attributes" do
|
|
59
|
-
expect(@client.list.first).to have_attributes(name: "audience-config-rvw-123", protocol: "openid-connect", protocolMapper: "oidc-audience-mapper")
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
context "with multiple mappers" do
|
|
64
|
-
let(:stub_response) { "[#{mapper_json},#{audience_mapper_json}]" }
|
|
65
|
-
|
|
66
|
-
it "returns two mappers" do
|
|
67
|
-
expect(@client.list.size).to eq 2
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "includes both mapper names" do
|
|
71
|
-
expect(@client.list.map(&:name)).to include("my-claim", "audience-config-rvw-123")
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe "#get" do
|
|
77
|
-
before(:each) do
|
|
78
|
-
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
79
|
-
stub_token_client
|
|
80
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return stub_response
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
context "with a hardcoded claim mapper" do
|
|
84
|
-
let(:stub_response) { mapper_json }
|
|
85
|
-
|
|
86
|
-
it "returns the correct id" do
|
|
87
|
-
expect(@client.get(mapper_id).id).to eq "valid-mapper-id"
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "returns the correct name" do
|
|
91
|
-
expect(@client.get(mapper_id).name).to eq "my-claim"
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "returns the correct protocol" do
|
|
95
|
-
expect(@client.get(mapper_id).protocol).to eq "openid-connect"
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "returns the correct protocolMapper" do
|
|
99
|
-
expect(@client.get(mapper_id).protocolMapper).to eq "oidc-hardcoded-claim-mapper"
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
context "with an audience mapper" do
|
|
104
|
-
let(:stub_response) { audience_mapper_json }
|
|
105
|
-
|
|
106
|
-
it "returns the correct name" do
|
|
107
|
-
expect(@client.get(mapper_id).name).to eq "audience-config-rvw-123"
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it "returns the correct protocol" do
|
|
111
|
-
expect(@client.get(mapper_id).protocol).to eq "openid-connect"
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it "returns the correct protocolMapper" do
|
|
115
|
-
expect(@client.get(mapper_id).protocolMapper).to eq "oidc-audience-mapper"
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it "returns the correct config" do
|
|
119
|
-
expect(@client.get(mapper_id).config).to include(
|
|
120
|
-
"included.custom.audience" => "https://api.example.com",
|
|
121
|
-
"access.token.claim" => "true",
|
|
122
|
-
"introspection.token.claim" => "true",
|
|
123
|
-
"id.token.claim" => "false"
|
|
124
|
-
)
|
|
125
|
-
end
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
describe "#create!" do
|
|
130
|
-
before(:each) do
|
|
131
|
-
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
132
|
-
stub_token_client
|
|
133
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return stub_response
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
context "with a hardcoded claim mapper" do
|
|
137
|
-
let(:stub_response) { mapper_json }
|
|
138
|
-
let(:mapper_representation) do
|
|
139
|
-
mapper = KeycloakAdmin::ProtocolMapperRepresentation.new
|
|
140
|
-
mapper.name = "my-claim"
|
|
141
|
-
mapper.protocol = "openid-connect"
|
|
142
|
-
mapper.protocolMapper = "oidc-hardcoded-claim-mapper"
|
|
143
|
-
mapper.config = { "claim.name" => "my_claim", "claim.value" => "bar", "access.token.claim" => "true" }
|
|
144
|
-
mapper
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it "creates successfully" do
|
|
148
|
-
expect(@client.create!(mapper_representation)).to be true
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
context "with an audience mapper" do
|
|
153
|
-
let(:stub_response) { audience_mapper_json }
|
|
154
|
-
let(:mapper_representation) do
|
|
155
|
-
mapper = KeycloakAdmin::ProtocolMapperRepresentation.new
|
|
156
|
-
mapper.name = "audience-config-rvw-123"
|
|
157
|
-
mapper.protocol = "openid-connect"
|
|
158
|
-
mapper.protocolMapper = "oidc-audience-mapper"
|
|
159
|
-
mapper.config = {
|
|
160
|
-
"included.client.audience" => "",
|
|
161
|
-
"included.custom.audience" => "https://api.example.com",
|
|
162
|
-
"id.token.claim" => "false",
|
|
163
|
-
"access.token.claim" => "true",
|
|
164
|
-
"lightweight.claim" => "false",
|
|
165
|
-
"introspection.token.claim" => "true"
|
|
166
|
-
}
|
|
167
|
-
mapper
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it "creates successfully" do
|
|
171
|
-
expect(@client.create!(mapper_representation)).to be true
|
|
172
|
-
end
|
|
173
|
-
end
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
describe "#save" do
|
|
177
|
-
before(:each) do
|
|
178
|
-
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
179
|
-
stub_token_client
|
|
180
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:put).and_return ""
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
context "with a hardcoded claim mapper" do
|
|
184
|
-
let(:mapper_representation) { KeycloakAdmin::ProtocolMapperRepresentation.from_hash(JSON.parse(mapper_json)) }
|
|
185
|
-
|
|
186
|
-
it "calls put on the mapper url" do
|
|
187
|
-
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
|
|
188
|
-
@client.save(mapper_representation)
|
|
189
|
-
end
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
context "with an audience mapper" do
|
|
193
|
-
let(:mapper_representation) { KeycloakAdmin::ProtocolMapperRepresentation.from_hash(JSON.parse(audience_mapper_json)) }
|
|
194
|
-
|
|
195
|
-
it "calls put on the mapper url" do
|
|
196
|
-
expect_any_instance_of(KeycloakAdmin::Resource).to receive(:put).with(anything, anything)
|
|
197
|
-
@client.save(mapper_representation)
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
describe "#delete" do
|
|
203
|
-
before(:each) do
|
|
204
|
-
@client = KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id)
|
|
205
|
-
stub_token_client
|
|
206
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return ""
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
it "returns true" do
|
|
210
|
-
expect(@client.delete(mapper_id)).to eq true
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
describe "#protocol_mappers_url" do
|
|
215
|
-
let(:client) { KeycloakAdmin.realm(realm_name).client_scope_protocol_mappers(client_scope_id) }
|
|
216
|
-
let(:base_url) { "http://auth.service.io/auth/admin/realms/valid-realm/client-scopes/valid-scope-id/protocol-mappers/models" }
|
|
217
|
-
|
|
218
|
-
context "without a mapper_id" do
|
|
219
|
-
it "returns the base url" do
|
|
220
|
-
expect(client.protocol_mappers_url).to eq base_url
|
|
221
|
-
end
|
|
222
|
-
end
|
|
223
|
-
|
|
224
|
-
context "with a mapper_id" do
|
|
225
|
-
it "returns the url with mapper_id appended" do
|
|
226
|
-
expect(client.protocol_mappers_url(mapper_id)).to eq "#{base_url}/valid-mapper-id"
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
end
|