keycloak-admin 1.1.3 → 1.1.4
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/.github/workflows/Dockerfile +24 -24
- data/.github/workflows/ci.yml +80 -83
- data/.gitignore +9 -9
- data/.rspec +2 -2
- data/CHANGELOG.md +194 -188
- data/Dockerfile +12 -12
- data/Gemfile +3 -3
- data/Gemfile.lock +51 -49
- data/MIT-LICENSE +20 -20
- data/README.md +748 -748
- data/bin/console +9 -9
- data/keycloak-admin.gemspec +24 -24
- data/lib/keycloak-admin/client/attack_detection_client.rb +41 -41
- data/lib/keycloak-admin/client/client.rb +56 -56
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +80 -80
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +75 -75
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +92 -92
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +70 -70
- data/lib/keycloak-admin/client/client_client.rb +71 -71
- data/lib/keycloak-admin/client/client_role_client.rb +20 -20
- data/lib/keycloak-admin/client/client_role_mappings_client.rb +32 -32
- data/lib/keycloak-admin/client/configurable_token_client.rb +35 -35
- data/lib/keycloak-admin/client/group_client.rb +148 -131
- data/lib/keycloak-admin/client/identity_provider_client.rb +51 -51
- data/lib/keycloak-admin/client/realm_client.rb +122 -122
- data/lib/keycloak-admin/client/role_client.rb +59 -59
- data/lib/keycloak-admin/client/role_mapper_client.rb +47 -45
- data/lib/keycloak-admin/client/token_client.rb +29 -29
- data/lib/keycloak-admin/client/user_client.rb +266 -266
- data/lib/keycloak-admin/configuration.rb +52 -52
- data/lib/keycloak-admin/representation/attack_detection_representation.rb +17 -17
- data/lib/keycloak-admin/representation/camel_json.rb +12 -12
- data/lib/keycloak-admin/representation/client_authz_permission_representation.rb +33 -33
- data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +14 -14
- data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +26 -26
- data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +25 -25
- data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +16 -16
- data/lib/keycloak-admin/representation/client_representation.rb +71 -71
- data/lib/keycloak-admin/representation/credential_representation.rb +38 -38
- data/lib/keycloak-admin/representation/federated_identity_representation.rb +15 -15
- data/lib/keycloak-admin/representation/group_representation.rb +21 -21
- data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +19 -19
- data/lib/keycloak-admin/representation/identity_provider_representation.rb +67 -67
- data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +16 -16
- data/lib/keycloak-admin/representation/impersonation_representation.rb +43 -43
- data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +19 -19
- data/lib/keycloak-admin/representation/realm_representation.rb +14 -14
- data/lib/keycloak-admin/representation/representation.rb +23 -23
- data/lib/keycloak-admin/representation/role_representation.rb +19 -19
- data/lib/keycloak-admin/representation/session_representation.rb +22 -22
- data/lib/keycloak-admin/representation/token_representation.rb +39 -39
- data/lib/keycloak-admin/representation/user_representation.rb +47 -47
- data/lib/keycloak-admin/resource/base_role_containing_resource.rb +28 -28
- data/lib/keycloak-admin/resource/group_resource.rb +11 -11
- data/lib/keycloak-admin/resource/user_resource.rb +7 -7
- data/lib/keycloak-admin/version.rb +3 -3
- data/lib/keycloak-admin.rb +84 -84
- data/spec/client/attack_detection_client_spec.rb +102 -102
- data/spec/client/client_authz_permission_client_spec.rb +170 -170
- data/spec/client/client_authz_policy_client_spec.rb +169 -169
- data/spec/client/client_authz_resource_client_spec.rb +150 -150
- data/spec/client/client_authz_scope_client_spec.rb +133 -133
- data/spec/client/client_client_spec.rb +133 -133
- data/spec/client/client_role_mappings_client_spec.rb +82 -82
- data/spec/client/client_spec.rb +28 -28
- data/spec/client/configurable_token_client_spec.rb +34 -34
- data/spec/client/group_client_spec.rb +328 -258
- data/spec/client/identity_provider_client_spec.rb +92 -92
- data/spec/client/realm_client_spec.rb +155 -155
- data/spec/client/role_client_spec.rb +79 -79
- data/spec/client/role_mapper_client_spec.rb +113 -68
- data/spec/client/token_client_spec.rb +68 -68
- data/spec/client/user_client_spec.rb +373 -373
- data/spec/configuration_spec.rb +113 -113
- data/spec/integration/client_authorization_spec.rb +93 -95
- data/spec/representation/attack_detection_representation_spec.rb +15 -15
- data/spec/representation/client_authz_permission_representation_spec.rb +52 -52
- data/spec/representation/client_authz_policy_representation_spec.rb +46 -46
- data/spec/representation/client_authz_resource_representation_spec.rb +33 -33
- data/spec/representation/client_authz_scope_representation_spec.rb +18 -18
- data/spec/representation/client_representation_spec.rb +119 -119
- data/spec/representation/group_representation_spec.rb +22 -22
- data/spec/representation/identity_provider_mapper_representation_spec.rb +24 -24
- data/spec/representation/identity_provider_representation_spec.rb +113 -113
- data/spec/representation/impersonation_representation_spec.rb +163 -163
- data/spec/representation/protocol_mapper_representation_spec.rb +57 -57
- data/spec/representation/role_representation_spec.rb +37 -37
- data/spec/representation/session_representation_spec.rb +15 -15
- data/spec/representation/user_representation_spec.rb +15 -15
- data/spec/resource/group_resource_spec.rb +14 -14
- data/spec/resource/user_resource_spec.rb +14 -14
- data/spec/spec_helper.rb +37 -37
- metadata +10 -10
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::IdentityProviderClient do
|
|
2
|
-
describe "#identity_providers_url" do
|
|
3
|
-
let(:realm_name) { "valid-realm" }
|
|
4
|
-
let(:provider_id) { nil }
|
|
5
|
-
|
|
6
|
-
before(:each) do
|
|
7
|
-
@built_url = KeycloakAdmin.realm(realm_name).identity_providers.identity_providers_url(provider_id)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "when provider_id is not defined" do
|
|
11
|
-
let(:provider_id) { nil }
|
|
12
|
-
it "returns a proper url without provider id" do
|
|
13
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/identity-provider/instances"
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context "when provider_id is defined" do
|
|
18
|
-
let(:provider_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
|
|
19
|
-
it "returns a proper url with the provider id" do
|
|
20
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/identity-provider/instances/95985b21-d884-4bbd-b852-cb8cd365afc2"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe "#list" do
|
|
26
|
-
let(:realm_name) { "valid-realm" }
|
|
27
|
-
let(:json_response) do
|
|
28
|
-
<<-JSON
|
|
29
|
-
[
|
|
30
|
-
{
|
|
31
|
-
"alias": "acme",
|
|
32
|
-
"displayName": "ACME",
|
|
33
|
-
"internalId": "20fea77e-ae3d-411e-9467-2b3a20cd3e6d",
|
|
34
|
-
"providerId": "saml",
|
|
35
|
-
"enabled": true,
|
|
36
|
-
"updateProfileFirstLoginMode": "on",
|
|
37
|
-
"trustEmail": true,
|
|
38
|
-
"storeToken": false,
|
|
39
|
-
"addReadTokenRoleOnCreate": false,
|
|
40
|
-
"authenticateByDefault": false,
|
|
41
|
-
"linkOnly": false,
|
|
42
|
-
"firstBrokerLoginFlowAlias": "first broker login",
|
|
43
|
-
"config": {
|
|
44
|
-
"hideOnLoginPage": "",
|
|
45
|
-
"validateSignature": "true",
|
|
46
|
-
"samlXmlKeyNameTranformer": "KEY_ID",
|
|
47
|
-
"signingCertificate": "",
|
|
48
|
-
"postBindingLogout": "false",
|
|
49
|
-
"nameIDPolicyFormat": "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
|
|
50
|
-
"postBindingResponse": "true",
|
|
51
|
-
"backchannelSupported": "",
|
|
52
|
-
"signatureAlgorithm": "RSA_SHA256",
|
|
53
|
-
"wantAssertionsEncrypted": "false",
|
|
54
|
-
"xmlSigKeyInfoKeyNameTransformer": "CERT_SUBJECT",
|
|
55
|
-
"useJwksUrl": "true",
|
|
56
|
-
"wantAssertionsSigned": "true",
|
|
57
|
-
"postBindingAuthnRequest": "true",
|
|
58
|
-
"forceAuthn": "",
|
|
59
|
-
"wantAuthnRequestsSigned": "true",
|
|
60
|
-
"singleSignOnServiceUrl": "https://login.microsoftonline.com/test/saml2",
|
|
61
|
-
"addExtensionsElementWithKeyInfo": "false"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
JSON
|
|
66
|
-
end
|
|
67
|
-
before(:each) do
|
|
68
|
-
@identity_provider_client = KeycloakAdmin.realm(realm_name).identity_providers
|
|
69
|
-
|
|
70
|
-
stub_token_client
|
|
71
|
-
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_response
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "lists identity providers" do
|
|
75
|
-
identity_providers = @identity_provider_client.list
|
|
76
|
-
expect(identity_providers.length).to eq 1
|
|
77
|
-
expect(identity_providers[0].alias).to eq "acme"
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "passes rest client options" do
|
|
81
|
-
rest_client_options = {timeout: 10}
|
|
82
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
83
|
-
|
|
84
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
85
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/identity-provider/instances", rest_client_options).and_call_original
|
|
86
|
-
|
|
87
|
-
identity_providers = @identity_provider_client.list
|
|
88
|
-
expect(identity_providers.length).to eq 1
|
|
89
|
-
expect(identity_providers[0].alias).to eq "acme"
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
1
|
+
RSpec.describe KeycloakAdmin::IdentityProviderClient do
|
|
2
|
+
describe "#identity_providers_url" do
|
|
3
|
+
let(:realm_name) { "valid-realm" }
|
|
4
|
+
let(:provider_id) { nil }
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
@built_url = KeycloakAdmin.realm(realm_name).identity_providers.identity_providers_url(provider_id)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when provider_id is not defined" do
|
|
11
|
+
let(:provider_id) { nil }
|
|
12
|
+
it "returns a proper url without provider id" do
|
|
13
|
+
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/identity-provider/instances"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "when provider_id is defined" do
|
|
18
|
+
let(:provider_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
|
|
19
|
+
it "returns a proper url with the provider id" do
|
|
20
|
+
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/identity-provider/instances/95985b21-d884-4bbd-b852-cb8cd365afc2"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#list" do
|
|
26
|
+
let(:realm_name) { "valid-realm" }
|
|
27
|
+
let(:json_response) do
|
|
28
|
+
<<-JSON
|
|
29
|
+
[
|
|
30
|
+
{
|
|
31
|
+
"alias": "acme",
|
|
32
|
+
"displayName": "ACME",
|
|
33
|
+
"internalId": "20fea77e-ae3d-411e-9467-2b3a20cd3e6d",
|
|
34
|
+
"providerId": "saml",
|
|
35
|
+
"enabled": true,
|
|
36
|
+
"updateProfileFirstLoginMode": "on",
|
|
37
|
+
"trustEmail": true,
|
|
38
|
+
"storeToken": false,
|
|
39
|
+
"addReadTokenRoleOnCreate": false,
|
|
40
|
+
"authenticateByDefault": false,
|
|
41
|
+
"linkOnly": false,
|
|
42
|
+
"firstBrokerLoginFlowAlias": "first broker login",
|
|
43
|
+
"config": {
|
|
44
|
+
"hideOnLoginPage": "",
|
|
45
|
+
"validateSignature": "true",
|
|
46
|
+
"samlXmlKeyNameTranformer": "KEY_ID",
|
|
47
|
+
"signingCertificate": "",
|
|
48
|
+
"postBindingLogout": "false",
|
|
49
|
+
"nameIDPolicyFormat": "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
|
|
50
|
+
"postBindingResponse": "true",
|
|
51
|
+
"backchannelSupported": "",
|
|
52
|
+
"signatureAlgorithm": "RSA_SHA256",
|
|
53
|
+
"wantAssertionsEncrypted": "false",
|
|
54
|
+
"xmlSigKeyInfoKeyNameTransformer": "CERT_SUBJECT",
|
|
55
|
+
"useJwksUrl": "true",
|
|
56
|
+
"wantAssertionsSigned": "true",
|
|
57
|
+
"postBindingAuthnRequest": "true",
|
|
58
|
+
"forceAuthn": "",
|
|
59
|
+
"wantAuthnRequestsSigned": "true",
|
|
60
|
+
"singleSignOnServiceUrl": "https://login.microsoftonline.com/test/saml2",
|
|
61
|
+
"addExtensionsElementWithKeyInfo": "false"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
JSON
|
|
66
|
+
end
|
|
67
|
+
before(:each) do
|
|
68
|
+
@identity_provider_client = KeycloakAdmin.realm(realm_name).identity_providers
|
|
69
|
+
|
|
70
|
+
stub_token_client
|
|
71
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return json_response
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "lists identity providers" do
|
|
75
|
+
identity_providers = @identity_provider_client.list
|
|
76
|
+
expect(identity_providers.length).to eq 1
|
|
77
|
+
expect(identity_providers[0].alias).to eq "acme"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "passes rest client options" do
|
|
81
|
+
rest_client_options = {timeout: 10}
|
|
82
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
83
|
+
|
|
84
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
85
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/identity-provider/instances", rest_client_options).and_call_original
|
|
86
|
+
|
|
87
|
+
identity_providers = @identity_provider_client.list
|
|
88
|
+
expect(identity_providers.length).to eq 1
|
|
89
|
+
expect(identity_providers[0].alias).to eq "acme"
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::RealmClient do
|
|
2
|
-
describe "#realm_url" do
|
|
3
|
-
|
|
4
|
-
let(:realm_name) { nil }
|
|
5
|
-
|
|
6
|
-
before(:each) do
|
|
7
|
-
@built_url = KeycloakAdmin.realm(realm_name).realm_url
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "when realm_name is defined" do
|
|
11
|
-
let(:realm_name) { "master2" }
|
|
12
|
-
it "return a proper url with realm_name" do
|
|
13
|
-
expect(@built_url).to eq "http://auth.service.io/auth/realms/master2"
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context "when realm_name is not defined" do
|
|
18
|
-
let(:realm_name) { nil }
|
|
19
|
-
it "return a proper url without realm_name" do
|
|
20
|
-
expect(@built_url).to eq "http://auth.service.io/auth/realms"
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe "#admin_realm_url" do
|
|
26
|
-
|
|
27
|
-
let(:realm_name) { nil }
|
|
28
|
-
|
|
29
|
-
before(:each) do
|
|
30
|
-
@built_url = KeycloakAdmin.realm(realm_name).realm_admin_url
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "when realm_name is defined" do
|
|
34
|
-
let(:realm_name) { "master2" }
|
|
35
|
-
it "return a proper url with realm_name" do
|
|
36
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/master2"
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
context "when realm_name is not defined" do
|
|
41
|
-
let(:realm_name) { nil }
|
|
42
|
-
it "return a proper url without realm_name" do
|
|
43
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
describe "#list" do
|
|
49
|
-
before(:each) do
|
|
50
|
-
@realm_client = KeycloakAdmin.realm('master')
|
|
51
|
-
|
|
52
|
-
stub_token_client
|
|
53
|
-
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '[{"id":"test_realm","realm":"test_realm"}]'
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "lists realms" do
|
|
57
|
-
realms = @realm_client.list
|
|
58
|
-
expect(realms.length).to eq 1
|
|
59
|
-
expect(realms[0].realm).to eq "test_realm"
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "passes rest client options" do
|
|
63
|
-
rest_client_options = {timeout: 10}
|
|
64
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
65
|
-
|
|
66
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
67
|
-
"http://auth.service.io/auth/admin/realms", rest_client_options).and_call_original
|
|
68
|
-
|
|
69
|
-
realms = @realm_client.list
|
|
70
|
-
expect(realms.length).to eq 1
|
|
71
|
-
expect(realms[0].realm).to eq "test_realm"
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
describe "#delete" do
|
|
76
|
-
let(:realm_name) { "valid-realm" }
|
|
77
|
-
|
|
78
|
-
before(:each) do
|
|
79
|
-
@realm_client = KeycloakAdmin.realm(realm_name)
|
|
80
|
-
|
|
81
|
-
stub_token_client
|
|
82
|
-
allow_any_instance_of(RestClient::Resource).to receive(:delete)
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "delete realm" do
|
|
86
|
-
expect(@realm_client.delete).to be_truthy
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "passes rest client options" do
|
|
90
|
-
rest_client_options = {timeout: 10}
|
|
91
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
92
|
-
|
|
93
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
94
|
-
"http://auth.service.io/auth/admin/realms/valid-realm", rest_client_options).and_call_original
|
|
95
|
-
|
|
96
|
-
expect(@realm_client.delete).to be_truthy
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
describe "#save" do
|
|
101
|
-
let(:realm_name) { "valid-realm" }
|
|
102
|
-
let(:realm) { KeycloakAdmin::RealmRepresentation.from_hash(
|
|
103
|
-
"id" => realm_name,
|
|
104
|
-
"realm" => realm_name
|
|
105
|
-
)}
|
|
106
|
-
|
|
107
|
-
before(:each) do
|
|
108
|
-
@realm_client = KeycloakAdmin.realm(nil)
|
|
109
|
-
|
|
110
|
-
stub_token_client
|
|
111
|
-
|
|
112
|
-
expect_any_instance_of(RestClient::Resource).to receive(:post).with(realm.to_json, anything)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "saves a realm" do
|
|
116
|
-
@realm_client.save(realm)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
it "passes rest client options" do
|
|
120
|
-
rest_client_options = {timeout: 10}
|
|
121
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
122
|
-
|
|
123
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
124
|
-
"http://auth.service.io/auth/admin/realms", rest_client_options).and_call_original
|
|
125
|
-
|
|
126
|
-
@realm_client.save(realm)
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
describe "#update" do
|
|
131
|
-
let(:realm_name) { "valid-realm" }
|
|
132
|
-
let(:realm_json) { { smtpServer: { host: 'test_host' } } }
|
|
133
|
-
|
|
134
|
-
before(:each) do
|
|
135
|
-
@realm_client = KeycloakAdmin.realm(realm_name)
|
|
136
|
-
|
|
137
|
-
stub_token_client
|
|
138
|
-
expect_any_instance_of(RestClient::Resource).to receive(:put).with(realm_json.to_json, anything)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
it "updates a realm" do
|
|
142
|
-
@realm_client.update(realm_json)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it "passes rest client options" do
|
|
146
|
-
rest_client_options = {timeout: 10}
|
|
147
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
148
|
-
|
|
149
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
150
|
-
"http://auth.service.io/auth/admin/realms/valid-realm", rest_client_options).and_call_original
|
|
151
|
-
|
|
152
|
-
@realm_client.update(realm_json)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
1
|
+
RSpec.describe KeycloakAdmin::RealmClient do
|
|
2
|
+
describe "#realm_url" do
|
|
3
|
+
|
|
4
|
+
let(:realm_name) { nil }
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
@built_url = KeycloakAdmin.realm(realm_name).realm_url
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
context "when realm_name is defined" do
|
|
11
|
+
let(:realm_name) { "master2" }
|
|
12
|
+
it "return a proper url with realm_name" do
|
|
13
|
+
expect(@built_url).to eq "http://auth.service.io/auth/realms/master2"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "when realm_name is not defined" do
|
|
18
|
+
let(:realm_name) { nil }
|
|
19
|
+
it "return a proper url without realm_name" do
|
|
20
|
+
expect(@built_url).to eq "http://auth.service.io/auth/realms"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe "#admin_realm_url" do
|
|
26
|
+
|
|
27
|
+
let(:realm_name) { nil }
|
|
28
|
+
|
|
29
|
+
before(:each) do
|
|
30
|
+
@built_url = KeycloakAdmin.realm(realm_name).realm_admin_url
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context "when realm_name is defined" do
|
|
34
|
+
let(:realm_name) { "master2" }
|
|
35
|
+
it "return a proper url with realm_name" do
|
|
36
|
+
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/master2"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "when realm_name is not defined" do
|
|
41
|
+
let(:realm_name) { nil }
|
|
42
|
+
it "return a proper url without realm_name" do
|
|
43
|
+
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe "#list" do
|
|
49
|
+
before(:each) do
|
|
50
|
+
@realm_client = KeycloakAdmin.realm('master')
|
|
51
|
+
|
|
52
|
+
stub_token_client
|
|
53
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '[{"id":"test_realm","realm":"test_realm"}]'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "lists realms" do
|
|
57
|
+
realms = @realm_client.list
|
|
58
|
+
expect(realms.length).to eq 1
|
|
59
|
+
expect(realms[0].realm).to eq "test_realm"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "passes rest client options" do
|
|
63
|
+
rest_client_options = {timeout: 10}
|
|
64
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
65
|
+
|
|
66
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
67
|
+
"http://auth.service.io/auth/admin/realms", rest_client_options).and_call_original
|
|
68
|
+
|
|
69
|
+
realms = @realm_client.list
|
|
70
|
+
expect(realms.length).to eq 1
|
|
71
|
+
expect(realms[0].realm).to eq "test_realm"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe "#delete" do
|
|
76
|
+
let(:realm_name) { "valid-realm" }
|
|
77
|
+
|
|
78
|
+
before(:each) do
|
|
79
|
+
@realm_client = KeycloakAdmin.realm(realm_name)
|
|
80
|
+
|
|
81
|
+
stub_token_client
|
|
82
|
+
allow_any_instance_of(RestClient::Resource).to receive(:delete)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "delete realm" do
|
|
86
|
+
expect(@realm_client.delete).to be_truthy
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "passes rest client options" do
|
|
90
|
+
rest_client_options = {timeout: 10}
|
|
91
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
92
|
+
|
|
93
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
94
|
+
"http://auth.service.io/auth/admin/realms/valid-realm", rest_client_options).and_call_original
|
|
95
|
+
|
|
96
|
+
expect(@realm_client.delete).to be_truthy
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
describe "#save" do
|
|
101
|
+
let(:realm_name) { "valid-realm" }
|
|
102
|
+
let(:realm) { KeycloakAdmin::RealmRepresentation.from_hash(
|
|
103
|
+
"id" => realm_name,
|
|
104
|
+
"realm" => realm_name
|
|
105
|
+
)}
|
|
106
|
+
|
|
107
|
+
before(:each) do
|
|
108
|
+
@realm_client = KeycloakAdmin.realm(nil)
|
|
109
|
+
|
|
110
|
+
stub_token_client
|
|
111
|
+
|
|
112
|
+
expect_any_instance_of(RestClient::Resource).to receive(:post).with(realm.to_json, anything)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "saves a realm" do
|
|
116
|
+
@realm_client.save(realm)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "passes rest client options" do
|
|
120
|
+
rest_client_options = {timeout: 10}
|
|
121
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
122
|
+
|
|
123
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
124
|
+
"http://auth.service.io/auth/admin/realms", rest_client_options).and_call_original
|
|
125
|
+
|
|
126
|
+
@realm_client.save(realm)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe "#update" do
|
|
131
|
+
let(:realm_name) { "valid-realm" }
|
|
132
|
+
let(:realm_json) { { smtpServer: { host: 'test_host' } } }
|
|
133
|
+
|
|
134
|
+
before(:each) do
|
|
135
|
+
@realm_client = KeycloakAdmin.realm(realm_name)
|
|
136
|
+
|
|
137
|
+
stub_token_client
|
|
138
|
+
expect_any_instance_of(RestClient::Resource).to receive(:put).with(realm_json.to_json, anything)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it "updates a realm" do
|
|
142
|
+
@realm_client.update(realm_json)
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it "passes rest client options" do
|
|
146
|
+
rest_client_options = {timeout: 10}
|
|
147
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
148
|
+
|
|
149
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
150
|
+
"http://auth.service.io/auth/admin/realms/valid-realm", rest_client_options).and_call_original
|
|
151
|
+
|
|
152
|
+
@realm_client.update(realm_json)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::RoleClient do
|
|
2
|
-
describe "#roles_url" do
|
|
3
|
-
let(:realm_name) { "valid-realm" }
|
|
4
|
-
|
|
5
|
-
it "return a proper url without role id" do
|
|
6
|
-
@built_url = KeycloakAdmin.realm(realm_name).roles.roles_url
|
|
7
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/roles"
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
describe "#role_id_url" do
|
|
12
|
-
let(:realm_name) { "valid-realm" }
|
|
13
|
-
let(:role_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
|
|
14
|
-
|
|
15
|
-
it "return a proper url with the role id" do
|
|
16
|
-
@built_url = KeycloakAdmin.realm(realm_name).roles.role_id_url(role_id)
|
|
17
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/roles-by-id/95985b21-d884-4bbd-b852-cb8cd365afc2"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "#list" do
|
|
22
|
-
let(:realm_name) { "valid-realm" }
|
|
23
|
-
|
|
24
|
-
before(:each) do
|
|
25
|
-
@role_client = KeycloakAdmin.realm(realm_name).roles
|
|
26
|
-
|
|
27
|
-
stub_token_client
|
|
28
|
-
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '[{"id":"test_role_id","name":"test_role_name"}]'
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it "lists roles" do
|
|
32
|
-
roles = @role_client.list
|
|
33
|
-
expect(roles.length).to eq 1
|
|
34
|
-
expect(roles[0].name).to eq "test_role_name"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
it "passes rest client options" do
|
|
38
|
-
rest_client_options = {timeout: 10}
|
|
39
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
40
|
-
|
|
41
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
42
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/roles", rest_client_options).and_call_original
|
|
43
|
-
|
|
44
|
-
roles = @role_client.list
|
|
45
|
-
expect(roles.length).to eq 1
|
|
46
|
-
expect(roles[0].name).to eq "test_role_name"
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
describe "#save" do
|
|
51
|
-
let(:realm_name) { "valid-realm" }
|
|
52
|
-
let(:role) { KeycloakAdmin::RoleRepresentation.from_hash(
|
|
53
|
-
"name" => "test_role_name",
|
|
54
|
-
"composite" => false,
|
|
55
|
-
"clientRole" => false
|
|
56
|
-
)}
|
|
57
|
-
|
|
58
|
-
before(:each) do
|
|
59
|
-
@role_client = KeycloakAdmin.realm(realm_name).roles
|
|
60
|
-
|
|
61
|
-
stub_token_client
|
|
62
|
-
expect_any_instance_of(RestClient::Resource).to receive(:post).with(role.to_json, anything)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
it "saves a role" do
|
|
66
|
-
@role_client.save(role)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "passes rest client options" do
|
|
70
|
-
rest_client_options = {timeout: 10}
|
|
71
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
72
|
-
|
|
73
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
74
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/roles", rest_client_options).and_call_original
|
|
75
|
-
|
|
76
|
-
@role_client.save(role)
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
end
|
|
1
|
+
RSpec.describe KeycloakAdmin::RoleClient do
|
|
2
|
+
describe "#roles_url" do
|
|
3
|
+
let(:realm_name) { "valid-realm" }
|
|
4
|
+
|
|
5
|
+
it "return a proper url without role id" do
|
|
6
|
+
@built_url = KeycloakAdmin.realm(realm_name).roles.roles_url
|
|
7
|
+
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/roles"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe "#role_id_url" do
|
|
12
|
+
let(:realm_name) { "valid-realm" }
|
|
13
|
+
let(:role_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
|
|
14
|
+
|
|
15
|
+
it "return a proper url with the role id" do
|
|
16
|
+
@built_url = KeycloakAdmin.realm(realm_name).roles.role_id_url(role_id)
|
|
17
|
+
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/roles-by-id/95985b21-d884-4bbd-b852-cb8cd365afc2"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "#list" do
|
|
22
|
+
let(:realm_name) { "valid-realm" }
|
|
23
|
+
|
|
24
|
+
before(:each) do
|
|
25
|
+
@role_client = KeycloakAdmin.realm(realm_name).roles
|
|
26
|
+
|
|
27
|
+
stub_token_client
|
|
28
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '[{"id":"test_role_id","name":"test_role_name"}]'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "lists roles" do
|
|
32
|
+
roles = @role_client.list
|
|
33
|
+
expect(roles.length).to eq 1
|
|
34
|
+
expect(roles[0].name).to eq "test_role_name"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "passes rest client options" do
|
|
38
|
+
rest_client_options = {timeout: 10}
|
|
39
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
40
|
+
|
|
41
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
42
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/roles", rest_client_options).and_call_original
|
|
43
|
+
|
|
44
|
+
roles = @role_client.list
|
|
45
|
+
expect(roles.length).to eq 1
|
|
46
|
+
expect(roles[0].name).to eq "test_role_name"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe "#save" do
|
|
51
|
+
let(:realm_name) { "valid-realm" }
|
|
52
|
+
let(:role) { KeycloakAdmin::RoleRepresentation.from_hash(
|
|
53
|
+
"name" => "test_role_name",
|
|
54
|
+
"composite" => false,
|
|
55
|
+
"clientRole" => false
|
|
56
|
+
)}
|
|
57
|
+
|
|
58
|
+
before(:each) do
|
|
59
|
+
@role_client = KeycloakAdmin.realm(realm_name).roles
|
|
60
|
+
|
|
61
|
+
stub_token_client
|
|
62
|
+
expect_any_instance_of(RestClient::Resource).to receive(:post).with(role.to_json, anything)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "saves a role" do
|
|
66
|
+
@role_client.save(role)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "passes rest client options" do
|
|
70
|
+
rest_client_options = {timeout: 10}
|
|
71
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
72
|
+
|
|
73
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
74
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/roles", rest_client_options).and_call_original
|
|
75
|
+
|
|
76
|
+
@role_client.save(role)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|