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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/README.md +54 -2
  4. data/keycloak-admin.gemspec +14 -5
  5. data/lib/keycloak-admin/client/client.rb +30 -11
  6. data/lib/keycloak-admin/client/client_authz_permission_client.rb +1 -1
  7. data/lib/keycloak-admin/client/client_authz_policy_client.rb +1 -1
  8. data/lib/keycloak-admin/client/client_authz_resource_client.rb +1 -1
  9. data/lib/keycloak-admin/client/client_authz_scope_client.rb +1 -1
  10. data/lib/keycloak-admin/client/configurable_token_client.rb +2 -1
  11. data/lib/keycloak-admin/client/group_client.rb +4 -6
  12. data/lib/keycloak-admin/client/organization_client.rb +7 -7
  13. data/lib/keycloak-admin/client/resource.rb +98 -0
  14. data/lib/keycloak-admin/client/response.rb +36 -0
  15. data/lib/keycloak-admin/client/role_mapper_client.rb +2 -1
  16. data/lib/keycloak-admin/client/user_client.rb +22 -11
  17. data/lib/keycloak-admin/configuration.rb +22 -0
  18. data/lib/keycloak-admin/error.rb +62 -0
  19. data/lib/keycloak-admin/version.rb +1 -1
  20. data/lib/keycloak-admin.rb +1 -0
  21. metadata +38 -53
  22. data/.github/workflows/Dockerfile +0 -24
  23. data/.github/workflows/ci.yml +0 -94
  24. data/.gitignore +0 -10
  25. data/.rspec +0 -2
  26. data/Dockerfile +0 -13
  27. data/Gemfile +0 -3
  28. data/Gemfile.lock +0 -52
  29. data/bin/console +0 -9
  30. data/spec/client/attack_detection_client_spec.rb +0 -102
  31. data/spec/client/client_authz_permission_client_spec.rb +0 -170
  32. data/spec/client/client_authz_policy_client_spec.rb +0 -170
  33. data/spec/client/client_authz_resource_client_spec.rb +0 -150
  34. data/spec/client/client_authz_scope_client_spec.rb +0 -134
  35. data/spec/client/client_client_spec.rb +0 -133
  36. data/spec/client/client_role_mappings_client_spec.rb +0 -82
  37. data/spec/client/client_scope_client_spec.rb +0 -220
  38. data/spec/client/client_scope_protocol_mapper_client_spec.rb +0 -230
  39. data/spec/client/client_spec.rb +0 -48
  40. data/spec/client/configurable_token_client_spec.rb +0 -34
  41. data/spec/client/group_client_spec.rb +0 -328
  42. data/spec/client/identity_provider_client_spec.rb +0 -92
  43. data/spec/client/organization_client_spec.rb +0 -595
  44. data/spec/client/realm_client_spec.rb +0 -155
  45. data/spec/client/role_client_spec.rb +0 -79
  46. data/spec/client/role_mapper_client_spec.rb +0 -113
  47. data/spec/client/token_client_spec.rb +0 -68
  48. data/spec/client/user_client_spec.rb +0 -418
  49. data/spec/configuration_spec.rb +0 -113
  50. data/spec/gemspec_spec.rb +0 -25
  51. data/spec/integration/client_authorization_spec.rb +0 -93
  52. data/spec/representation/attack_detection_representation_spec.rb +0 -16
  53. data/spec/representation/client_authz_permission_representation_spec.rb +0 -52
  54. data/spec/representation/client_authz_policy_representation_spec.rb +0 -47
  55. data/spec/representation/client_authz_resource_representation_spec.rb +0 -33
  56. data/spec/representation/client_authz_scope_representation_spec.rb +0 -19
  57. data/spec/representation/client_representation_spec.rb +0 -119
  58. data/spec/representation/client_scope_representation_spec.rb +0 -125
  59. data/spec/representation/credential_representation_spec.rb +0 -68
  60. data/spec/representation/group_representation_spec.rb +0 -22
  61. data/spec/representation/identity_provider_mapper_representation_spec.rb +0 -24
  62. data/spec/representation/identity_provider_representation_spec.rb +0 -113
  63. data/spec/representation/impersonation_representation_spec.rb +0 -163
  64. data/spec/representation/organization_representation_spec.rb +0 -64
  65. data/spec/representation/protocol_mapper_representation_spec.rb +0 -57
  66. data/spec/representation/role_representation_spec.rb +0 -37
  67. data/spec/representation/session_representation_spec.rb +0 -16
  68. data/spec/representation/user_representation_spec.rb +0 -15
  69. data/spec/resource/group_resource_spec.rb +0 -14
  70. data/spec/resource/user_resource_spec.rb +0 -14
  71. data/spec/spec_helper.rb +0 -29
