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,68 +1,113 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::RoleMapperClient do
|
|
2
|
-
describe "#available_url" do
|
|
3
|
-
let(:realm_name) { "valid-realm" }
|
|
4
|
-
let(:user_id) { "test_user" }
|
|
5
|
-
|
|
6
|
-
before(:each) do
|
|
7
|
-
@built_url = KeycloakAdmin.realm(realm_name).user(user_id).role_mapper.realm_level_url
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "return a proper url" do
|
|
11
|
-
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/realm"
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
describe "#list" do
|
|
16
|
-
let(:realm_name) { "valid-realm" }
|
|
17
|
-
let(:user_id) { "test_user" }
|
|
18
|
-
|
|
19
|
-
before(:each) do
|
|
20
|
-
@role_mapper_client = KeycloakAdmin.realm(realm_name).user(user_id).role_mapper
|
|
21
|
-
|
|
22
|
-
stub_token_client
|
|
23
|
-
allow_any_instance_of(RestClient::Resource).to receive(:get)
|
|
24
|
-
.and_return '[{"id":"test_role_id","name":"test_role_name","composite": false}]'
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
it "list user realm-level role mappings" do
|
|
28
|
-
roles = @role_mapper_client.list
|
|
29
|
-
expect(roles.length).to eq 1
|
|
30
|
-
expect(roles[0].id).to eq "test_role_id"
|
|
31
|
-
expect(roles[0].name).to eq "test_role_name"
|
|
32
|
-
expect(roles[0].composite).to be false
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe "#save_realm_level" do
|
|
37
|
-
let(:realm_name) { "valid-realm" }
|
|
38
|
-
let(:user_id) { "test_user" }
|
|
39
|
-
let(:role_list) { [
|
|
40
|
-
KeycloakAdmin::RoleRepresentation.from_hash(
|
|
41
|
-
"name" => "test_role_name",
|
|
42
|
-
"composite" => false,
|
|
43
|
-
"clientRole" => false
|
|
44
|
-
)
|
|
45
|
-
] }
|
|
46
|
-
|
|
47
|
-
before(:each) do
|
|
48
|
-
@role_mapper_client = KeycloakAdmin.realm(realm_name).user(user_id).role_mapper
|
|
49
|
-
|
|
50
|
-
stub_token_client
|
|
51
|
-
expect_any_instance_of(RestClient::Resource).to receive(:post).with(role_list.to_json, anything)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "saves realm-elevel role mappings" do
|
|
55
|
-
@role_mapper_client.save_realm_level(role_list)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "passes rest client options" do
|
|
59
|
-
rest_client_options = {timeout: 10}
|
|
60
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
61
|
-
|
|
62
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
63
|
-
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/realm", rest_client_options).and_call_original
|
|
64
|
-
|
|
65
|
-
@role_mapper_client.save_realm_level(role_list)
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
1
|
+
RSpec.describe KeycloakAdmin::RoleMapperClient do
|
|
2
|
+
describe "#available_url" do
|
|
3
|
+
let(:realm_name) { "valid-realm" }
|
|
4
|
+
let(:user_id) { "test_user" }
|
|
5
|
+
|
|
6
|
+
before(:each) do
|
|
7
|
+
@built_url = KeycloakAdmin.realm(realm_name).user(user_id).role_mapper.realm_level_url
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "return a proper url" do
|
|
11
|
+
expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/realm"
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe "#list" do
|
|
16
|
+
let(:realm_name) { "valid-realm" }
|
|
17
|
+
let(:user_id) { "test_user" }
|
|
18
|
+
|
|
19
|
+
before(:each) do
|
|
20
|
+
@role_mapper_client = KeycloakAdmin.realm(realm_name).user(user_id).role_mapper
|
|
21
|
+
|
|
22
|
+
stub_token_client
|
|
23
|
+
allow_any_instance_of(RestClient::Resource).to receive(:get)
|
|
24
|
+
.and_return '[{"id":"test_role_id","name":"test_role_name","composite": false}]'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "list user realm-level role mappings" do
|
|
28
|
+
roles = @role_mapper_client.list
|
|
29
|
+
expect(roles.length).to eq 1
|
|
30
|
+
expect(roles[0].id).to eq "test_role_id"
|
|
31
|
+
expect(roles[0].name).to eq "test_role_name"
|
|
32
|
+
expect(roles[0].composite).to be false
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe "#save_realm_level" do
|
|
37
|
+
let(:realm_name) { "valid-realm" }
|
|
38
|
+
let(:user_id) { "test_user" }
|
|
39
|
+
let(:role_list) { [
|
|
40
|
+
KeycloakAdmin::RoleRepresentation.from_hash(
|
|
41
|
+
"name" => "test_role_name",
|
|
42
|
+
"composite" => false,
|
|
43
|
+
"clientRole" => false
|
|
44
|
+
)
|
|
45
|
+
] }
|
|
46
|
+
|
|
47
|
+
before(:each) do
|
|
48
|
+
@role_mapper_client = KeycloakAdmin.realm(realm_name).user(user_id).role_mapper
|
|
49
|
+
|
|
50
|
+
stub_token_client
|
|
51
|
+
expect_any_instance_of(RestClient::Resource).to receive(:post).with(role_list.to_json, anything)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it "saves realm-elevel role mappings" do
|
|
55
|
+
@role_mapper_client.save_realm_level(role_list)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "passes rest client options" do
|
|
59
|
+
rest_client_options = {timeout: 10}
|
|
60
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
61
|
+
|
|
62
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
63
|
+
"http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/realm", rest_client_options).and_call_original
|
|
64
|
+
|
|
65
|
+
@role_mapper_client.save_realm_level(role_list)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
describe "#remove_realm_level" do
|
|
70
|
+
let(:realm_name) { "valid-realm" }
|
|
71
|
+
let(:user_id) { "test_user" }
|
|
72
|
+
let(:role_list) { [
|
|
73
|
+
KeycloakAdmin::RoleRepresentation.from_hash(
|
|
74
|
+
"id" => "d9e3376b-f602-4086-8eee-89fea73c73ea"
|
|
75
|
+
)
|
|
76
|
+
] }
|
|
77
|
+
let(:expected_url) { "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/realm" }
|
|
78
|
+
|
|
79
|
+
before(:each) do
|
|
80
|
+
@role_mapper_client = KeycloakAdmin.realm(realm_name).user(user_id).role_mapper
|
|
81
|
+
|
|
82
|
+
stub_token_client
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "removes realm-level role mappings" do
|
|
86
|
+
expect(RestClient::Request).to receive(:execute).with(
|
|
87
|
+
hash_including(
|
|
88
|
+
method: :delete,
|
|
89
|
+
url: expected_url,
|
|
90
|
+
payload: role_list.to_json
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
@role_mapper_client.remove_realm_level(role_list)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "passes rest client options" do
|
|
98
|
+
rest_client_options = {timeout: 10}
|
|
99
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
100
|
+
|
|
101
|
+
expect(RestClient::Request).to receive(:execute).with(
|
|
102
|
+
hash_including(
|
|
103
|
+
method: :delete,
|
|
104
|
+
url: expected_url,
|
|
105
|
+
payload: role_list.to_json,
|
|
106
|
+
timeout: 10
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
@role_mapper_client.remove_realm_level(role_list)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::TokenClient do
|
|
2
|
-
describe "#initialize" do
|
|
3
|
-
let(:realm_name) { nil }
|
|
4
|
-
before(:each) do
|
|
5
|
-
@realm = KeycloakAdmin.realm(realm_name)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
context "when realm_name is defined" do
|
|
9
|
-
let(:realm_name) { "master" }
|
|
10
|
-
it "does not raise any error" do
|
|
11
|
-
expect {
|
|
12
|
-
@realm.token
|
|
13
|
-
}.to_not raise_error
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
context "when realm_name is not defined" do
|
|
18
|
-
let(:realm_name) { nil }
|
|
19
|
-
it "raises any error" do
|
|
20
|
-
expect {
|
|
21
|
-
@realm.token
|
|
22
|
-
}.to raise_error(ArgumentError)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
describe "#token_url" do
|
|
28
|
-
let(:realm_name) { "valid-realm" }
|
|
29
|
-
before(:each) do
|
|
30
|
-
@built_url = KeycloakAdmin.realm(realm_name).token.token_url
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it "returns a proper url" do
|
|
34
|
-
expect(@built_url).to eq "http://auth.service.io/auth/realms/valid-realm/protocol/openid-connect/token"
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "#get" do
|
|
39
|
-
let(:realm_name) { "valid-realm" }
|
|
40
|
-
before(:each) do
|
|
41
|
-
@token_client = KeycloakAdmin.realm(realm_name).token
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it "parses the response" do
|
|
45
|
-
stub_post
|
|
46
|
-
|
|
47
|
-
token = @token_client.get
|
|
48
|
-
expect(token.access_token).to eq 'test_access_token'
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "passes rest client options" do
|
|
52
|
-
rest_client_options = {timeout: 10}
|
|
53
|
-
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
54
|
-
stub_post
|
|
55
|
-
|
|
56
|
-
expect(RestClient::Resource).to receive(:new).with(
|
|
57
|
-
"http://auth.service.io/auth/realms/valid-realm/protocol/openid-connect/token", rest_client_options).and_call_original
|
|
58
|
-
|
|
59
|
-
@token_client.get
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def stub_post
|
|
63
|
-
response = double
|
|
64
|
-
allow(response).to receive(:body).and_return '{"access_token":"test_access_token"}'
|
|
65
|
-
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return response
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
end
|
|
1
|
+
RSpec.describe KeycloakAdmin::TokenClient do
|
|
2
|
+
describe "#initialize" do
|
|
3
|
+
let(:realm_name) { nil }
|
|
4
|
+
before(:each) do
|
|
5
|
+
@realm = KeycloakAdmin.realm(realm_name)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context "when realm_name is defined" do
|
|
9
|
+
let(:realm_name) { "master" }
|
|
10
|
+
it "does not raise any error" do
|
|
11
|
+
expect {
|
|
12
|
+
@realm.token
|
|
13
|
+
}.to_not raise_error
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
context "when realm_name is not defined" do
|
|
18
|
+
let(:realm_name) { nil }
|
|
19
|
+
it "raises any error" do
|
|
20
|
+
expect {
|
|
21
|
+
@realm.token
|
|
22
|
+
}.to raise_error(ArgumentError)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe "#token_url" do
|
|
28
|
+
let(:realm_name) { "valid-realm" }
|
|
29
|
+
before(:each) do
|
|
30
|
+
@built_url = KeycloakAdmin.realm(realm_name).token.token_url
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "returns a proper url" do
|
|
34
|
+
expect(@built_url).to eq "http://auth.service.io/auth/realms/valid-realm/protocol/openid-connect/token"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
describe "#get" do
|
|
39
|
+
let(:realm_name) { "valid-realm" }
|
|
40
|
+
before(:each) do
|
|
41
|
+
@token_client = KeycloakAdmin.realm(realm_name).token
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "parses the response" do
|
|
45
|
+
stub_post
|
|
46
|
+
|
|
47
|
+
token = @token_client.get
|
|
48
|
+
expect(token.access_token).to eq 'test_access_token'
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "passes rest client options" do
|
|
52
|
+
rest_client_options = {timeout: 10}
|
|
53
|
+
allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
|
|
54
|
+
stub_post
|
|
55
|
+
|
|
56
|
+
expect(RestClient::Resource).to receive(:new).with(
|
|
57
|
+
"http://auth.service.io/auth/realms/valid-realm/protocol/openid-connect/token", rest_client_options).and_call_original
|
|
58
|
+
|
|
59
|
+
@token_client.get
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def stub_post
|
|
63
|
+
response = double
|
|
64
|
+
allow(response).to receive(:body).and_return '{"access_token":"test_access_token"}'
|
|
65
|
+
allow_any_instance_of(RestClient::Resource).to receive(:post).and_return response
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|