keycloak-admin 1.1.4 → 1.1.6

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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/Dockerfile +24 -24
  3. data/.github/workflows/ci.yml +80 -80
  4. data/.gitignore +9 -9
  5. data/.rspec +2 -2
  6. data/CHANGELOG.md +23 -0
  7. data/Dockerfile +12 -12
  8. data/Gemfile +3 -3
  9. data/Gemfile.lock +1 -1
  10. data/MIT-LICENSE +20 -20
  11. data/README.md +20 -1
  12. data/bin/console +9 -9
  13. data/keycloak-admin.gemspec +24 -24
  14. data/lib/keycloak-admin/client/attack_detection_client.rb +41 -41
  15. data/lib/keycloak-admin/client/client.rb +56 -56
  16. data/lib/keycloak-admin/client/client_authz_permission_client.rb +80 -80
  17. data/lib/keycloak-admin/client/client_authz_policy_client.rb +75 -75
  18. data/lib/keycloak-admin/client/client_authz_resource_client.rb +92 -92
  19. data/lib/keycloak-admin/client/client_authz_scope_client.rb +70 -70
  20. data/lib/keycloak-admin/client/client_client.rb +71 -71
  21. data/lib/keycloak-admin/client/client_role_client.rb +20 -20
  22. data/lib/keycloak-admin/client/client_role_mappings_client.rb +32 -32
  23. data/lib/keycloak-admin/client/configurable_token_client.rb +35 -35
  24. data/lib/keycloak-admin/client/group_client.rb +148 -148
  25. data/lib/keycloak-admin/client/identity_provider_client.rb +51 -51
  26. data/lib/keycloak-admin/client/organization_client.rb +245 -0
  27. data/lib/keycloak-admin/client/realm_client.rb +126 -122
  28. data/lib/keycloak-admin/client/role_client.rb +59 -59
  29. data/lib/keycloak-admin/client/role_mapper_client.rb +47 -47
  30. data/lib/keycloak-admin/client/token_client.rb +29 -29
  31. data/lib/keycloak-admin/client/user_client.rb +278 -266
  32. data/lib/keycloak-admin/configuration.rb +52 -52
  33. data/lib/keycloak-admin/representation/attack_detection_representation.rb +17 -17
  34. data/lib/keycloak-admin/representation/camel_json.rb +12 -12
  35. data/lib/keycloak-admin/representation/client_authz_permission_representation.rb +33 -33
  36. data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +14 -14
  37. data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +26 -26
  38. data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +25 -25
  39. data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +16 -16
  40. data/lib/keycloak-admin/representation/client_representation.rb +71 -71
  41. data/lib/keycloak-admin/representation/credential_representation.rb +71 -38
  42. data/lib/keycloak-admin/representation/federated_identity_representation.rb +15 -15
  43. data/lib/keycloak-admin/representation/group_representation.rb +21 -21
  44. data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +19 -19
  45. data/lib/keycloak-admin/representation/identity_provider_representation.rb +71 -67
  46. data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +16 -16
  47. data/lib/keycloak-admin/representation/impersonation_representation.rb +43 -43
  48. data/lib/keycloak-admin/representation/member_representation.rb +11 -0
  49. data/lib/keycloak-admin/representation/organization_domain_representation.rb +18 -0
  50. data/lib/keycloak-admin/representation/organization_representation.rb +30 -0
  51. data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +19 -19
  52. data/lib/keycloak-admin/representation/realm_representation.rb +14 -14
  53. data/lib/keycloak-admin/representation/representation.rb +23 -23
  54. data/lib/keycloak-admin/representation/role_representation.rb +19 -19
  55. data/lib/keycloak-admin/representation/session_representation.rb +22 -22
  56. data/lib/keycloak-admin/representation/token_representation.rb +39 -39
  57. data/lib/keycloak-admin/representation/user_representation.rb +47 -47
  58. data/lib/keycloak-admin/resource/base_role_containing_resource.rb +28 -28
  59. data/lib/keycloak-admin/resource/group_resource.rb +11 -11
  60. data/lib/keycloak-admin/resource/user_resource.rb +7 -7
  61. data/lib/keycloak-admin/version.rb +3 -3
  62. data/lib/keycloak-admin.rb +88 -84
  63. data/spec/client/attack_detection_client_spec.rb +102 -102
  64. data/spec/client/client_authz_permission_client_spec.rb +170 -170
  65. data/spec/client/client_authz_policy_client_spec.rb +169 -169
  66. data/spec/client/client_authz_resource_client_spec.rb +150 -150
  67. data/spec/client/client_authz_scope_client_spec.rb +133 -133
  68. data/spec/client/client_client_spec.rb +133 -133
  69. data/spec/client/client_role_mappings_client_spec.rb +82 -82
  70. data/spec/client/client_spec.rb +28 -28
  71. data/spec/client/configurable_token_client_spec.rb +34 -34
  72. data/spec/client/group_client_spec.rb +328 -328
  73. data/spec/client/identity_provider_client_spec.rb +92 -92
  74. data/spec/client/organization_client_spec.rb +595 -0
  75. data/spec/client/realm_client_spec.rb +155 -155
  76. data/spec/client/role_client_spec.rb +79 -79
  77. data/spec/client/role_mapper_client_spec.rb +113 -113
  78. data/spec/client/token_client_spec.rb +68 -68
  79. data/spec/client/user_client_spec.rb +418 -373
  80. data/spec/configuration_spec.rb +113 -113
  81. data/spec/integration/client_authorization_spec.rb +93 -93
  82. data/spec/representation/attack_detection_representation_spec.rb +15 -15
  83. data/spec/representation/client_authz_permission_representation_spec.rb +52 -52
  84. data/spec/representation/client_authz_policy_representation_spec.rb +46 -46
  85. data/spec/representation/client_authz_resource_representation_spec.rb +33 -33
  86. data/spec/representation/client_authz_scope_representation_spec.rb +18 -18
  87. data/spec/representation/client_representation_spec.rb +119 -119
  88. data/spec/representation/credential_representation_spec.rb +68 -0
  89. data/spec/representation/group_representation_spec.rb +22 -22
  90. data/spec/representation/identity_provider_mapper_representation_spec.rb +24 -24
  91. data/spec/representation/identity_provider_representation_spec.rb +113 -113
  92. data/spec/representation/impersonation_representation_spec.rb +163 -163
  93. data/spec/representation/organization_representation_spec.rb +64 -0
  94. data/spec/representation/protocol_mapper_representation_spec.rb +57 -57
  95. data/spec/representation/role_representation_spec.rb +37 -37
  96. data/spec/representation/session_representation_spec.rb +15 -15
  97. data/spec/representation/user_representation_spec.rb +15 -15
  98. data/spec/resource/group_resource_spec.rb +14 -14
  99. data/spec/resource/user_resource_spec.rb +14 -14
  100. data/spec/spec_helper.rb +37 -37
  101. metadata +13 -6