@@ -0,0 +1,62 @@
1
+ module KeycloakAdmin
2
+ class Error < StandardError; end
3
+
4
+ # Raised when Keycloak answers with a non-2xx status.
5
+ #
6
+ # Callers can rescue the precise failure (KeycloakAdmin::NotFoundError), a whole family
7
+ # (KeycloakAdmin::ClientError for any 4xx) or every HTTP failure (KeycloakAdmin::ApiError),
8
+ # and read #status/#body off the exception rather than parsing the message.
9
+ class ApiError < Error
10
+ attr_reader :status, :body, :headers
11
+
12
+ def initialize(status, body, headers = {})
13
+ @status = status
14
+ @body = body
15
+ @headers = headers || {}
16
+ super("Keycloak: The request failed with response code #{status} and message: #{body}")
17
+ end
18
+
19
+ def self.from_response(response)
20
+ response ||= {}
21
+ status = response[:status]
22
+ error_class_for(status).new(status, response[:body], response[:headers])
23
+ end
24
+
25
+ def self.error_class_for(status)
26
+ case status
27
+ when 400 then BadRequestError
28
+ when 401 then UnauthorizedError
29
+ when 403 then ForbiddenError
30
+ when 404 then NotFoundError
31
+ when 409 then ConflictError
32
+ when 400..499 then ClientError
33
+ when 500..599 then ServerError
34
+ else ApiError
35
+ end
36
+ end
37
+ end
38
+
39
+ # Any 4xx: the request itself was rejected.
40
+ class ClientError < ApiError; end
41
+
42
+ class BadRequestError < ClientError; end
43
+ class UnauthorizedError < ClientError; end
44
+ class ForbiddenError < ClientError; end
45
+ class NotFoundError < ClientError; end
46
+ class ConflictError < ClientError; end
47
+
48
+ # Any 5xx: Keycloak accepted the request but failed to serve it.
49
+ class ServerError < ApiError; end
50
+
51
+ # Raised when a create call succeeds at the HTTP level but answers something other than
52
+ # 201 Created, leaving no Location header to read the new resource's id from.
53
+ class UnexpectedResponseError < Error
54
+ attr_reader :status, :reason_phrase
55
+
56
+ def initialize(status, reason_phrase)
57
+ @status = status
58
+ @reason_phrase = reason_phrase
59
+ super("Create method returned status #{reason_phrase} (Code: #{status}); expected status: Created (201)")
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module KeycloakAdmin
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "logger"
2
2
 
3
+ require_relative "keycloak-admin/error"
3
4
  require_relative "keycloak-admin/configuration"
4
5
  require_relative "keycloak-admin/client/response"
5
6
  require_relative "keycloak-admin/client/resource"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keycloak-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lorent Lempereur
@@ -85,6 +85,34 @@ dependencies:
85
85
  - - '='
86
86
  - !ruby/object:Gem::Version
87
87
  version: 12.0.0
88
+ - !ruby/object:Gem::Dependency
89
+ name: rake
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '13.0'
95
+ type: :development
96
+ prerelease: false
97
+ version_requirements: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '13.0'
102
+ - !ruby/object:Gem::Dependency
103
+ name: webmock
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '3.0'
109
+ type: :development
110
+ prerelease: false
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '3.0'
88
116
  description: Keycloak Admin REST API client written in Ruby
89
117
  email:
