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,28 +1,28 @@
|
|
|
1
|
-
module KeycloakAdmin
|
|
2
|
-
class BaseRoleContainingResource
|
|
3
|
-
attr_reader :resource_id
|
|
4
|
-
|
|
5
|
-
def initialize(configuration, realm_client, resource_id)
|
|
6
|
-
@configuration = configuration
|
|
7
|
-
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
|
|
8
|
-
@realm_client = realm_client
|
|
9
|
-
@resource_id = resource_id
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def resources_name
|
|
13
|
-
raise NotImplementedError.new("must override in subclass")
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def resource_url
|
|
17
|
-
"#{@realm_client.realm_admin_url}/#{resources_name}/#{@resource_id}"
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def client_role_mappings(client_id)
|
|
21
|
-
ClientRoleMappingsClient.new(@configuration, self, client_id)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def role_mapper
|
|
25
|
-
RoleMapperClient.new(@configuration, self)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
1
|
+
module KeycloakAdmin
|
|
2
|
+
class BaseRoleContainingResource
|
|
3
|
+
attr_reader :resource_id
|
|
4
|
+
|
|
5
|
+
def initialize(configuration, realm_client, resource_id)
|
|
6
|
+
@configuration = configuration
|
|
7
|
+
raise ArgumentError.new("realm must be defined") unless realm_client.name_defined?
|
|
8
|
+
@realm_client = realm_client
|
|
9
|
+
@resource_id = resource_id
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def resources_name
|
|
13
|
+
raise NotImplementedError.new("must override in subclass")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def resource_url
|
|
17
|
+
"#{@realm_client.realm_admin_url}/#{resources_name}/#{@resource_id}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def client_role_mappings(client_id)
|
|
21
|
+
ClientRoleMappingsClient.new(@configuration, self, client_id)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def role_mapper
|
|
25
|
+
RoleMapperClient.new(@configuration, self)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
module KeycloakAdmin
|
|
2
|
-
class GroupResource < BaseRoleContainingResource
|
|
3
|
-
def resources_name
|
|
4
|
-
"groups"
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def members(first:0, max:100)
|
|
8
|
-
@realm_client.groups.members(@resource_id, first, max)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
1
|
+
module KeycloakAdmin
|
|
2
|
+
class GroupResource < BaseRoleContainingResource
|
|
3
|
+
def resources_name
|
|
4
|
+
"groups"
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def members(first:0, max:100)
|
|
8
|
+
@realm_client.groups.members(@resource_id, first, max)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
module KeycloakAdmin
|
|
2
|
-
class UserResource < BaseRoleContainingResource
|
|
3
|
-
def resources_name
|
|
4
|
-
"users"
|
|
5
|
-
end
|
|
6
|
-
end
|
|
7
|
-
end
|
|
1
|
+
module KeycloakAdmin
|
|
2
|
+
class UserResource < BaseRoleContainingResource
|
|
3
|
+
def resources_name
|
|
4
|
+
"users"
|
|
5
|
+
end
|
|
6
|
+
end
|
|
7
|
+
end
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
module KeycloakAdmin
|
|
2
|
-
VERSION = "1.1.
|
|
3
|
-
end
|
|
1
|
+
module KeycloakAdmin
|
|
2
|
+
VERSION = "1.1.4"
|
|
3
|
+
end
|
data/lib/keycloak-admin.rb
CHANGED
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
require "logger"
|
|
2
|
-
|
|
3
|
-
require_relative "keycloak-admin/configuration"
|
|
4
|
-
require_relative "keycloak-admin/client/client"
|
|
5
|
-
require_relative "keycloak-admin/client/client_client"
|
|
6
|
-
require_relative "keycloak-admin/client/client_role_client"
|
|
7
|
-
require_relative "keycloak-admin/client/client_role_mappings_client"
|
|
8
|
-
require_relative "keycloak-admin/client/group_client"
|
|
9
|
-
require_relative "keycloak-admin/client/realm_client"
|
|
10
|
-
require_relative "keycloak-admin/client/role_client"
|
|
11
|
-
require_relative "keycloak-admin/client/role_mapper_client"
|
|
12
|
-
require_relative "keycloak-admin/client/token_client"
|
|
13
|
-
require_relative "keycloak-admin/client/user_client"
|
|
14
|
-
require_relative "keycloak-admin/client/identity_provider_client"
|
|
15
|
-
require_relative "keycloak-admin/client/configurable_token_client"
|
|
16
|
-
require_relative "keycloak-admin/client/attack_detection_client"
|
|
17
|
-
require_relative "keycloak-admin/client/client_authz_scope_client"
|
|
18
|
-
require_relative "keycloak-admin/client/client_authz_resource_client"
|
|
19
|
-
require_relative "keycloak-admin/client/client_authz_policy_client"
|
|
20
|
-
require_relative "keycloak-admin/client/client_authz_permission_client"
|
|
21
|
-
require_relative "keycloak-admin/representation/camel_json"
|
|
22
|
-
require_relative "keycloak-admin/representation/representation"
|
|
23
|
-
require_relative "keycloak-admin/representation/protocol_mapper_representation"
|
|
24
|
-
require_relative "keycloak-admin/representation/client_representation"
|
|
25
|
-
require_relative "keycloak-admin/representation/group_representation"
|
|
26
|
-
require_relative "keycloak-admin/representation/token_representation"
|
|
27
|
-
require_relative "keycloak-admin/representation/impersonation_redirection_representation"
|
|
28
|
-
require_relative "keycloak-admin/representation/impersonation_representation"
|
|
29
|
-
require_relative "keycloak-admin/representation/credential_representation"
|
|
30
|
-
require_relative "keycloak-admin/representation/realm_representation"
|
|
31
|
-
require_relative "keycloak-admin/representation/role_representation"
|
|
32
|
-
require_relative "keycloak-admin/representation/federated_identity_representation"
|
|
33
|
-
require_relative "keycloak-admin/representation/user_representation"
|
|
34
|
-
require_relative "keycloak-admin/representation/identity_provider_mapper_representation"
|
|
35
|
-
require_relative "keycloak-admin/representation/identity_provider_representation"
|
|
36
|
-
require_relative "keycloak-admin/representation/attack_detection_representation"
|
|
37
|
-
require_relative "keycloak-admin/representation/session_representation"
|
|
38
|
-
require_relative "keycloak-admin/representation/client_authz_scope_representation"
|
|
39
|
-
require_relative "keycloak-admin/representation/client_authz_resource_representation"
|
|
40
|
-
require_relative "keycloak-admin/representation/client_authz_policy_representation"
|
|
41
|
-
require_relative "keycloak-admin/representation/client_authz_policy_config_representation"
|
|
42
|
-
require_relative "keycloak-admin/representation/client_authz_permission_representation"
|
|
43
|
-
require_relative "keycloak-admin/resource/base_role_containing_resource"
|
|
44
|
-
require_relative "keycloak-admin/resource/group_resource"
|
|
45
|
-
require_relative "keycloak-admin/resource/user_resource"
|
|
46
|
-
|
|
47
|
-
module KeycloakAdmin
|
|
48
|
-
|
|
49
|
-
def self.configure
|
|
50
|
-
yield @configuration ||= KeycloakAdmin::Configuration.new
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
def self.config
|
|
54
|
-
@configuration
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def self.realm(realm_name)
|
|
58
|
-
create_client(@configuration, realm_name)
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def self.create_client(configuration, realm_name)
|
|
62
|
-
RealmClient.new(configuration, realm_name)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def self.logger
|
|
66
|
-
config.logger
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def self.load_configuration
|
|
70
|
-
configure do |config|
|
|
71
|
-
config.server_url = nil
|
|
72
|
-
config.server_domain = nil
|
|
73
|
-
config.client_realm_name = ""
|
|
74
|
-
config.client_id = "admin-cli"
|
|
75
|
-
config.logger = ::Logger.new(STDOUT)
|
|
76
|
-
config.use_service_account = true
|
|
77
|
-
config.username = nil
|
|
78
|
-
config.password = nil
|
|
79
|
-
config.rest_client_options = {}
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
load_configuration
|
|
84
|
-
end
|
|
1
|
+
require "logger"
|
|
2
|
+
|
|
3
|
+
require_relative "keycloak-admin/configuration"
|
|
4
|
+
require_relative "keycloak-admin/client/client"
|
|
5
|
+
require_relative "keycloak-admin/client/client_client"
|
|
6
|
+
require_relative "keycloak-admin/client/client_role_client"
|
|
7
|
+
require_relative "keycloak-admin/client/client_role_mappings_client"
|
|
8
|
+
require_relative "keycloak-admin/client/group_client"
|
|
9
|
+
require_relative "keycloak-admin/client/realm_client"
|
|
10
|
+
require_relative "keycloak-admin/client/role_client"
|
|
11
|
+
require_relative "keycloak-admin/client/role_mapper_client"
|
|
12
|
+
require_relative "keycloak-admin/client/token_client"
|
|
13
|
+
require_relative "keycloak-admin/client/user_client"
|
|
14
|
+
require_relative "keycloak-admin/client/identity_provider_client"
|
|
15
|
+
require_relative "keycloak-admin/client/configurable_token_client"
|
|
16
|
+
require_relative "keycloak-admin/client/attack_detection_client"
|
|
17
|
+
require_relative "keycloak-admin/client/client_authz_scope_client"
|
|
18
|
+
require_relative "keycloak-admin/client/client_authz_resource_client"
|
|
19
|
+
require_relative "keycloak-admin/client/client_authz_policy_client"
|
|
20
|
+
require_relative "keycloak-admin/client/client_authz_permission_client"
|
|
21
|
+
require_relative "keycloak-admin/representation/camel_json"
|
|
22
|
+
require_relative "keycloak-admin/representation/representation"
|
|
23
|
+
require_relative "keycloak-admin/representation/protocol_mapper_representation"
|
|
24
|
+
require_relative "keycloak-admin/representation/client_representation"
|
|
25
|
+
require_relative "keycloak-admin/representation/group_representation"
|
|
26
|
+
require_relative "keycloak-admin/representation/token_representation"
|
|
27
|
+
require_relative "keycloak-admin/representation/impersonation_redirection_representation"
|
|
28
|
+
require_relative "keycloak-admin/representation/impersonation_representation"
|
|
29
|
+
require_relative "keycloak-admin/representation/credential_representation"
|
|
30
|
+
require_relative "keycloak-admin/representation/realm_representation"
|
|
31
|
+
require_relative "keycloak-admin/representation/role_representation"
|
|
32
|
+
require_relative "keycloak-admin/representation/federated_identity_representation"
|
|
33
|
+
require_relative "keycloak-admin/representation/user_representation"
|
|
34
|
+
require_relative "keycloak-admin/representation/identity_provider_mapper_representation"
|
|
35
|
+
require_relative "keycloak-admin/representation/identity_provider_representation"
|
|
36
|
+
require_relative "keycloak-admin/representation/attack_detection_representation"
|
|
37
|
+
require_relative "keycloak-admin/representation/session_representation"
|
|
38
|
+
require_relative "keycloak-admin/representation/client_authz_scope_representation"
|
|
39
|
+
require_relative "keycloak-admin/representation/client_authz_resource_representation"
|
|
40
|
+
require_relative "keycloak-admin/representation/client_authz_policy_representation"
|
|
41
|
+
require_relative "keycloak-admin/representation/client_authz_policy_config_representation"
|
|
42
|
+
require_relative "keycloak-admin/representation/client_authz_permission_representation"
|
|
43
|
+
require_relative "keycloak-admin/resource/base_role_containing_resource"
|
|
44
|
+
require_relative "keycloak-admin/resource/group_resource"
|
|
45
|
+
require_relative "keycloak-admin/resource/user_resource"
|
|
46
|
+
|
|
47
|
+
module KeycloakAdmin
|
|
48
|
+
|
|
49
|
+
def self.configure
|
|
50
|
+
yield @configuration ||= KeycloakAdmin::Configuration.new
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.config
|
|
54
|
+
@configuration
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.realm(realm_name)
|
|
58
|
+
create_client(@configuration, realm_name)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.create_client(configuration, realm_name)
|
|
62
|
+
RealmClient.new(configuration, realm_name)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.logger
|
|
66
|
+
config.logger
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.load_configuration
|
|
70
|
+
configure do |config|
|
|
71
|
+
config.server_url = nil
|
|
72
|
+
config.server_domain = nil
|
|
73
|
+
config.client_realm_name = ""
|
|
74
|
+
config.client_id = "admin-cli"
|
|
75
|
+
config.logger = ::Logger.new(STDOUT)
|
|
76
|
+
config.use_service_account = true
|
|
77
|
+
config.username = nil
|
|
78
|
+
config.password = nil
|
|
79
|
+
config.rest_client_options = {}
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
load_configuration
|
|
84
|
+
end
|
|
@@ -1,102 +1,102 @@
|
|
|
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(RestClient::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(RestClient::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(RestClient::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
|
|
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(RestClient::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(RestClient::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(RestClient::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
|