@@ -1,133 +1,133 @@
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(RestClient::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(RestClient::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(RestClient::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
- rest_client_options = {timeout: 10}
86
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
87
-
88
- expect(RestClient::Resource).to receive(:new).with(
89
- "http://auth.service.io/auth/admin/realms/valid-realm/clients", rest_client_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(RestClient::Resource).to receive(:put).and_return ''
106
- allow_any_instance_of(RestClient::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(RestClient::Resource).to receive(:delete).and_return ''
123
- end
124
-
125
- it "passes rest client options" do
126
- rest_client_options = {timeout: 10}
127
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
128
- expect(RestClient::Resource).to receive(:new).with(
129
- "http://auth.service.io/auth/admin/realms/valid-realm/clients/95b45037-3980-404c-ba12-784fa1baf2c2", rest_client_options).and_call_original
130
- @client_client.delete("95b45037-3980-404c-ba12-784fa1baf2c2")
131
- end
132
- end
133
- end
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(RestClient::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(RestClient::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(RestClient::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
+ rest_client_options = {timeout: 10}
86
+ allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
87
+
88
+ expect(RestClient::Resource).to receive(:new).with(
89
+ "http://auth.service.io/auth/admin/realms/valid-realm/clients", rest_client_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(RestClient::Resource).to receive(:put).and_return ''
106
+ allow_any_instance_of(RestClient::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(RestClient::Resource).to receive(:delete).and_return ''
123
+ end
124
+
125
+ it "passes rest client options" do
126
+ rest_client_options = {timeout: 10}
127
+ allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
128
+ expect(RestClient::Resource).to receive(:new).with(
129
+ "http://auth.service.io/auth/admin/realms/valid-realm/clients/95b45037-3980-404c-ba12-784fa1baf2c2", rest_client_options).and_call_original
130
+ @client_client.delete("95b45037-3980-404c-ba12-784fa1baf2c2")
131
+ end
132
+ end
133
+ end
@@ -1,82 +1,82 @@
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(RestClient::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
- rest_client_options = {timeout: 10}
36
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
37
-
38
- expect(RestClient::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
- rest_client_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(RestClient::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
- rest_client_options = {timeout: 10}
74
- allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
75
-
76
- expect(RestClient::Resource).to receive(:new).with(
77
- "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client", rest_client_options).and_call_original
78
-
79
- @client_role_mappings_client.save(role_list)
80
- end
81
- end
82
- end
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(RestClient::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
+ rest_client_options = {timeout: 10}
36
+ allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
37
+
38
+ expect(RestClient::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
+ rest_client_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(RestClient::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
+ rest_client_options = {timeout: 10}
74
+ allow_any_instance_of(KeycloakAdmin::Configuration).to receive(:rest_client_options).and_return rest_client_options
75
+
76
+ expect(RestClient::Resource).to receive(:new).with(
77
+ "http://auth.service.io/auth/admin/realms/valid-realm/users/test_user/role-mappings/clients/test_client", rest_client_options).and_call_original
78
+
79
+ @client_role_mappings_client.save(role_list)
80
+ end
81
+ end
82
+ end
@@ -1,28 +1,28 @@
1
- RSpec.describe KeycloakAdmin::Client do
2
- describe "#execute_http" do
3
- let(:realm_name) { "valid-realm" }
4
- before(:each) do
5
- @client = KeycloakAdmin::Client.new(KeycloakAdmin.config)
6
- end
7
-
8
- it "handles timeout" do
9
- expect do
10
- @client.execute_http do
11
- raise RestClient::Exceptions::OpenTimeout.new
12
- end
13
- end.to raise_error(RestClient::Exceptions::OpenTimeout)
14
- end
15
-
16
- it "handles response exception" do
17
- response = double
18
- allow(response).to receive(:code).and_return 500
19
- allow(response).to receive(:body).and_return "Server error"
20
-
21
- expect do
22
- @client.execute_http do
23
- raise RestClient::ExceptionWithResponse.new(response)
24
- end
25
- end.to raise_error("Keycloak: The request failed with response code 500 and message: Server error")
26
- end
27
- end
28
- end
1
+ RSpec.describe KeycloakAdmin::Client do
2
+ describe "#execute_http" do
3
+ let(:realm_name) { "valid-realm" }
4
+ before(:each) do
5
+ @client = KeycloakAdmin::Client.new(KeycloakAdmin.config)
6
+ end
7
+
8
+ it "handles timeout" do
9
+ expect do
10
+ @client.execute_http do
11
+ raise RestClient::Exceptions::OpenTimeout.new
12
+ end
13
+ end.to raise_error(RestClient::Exceptions::OpenTimeout)
14
+ end
15
+
16
+ it "handles response exception" do
17
+ response = double
18
+ allow(response).to receive(:code).and_return 500
19
+ allow(response).to receive(:body).and_return "Server error"
20
+
21
+ expect do
22
+ @client.execute_http do
23
+ raise RestClient::ExceptionWithResponse.new(response)
24
+ end
25
+ end.to raise_error("Keycloak: The request failed with response code 500 and message: Server error")
26
+ end
27
+ end
28
+ end
@@ -1,34 +1,34 @@
1
- RSpec.describe KeycloakAdmin::ConfigurableTokenClient do
2
- describe "#initialize" do
3
- context "when realm_name is defined" do
4
- let(:realm_name) { "master" }
5
- it "does not raise any error" do
6
- expect {
7
- KeycloakAdmin.realm(realm_name).configurable_token
8
- }.to_not raise_error
9
- end
10
- end
11
-
12
- context "when realm_name is not defined" do
13
- let(:realm_name) { nil }
14
- it "raises any error" do
15
- expect {
16
- KeycloakAdmin.realm(realm_name).configurable_token
17
- }.to raise_error(ArgumentError)
18
- end
19
- end
20
- end
21
-
22
- describe "#token_url" do
23
- let(:realm_name) { "valid-realm" }
24
- let(:user_id) { nil }
25
-
26
- before(:each) do
27
- @built_url = KeycloakAdmin.realm(realm_name).configurable_token.token_url
28
- end
29
-
30
- it "return a proper url with the realm name" do
31
- expect(@built_url).to eq "http://auth.service.io/auth/realms/valid-realm/configurable-token"
32
- end
33
- end
34
- end
1
+ RSpec.describe KeycloakAdmin::ConfigurableTokenClient do
2
+ describe "#initialize" do
3
+ context "when realm_name is defined" do
4
+ let(:realm_name) { "master" }
5
+ it "does not raise any error" do
6
+ expect {
7
+ KeycloakAdmin.realm(realm_name).configurable_token
8
+ }.to_not raise_error
9
+ end
10
+ end
11
+
12
+ context "when realm_name is not defined" do
13
+ let(:realm_name) { nil }
14
+ it "raises any error" do
15
+ expect {
16
+ KeycloakAdmin.realm(realm_name).configurable_token
17
+ }.to raise_error(ArgumentError)
18
+ end
19
+ end
20
+ end
21
+
22
+ describe "#token_url" do
23
+ let(:realm_name) { "valid-realm" }
24
+ let(:user_id) { nil }
25
+
26
+ before(:each) do
27
+ @built_url = KeycloakAdmin.realm(realm_name).configurable_token.token_url
28
+ end
29
+
30
+ it "return a proper url with the realm name" do
31
+ expect(@built_url).to eq "http://auth.service.io/auth/realms/valid-realm/configurable-token"
32
+ end
33
+ end
34
+ end