90
118
  - lorent.lempereur.dev@gmail.com
@@ -92,17 +120,9 @@ executables: []
92
120
  extensions: []
93
121
  extra_rdoc_files: []
94
122
  files:
95
- - ".github/workflows/Dockerfile"
96
- - ".github/workflows/ci.yml"
97
- - ".gitignore"
98
- - ".rspec"
99
123
  - CHANGELOG.md
100
- - Dockerfile
101
- - Gemfile
102
- - Gemfile.lock
103
124
  - MIT-LICENSE
104
125
  - README.md
105
- - bin/console
106
126
  - keycloak-admin.gemspec
107
127
  - lib/keycloak-admin.rb
108
128
  - lib/keycloak-admin/client/attack_detection_client.rb
@@ -121,11 +141,14 @@ files:
121
141
  - lib/keycloak-admin/client/identity_provider_client.rb
122
142
  - lib/keycloak-admin/client/organization_client.rb
123
143
  - lib/keycloak-admin/client/realm_client.rb
144
+ - lib/keycloak-admin/client/resource.rb
145
+ - lib/keycloak-admin/client/response.rb
124
146
  - lib/keycloak-admin/client/role_client.rb
125
147
  - lib/keycloak-admin/client/role_mapper_client.rb
126
148
  - lib/keycloak-admin/client/token_client.rb
127
149
  - lib/keycloak-admin/client/user_client.rb
128
150
  - lib/keycloak-admin/configuration.rb
151
+ - lib/keycloak-admin/error.rb
129
152
  - lib/keycloak-admin/representation/attack_detection_representation.rb
130
153
  - lib/keycloak-admin/representation/camel_json.rb
131
154
  - lib/keycloak-admin/representation/client_authz_permission_representation.rb
@@ -156,52 +179,14 @@ files:
156
179
  - lib/keycloak-admin/resource/group_resource.rb
157
180
  - lib/keycloak-admin/resource/user_resource.rb
158
181
  - lib/keycloak-admin/version.rb
159
- - spec/client/attack_detection_client_spec.rb
160
- - spec/client/client_authz_permission_client_spec.rb
161
- - spec/client/client_authz_policy_client_spec.rb
162
- - spec/client/client_authz_resource_client_spec.rb
163
- - spec/client/client_authz_scope_client_spec.rb
164
- - spec/client/client_client_spec.rb
165
- - spec/client/client_role_mappings_client_spec.rb
166
- - spec/client/client_scope_client_spec.rb
167
- - spec/client/client_scope_protocol_mapper_client_spec.rb
168
- - spec/client/client_spec.rb
169
- - spec/client/configurable_token_client_spec.rb
170
- - spec/client/group_client_spec.rb
171
- - spec/client/identity_provider_client_spec.rb
172
- - spec/client/organization_client_spec.rb
173
- - spec/client/realm_client_spec.rb
174
- - spec/client/role_client_spec.rb
175
- - spec/client/role_mapper_client_spec.rb
176
- - spec/client/token_client_spec.rb
177
- - spec/client/user_client_spec.rb
178
- - spec/configuration_spec.rb
179
- - spec/gemspec_spec.rb
180
- - spec/integration/client_authorization_spec.rb
181
- - spec/representation/attack_detection_representation_spec.rb
182
- - spec/representation/client_authz_permission_representation_spec.rb
183
- - spec/representation/client_authz_policy_representation_spec.rb
184
- - spec/representation/client_authz_resource_representation_spec.rb
185
- - spec/representation/client_authz_scope_representation_spec.rb
186
- - spec/representation/client_representation_spec.rb
187
- - spec/representation/client_scope_representation_spec.rb
188
- - spec/representation/credential_representation_spec.rb
189
- - spec/representation/group_representation_spec.rb
190
- - spec/representation/identity_provider_mapper_representation_spec.rb
191
- - spec/representation/identity_provider_representation_spec.rb
192
- - spec/representation/impersonation_representation_spec.rb
193
- - spec/representation/organization_representation_spec.rb
194
- - spec/representation/protocol_mapper_representation_spec.rb
195
- - spec/representation/role_representation_spec.rb
196
- - spec/representation/session_representation_spec.rb
197
- - spec/representation/user_representation_spec.rb
198
- - spec/resource/group_resource_spec.rb
199
- - spec/resource/user_resource_spec.rb
200
- - spec/spec_helper.rb
201
182
  homepage: https://github.com/looorent/keycloak-admin-ruby
202
183
  licenses:
203
184
  - MIT
204
- metadata: {}
185
+ metadata:
186
+ source_code_uri: https://github.com/looorent/keycloak-admin-ruby
187
+ changelog_uri: https://github.com/looorent/keycloak-admin-ruby/blob/main/CHANGELOG.md
188
+ bug_tracker_uri: https://github.com/looorent/keycloak-admin-ruby/issues
189
+ rubygems_mfa_required: 'true'
205
190
  rdoc_options: []
206
191
  require_paths:
207
192
  - lib
@@ -216,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
201
  - !ruby/object:Gem::Version
217
202
  version: '0'
218
203
  requirements: []
219
- rubygems_version: 4.0.17
204
+ rubygems_version: 3.6.9
220
205
  specification_version: 4
221
206
  summary: Keycloak Admin REST API client written in Ruby
222
207
  test_files: []
@@ -1,24 +0,0 @@
1
- ### Dockerfile for: tillawy/keycloak-github-actions
2
- ##
3
- ## To build & push
4
- # docker buildx build . --platform linux/amd64 -t tillawy/keycloak-github-actions:25.0.1
5
- # docker push tillawy/keycloak-github-actions:25.0.1
6
- #
7
- ## To Run Locally
8
- # docker run \
9
- # --rm \
10
- # -p 8080:8080 \
11
- # -e KEYCLOAK_ADMIN="admin" \
12
- # -e KEYCLOAK_ADMIN_PASSWORD="admin" \
13
- # -e KC_HOSTNAME="http://localhost:8080" \
14
- # -e KC_HOSTNAME_ADMIN="http://localhost:8080" \
15
- # -e KC_HTTP_ENABLED="true" \
16
- # -e KC_DB="dev-file" \
17
- # tillawy/keycloak-github-actions:25.0.1
18
-
19
- FROM quay.io/keycloak/keycloak:25.0.1
20
-
21
- ENTRYPOINT ["/opt/keycloak/bin/kc.sh"]
22
-
23
- CMD ["start-dev", "--hostname=http://localhost:8080" , "--hostname-admin=http://localhost:8080" , "--http-enabled=true", "--verbose"]
24
-
@@ -1,94 +0,0 @@
1
- # This workflow uses actions that are not certified by GitHub.
2
- # They are provided by a third-party and are governed by
3
- # separate terms of service, privacy policy, and support
4
- # documentation.
5
- # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
- # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
-
8
- name: Ruby
9
-
10
- on:
11
- push:
12
- branches: [ "main" ]
13
- pull_request:
14
- branches: [ "main" ]
15
-
16
- permissions:
17
- contents: read
18
-
19
- jobs:
20
- test:
21
- name: Ruby ${{ matrix.ruby-version }}
22
- runs-on: ubuntu-24.04
23
-
24
- strategy:
25
- fail-fast: false
26
- matrix:
27
- ruby-version: ['3.1', '3.2', '3.3', '3.4']
28
-
29
- steps:
30
- - name: Start Keycloak
31
- run: |
32
- docker run -d --name keycloak -p 8080:8080 \
33
- -e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
34
- -e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
35
- -e KC_HOSTNAME=http://localhost:8080 \
36
- -e KC_HOSTNAME_ADMIN=http://localhost:8080 \
37
- -e KC_HTTP_ENABLED=true \
38
- -e KC_DB=dev-file \
39
- quay.io/keycloak/keycloak:26.7.0 \
40
- start-dev
41
-
42
- - name: Wait for Keycloak to be ready
43
- run: |
44
- for i in $(seq 1 30); do
45
- if curl --silent --fail http://localhost:8080/realms/master > /dev/null; then
46
- echo "Keycloak is ready"
47
- exit 0
48
- fi
49
- sleep 5
50
- done
51
- echo "Keycloak did not become ready in time"
52
- docker logs keycloak
53
- exit 1
54
-
55
- - name: create realm
56
- run: |
57
- TOKEN=$(curl --silent --location --request POST "http://localhost:8080/realms/master/protocol/openid-connect/token" \
58
- --header 'Content-Type: application/x-www-form-urlencoded' \
59
- --data-urlencode 'grant_type=password' \
60
- --data-urlencode 'username=admin' \
61
- --data-urlencode 'password=admin' \
62
- --data-urlencode 'client_id=admin-cli' | jq -r '.access_token')
63
-
64
- curl --silent --show-error -L -X POST "http://localhost:8080/admin/realms" \
65
- --header "Content-Type: application/json" \
66
- --header "Authorization: Bearer ${TOKEN}" \
67
- --data '{"realm":"dummy","enabled":true}'
68
-
69
- curl --silent --show-error --request POST 'http://localhost:8080/admin/realms/dummy/clients' \
70
- --header 'Authorization: Bearer '$TOKEN \
71
- --header 'Content-Type: application/json' \
72
- --data-raw '{
73
- "clientId":"dummy-client",
74
- "enabled":true,
75
- "consentRequired": false,
76
- "attributes":{},
77
- "serviceAccountsEnabled": true,
78
- "protocol":"openid-connect",
79
- "publicClient":false,
80
- "authorizationServicesEnabled": true,
81
- "clientAuthenticatorType":"client-secret",
82
- "redirectUris":["http://localhost:8180/demo"]
83
- }'
84
-
85
- - uses: actions/checkout@v6
86
- - name: Set up Ruby
87
- uses: ruby/setup-ruby@v1
88
- with:
89
- ruby-version: ${{ matrix.ruby-version }}
90
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
91
- - name: Run tests
92
- run: bundle exec rspec
93
- env:
94
- GITHUB_ACTIONS: true
data/.gitignore DELETED
@@ -1,10 +0,0 @@
1
- .bundle/
2
- log/*.log
3
- pkg/
4
- test/dummy/db/*.sqlite3
5
- test/dummy/db/*.sqlite3-journal
6
- test/dummy/log/*.log
7
- test/dummy/tmp/
8
- *.gem
9
- .idea/
10
- .byebug_history
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/Dockerfile DELETED
@@ -1,13 +0,0 @@
1
- FROM ruby:3.3.12-slim-trixie
2
-
3
- RUN apt-get update -qq && apt-get install -y build-essential git ruby-dev && apt-get clean && \
4
- mkdir -p /usr/src/app/lib/keycloak-admin
5
- WORKDIR /usr/src/app
6
-
7
- COPY Gemfile /usr/src/app/
8
- COPY Gemfile.lock /usr/src/app/
9
- COPY keycloak-admin.gemspec /usr/src/app/
10
- COPY lib/keycloak-admin/version.rb /usr/src/app/lib/keycloak-admin/
11
- RUN bundle install
12
- COPY . /usr/src/app
13
- RUN bundle install
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,52 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- keycloak-admin (2.0.0)
5
- base64
6
- faraday (~> 2.0)
7
- http-cookie (~> 1.0, >= 1.0.3)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- base64 (0.3.0)
13
- byebug (12.0.0)
14
- diff-lcs (1.6.2)
15
- domain_name (0.6.20240107)
16
- faraday (2.14.3)
17
- faraday-net_http (>= 2.0, < 3.5)
18
- json
19
- logger
20
- faraday-net_http (3.4.4)
21
- net-http (~> 0.5)
22
- http-cookie (1.1.6)
23
- domain_name (~> 0.5)
24
- json (2.21.2)
25
- logger (1.7.0)
26
- net-http (0.9.1)
27
- uri (>= 0.11.1)
28
- rspec (3.13.2)
29
- rspec-core (~> 3.13.0)
30
- rspec-expectations (~> 3.13.0)
31
- rspec-mocks (~> 3.13.0)
32
- rspec-core (3.13.6)
33
- rspec-support (~> 3.13.0)
34
- rspec-expectations (3.13.5)
35
- diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.13.0)
37
- rspec-mocks (3.13.8)
38
- diff-lcs (>= 1.2.0, < 2.0)
39
- rspec-support (~> 3.13.0)
40
- rspec-support (3.13.7)
41
- uri (1.1.1)
42
-
43
- PLATFORMS
44
- ruby
45
-
46
- DEPENDENCIES
47
- byebug (= 12.0.0)
48
- keycloak-admin!
49
- rspec (= 3.13.2)
50
-
51
- BUNDLED WITH
52
- 2.6.9
data/bin/console DELETED
@@ -1,9 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- require "bundler/setup"
5
- require "keycloak-admin"
6
- require "byebug"
7
-
8
- require "irb"
9
- IRB.start
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe KeycloakAdmin::AttackDetectionClient do
4
- describe "#initialize" do
5
- let(:realm_name) { nil }
6
- before(:each) do
7
- @realm = KeycloakAdmin.realm(realm_name)
8
- end
9
- context "when realm_name is defined" do
10
- let(:realm_name) { "master" }
11
- it "does not raise any error" do
12
- expect { @realm.attack_detections }.to_not raise_error
13
- end
14
- end
15
-
16
- context "when realm_name is not defined" do
17
- it "raise argument error" do
18
- expect { @realm.attack_detections }.to raise_error(ArgumentError)
19
- end
20
- end
21
- end
22
-
23
- describe "#lock_status" do
24
- let(:realm_name) { "valid-realm" }
25
- before(:each) do
26
- @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
27
- stub_token_client
28
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"numFailures":1,"disabled":true, "lastFailure":123456}'
29
- end
30
-
31
- context "when user_id is defined" do
32
- let(:user_id) { "test_user_id" }
33
- it "returns lock details" do
34
- response = @attack_detections.lock_status(user_id)
35
- expect(response.num_failures).to eq 1
36
- end
37
- end
38
-
39
- context "when user_id is not defined" do
40
- let(:user_id) { nil }
41
- it "raise argument error" do
42
- expect { @attack_detections.lock_status(user_id) }.to raise_error(ArgumentError)
43
- end
44
- end
45
- end
46
-
47
- describe "#unlock_user" do
48
- let(:realm_name) { "valid-realm" }
49
- before(:each) do
50
- @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
51
- stub_token_client
52
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete)
53
- end
54
-
55
- context "when user_id is defined" do
56
- let(:user_id) { "test_user_id" }
57
- it "returns true" do
58
- expect(@attack_detections.unlock_user(user_id)).to be_truthy
59
- end
60
- end
61
-
62
- context "when user_id is not defined" do
63
- let(:user_id) { nil }
64
- it "raise argument error" do
65
- expect { @attack_detections.unlock_user(user_id) }.to raise_error(ArgumentError)
66
- end
67
- end
68
- end
69
-
70
- describe "#unlock_users" do
71
- let(:realm_name) { "valid-realm" }
72
- before(:each) do
73
- @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
74
- stub_token_client
75
- allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete)
76
- end
77
- it "returns true" do
78
- expect(@attack_detections.unlock_users).to be_truthy
79
- end
80
- end
81
-
82
- describe "#brute_force_url" do
83
- let(:realm_name) { "valid-realm" }
84
- let(:user_id) { nil }
85
- before(:each) do
86
- @attack_detections_url = KeycloakAdmin.realm(realm_name).attack_detections.brute_force_url(user_id)
87
- end
88
-
89
- context "when user_id is defined" do
90
- let(:user_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
91
- it "returns user specific url" do
92
- expect(@attack_detections_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/attack-detection/brute-force/users/#{user_id}"
93
- end
94
- end
95
-
96
- context "when user_id is not defined" do
97
- it "returns url without user" do
98
- expect(@attack_detections_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/attack-detection/brute-force/users"
99
- end
100
- end
101
- end
102
- end