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
data/spec/configuration_spec.rb
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::RealmClient do
|
|
2
|
-
|
|
3
|
-
let(:client_id) { "admin-cli" }
|
|
4
|
-
let(:client_secret) { "aaaaaaaa" }
|
|
5
|
-
let(:client_realm_name) { "master2" }
|
|
6
|
-
let(:use_service_account) { true }
|
|
7
|
-
let(:username) { "a" }
|
|
8
|
-
let(:password) { "b" }
|
|
9
|
-
let(:rest_client_options) { {timeout: 10 } }
|
|
10
|
-
|
|
11
|
-
before(:each) do
|
|
12
|
-
@configuration = KeycloakAdmin::Configuration.new
|
|
13
|
-
@configuration.server_url = "http://auth.service.io/auth"
|
|
14
|
-
@configuration.server_domain = "auth.service.io"
|
|
15
|
-
@configuration.client_id = client_id
|
|
16
|
-
@configuration.client_secret = client_secret
|
|
17
|
-
@configuration.client_realm_name = client_realm_name
|
|
18
|
-
@configuration.use_service_account = use_service_account
|
|
19
|
-
@configuration.username = username
|
|
20
|
-
@configuration.password = password
|
|
21
|
-
@configuration.rest_client_options = rest_client_options
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe "#headers_for_token_retrieval" do
|
|
25
|
-
before(:each) do
|
|
26
|
-
@headers = @configuration.headers_for_token_retrieval
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "when use_service_account is false" do
|
|
30
|
-
let(:use_service_account) { false }
|
|
31
|
-
it "returns an empty hash" do
|
|
32
|
-
expect(@headers).to be_empty
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
context "when use_service_account is true" do
|
|
37
|
-
let(:use_service_account) { true }
|
|
38
|
-
it "returns a single element" do
|
|
39
|
-
expect(@headers.size).to eq 1
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
it "returns the Authorization Key" do
|
|
43
|
-
expect(@headers.has_key?(:Authorization)).to be true
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "returns a Basic Authorization Key" do
|
|
47
|
-
expect(@headers[:Authorization]).to start_with "Basic"
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context "client_id='a' and client_secret='b'" do
|
|
51
|
-
let(:client_id) { "a" }
|
|
52
|
-
let(:client_secret) { "b" }
|
|
53
|
-
|
|
54
|
-
it "returns a Basic Authorization = 'Basic YTpi'" do
|
|
55
|
-
expect(@headers[:Authorization]).to eq "Basic YTpi"
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
context "client_id='365e3c66-fd0f-11e7-8be5-0ed5f89f718b' and client_secret='411e6f9a-fd0f-11e7-8be5-0ed5f89f718b'" do
|
|
60
|
-
let(:client_id) { "365e3c66-fd0f-11e7-8be5-0ed5f89f718b" }
|
|
61
|
-
let(:client_secret) { "411e6f9a-fd0f-11e7-8be5-0ed5f89f718b" }
|
|
62
|
-
|
|
63
|
-
it "returns a Basic Authorization = 'Basic MzY1ZTNjNjYtZmQwZi0xMWU3LThiZTUtMGVkNWY4OWY3MThiOjQxMWU2ZjlhLWZkMGYtMTFlNy04YmU1LTBlZDVmODlmNzE4Yg=='" do
|
|
64
|
-
expect(@headers[:Authorization]).to eq "Basic MzY1ZTNjNjYtZmQwZi0xMWU3LThiZTUtMGVkNWY4OWY3MThiOjQxMWU2ZjlhLWZkMGYtMTFlNy04YmU1LTBlZDVmODlmNzE4Yg=="
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe "#body_for_token_retrieval" do
|
|
72
|
-
before(:each) do
|
|
73
|
-
@body = @configuration.body_for_token_retrieval
|
|
74
|
-
end
|
|
75
|
-
context "when use_service_account is false" do
|
|
76
|
-
let(:use_service_account) { false }
|
|
77
|
-
it "returns a hash of 5 elements" do
|
|
78
|
-
expect(@body.size).to eq 5
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it "returns a hash containing the username" do
|
|
82
|
-
expect(@body[:username]).to eq username
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "returns a hash containing the password" do
|
|
86
|
-
expect(@body[:password]).to eq password
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "returns a hash containing the grant_type 'password'" do
|
|
90
|
-
expect(@body[:grant_type]).to eq "password"
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it "returns a hash containing the client_id" do
|
|
94
|
-
expect(@body[:client_id]).to eq client_id
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "returns a hash containing the client_secret" do
|
|
98
|
-
expect(@body[:client_secret]).to eq client_secret
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
context "when use_service_account is true" do
|
|
103
|
-
let(:use_service_account) { true }
|
|
104
|
-
it "returns a hash of 1 element" do
|
|
105
|
-
expect(@body.size).to eq 1
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
it "returns a hash containing the grant_type" do
|
|
109
|
-
expect(@body[:grant_type]).to eq "client_credentials"
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
1
|
+
RSpec.describe KeycloakAdmin::RealmClient do
|
|
2
|
+
|
|
3
|
+
let(:client_id) { "admin-cli" }
|
|
4
|
+
let(:client_secret) { "aaaaaaaa" }
|
|
5
|
+
let(:client_realm_name) { "master2" }
|
|
6
|
+
let(:use_service_account) { true }
|
|
7
|
+
let(:username) { "a" }
|
|
8
|
+
let(:password) { "b" }
|
|
9
|
+
let(:rest_client_options) { {timeout: 10 } }
|
|
10
|
+
|
|
11
|
+
before(:each) do
|
|
12
|
+
@configuration = KeycloakAdmin::Configuration.new
|
|
13
|
+
@configuration.server_url = "http://auth.service.io/auth"
|
|
14
|
+
@configuration.server_domain = "auth.service.io"
|
|
15
|
+
@configuration.client_id = client_id
|
|
16
|
+
@configuration.client_secret = client_secret
|
|
17
|
+
@configuration.client_realm_name = client_realm_name
|
|
18
|
+
@configuration.use_service_account = use_service_account
|
|
19
|
+
@configuration.username = username
|
|
20
|
+
@configuration.password = password
|
|
21
|
+
@configuration.rest_client_options = rest_client_options
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe "#headers_for_token_retrieval" do
|
|
25
|
+
before(:each) do
|
|
26
|
+
@headers = @configuration.headers_for_token_retrieval
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "when use_service_account is false" do
|
|
30
|
+
let(:use_service_account) { false }
|
|
31
|
+
it "returns an empty hash" do
|
|
32
|
+
expect(@headers).to be_empty
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "when use_service_account is true" do
|
|
37
|
+
let(:use_service_account) { true }
|
|
38
|
+
it "returns a single element" do
|
|
39
|
+
expect(@headers.size).to eq 1
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "returns the Authorization Key" do
|
|
43
|
+
expect(@headers.has_key?(:Authorization)).to be true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "returns a Basic Authorization Key" do
|
|
47
|
+
expect(@headers[:Authorization]).to start_with "Basic"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context "client_id='a' and client_secret='b'" do
|
|
51
|
+
let(:client_id) { "a" }
|
|
52
|
+
let(:client_secret) { "b" }
|
|
53
|
+
|
|
54
|
+
it "returns a Basic Authorization = 'Basic YTpi'" do
|
|
55
|
+
expect(@headers[:Authorization]).to eq "Basic YTpi"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
context "client_id='365e3c66-fd0f-11e7-8be5-0ed5f89f718b' and client_secret='411e6f9a-fd0f-11e7-8be5-0ed5f89f718b'" do
|
|
60
|
+
let(:client_id) { "365e3c66-fd0f-11e7-8be5-0ed5f89f718b" }
|
|
61
|
+
let(:client_secret) { "411e6f9a-fd0f-11e7-8be5-0ed5f89f718b" }
|
|
62
|
+
|
|
63
|
+
it "returns a Basic Authorization = 'Basic MzY1ZTNjNjYtZmQwZi0xMWU3LThiZTUtMGVkNWY4OWY3MThiOjQxMWU2ZjlhLWZkMGYtMTFlNy04YmU1LTBlZDVmODlmNzE4Yg=='" do
|
|
64
|
+
expect(@headers[:Authorization]).to eq "Basic MzY1ZTNjNjYtZmQwZi0xMWU3LThiZTUtMGVkNWY4OWY3MThiOjQxMWU2ZjlhLWZkMGYtMTFlNy04YmU1LTBlZDVmODlmNzE4Yg=="
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe "#body_for_token_retrieval" do
|
|
72
|
+
before(:each) do
|
|
73
|
+
@body = @configuration.body_for_token_retrieval
|
|
74
|
+
end
|
|
75
|
+
context "when use_service_account is false" do
|
|
76
|
+
let(:use_service_account) { false }
|
|
77
|
+
it "returns a hash of 5 elements" do
|
|
78
|
+
expect(@body.size).to eq 5
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "returns a hash containing the username" do
|
|
82
|
+
expect(@body[:username]).to eq username
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "returns a hash containing the password" do
|
|
86
|
+
expect(@body[:password]).to eq password
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "returns a hash containing the grant_type 'password'" do
|
|
90
|
+
expect(@body[:grant_type]).to eq "password"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "returns a hash containing the client_id" do
|
|
94
|
+
expect(@body[:client_id]).to eq client_id
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "returns a hash containing the client_secret" do
|
|
98
|
+
expect(@body[:client_secret]).to eq client_secret
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
context "when use_service_account is true" do
|
|
103
|
+
let(:use_service_account) { true }
|
|
104
|
+
it "returns a hash of 1 element" do
|
|
105
|
+
expect(@body.size).to eq 1
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
it "returns a hash containing the grant_type" do
|
|
109
|
+
expect(@body[:grant_type]).to eq "client_credentials"
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
@@ -1,95 +1,93 @@
|
|
|
1
|
-
RSpec.describe 'ClientAuthorization' do
|
|
2
|
-
|
|
3
|
-
before do
|
|
4
|
-
skip unless ENV["GITHUB_ACTIONS"]
|
|
5
|
-
|
|
6
|
-
KeycloakAdmin.configure do |config|
|
|
7
|
-
config.use_service_account = false
|
|
8
|
-
config.server_url = "http://localhost:8080/"
|
|
9
|
-
config.client_id = "admin-cli"
|
|
10
|
-
config.client_realm_name = "master"
|
|
11
|
-
config.username = "admin"
|
|
12
|
-
config.password = "admin"
|
|
13
|
-
config.rest_client_options = { timeout: 5, verify_ssl: false }
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
after do
|
|
18
|
-
configure
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
describe "ClientAuthorization Suite" do
|
|
22
|
-
it do
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
KeycloakAdmin.realm(realm_name).
|
|
30
|
-
|
|
31
|
-
expect(KeycloakAdmin.realm(realm_name).
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
expect(KeycloakAdmin.realm(realm_name).
|
|
72
|
-
|
|
73
|
-
expect(KeycloakAdmin.realm(realm_name).
|
|
74
|
-
|
|
75
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id,
|
|
76
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id,
|
|
77
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "
|
|
78
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "
|
|
79
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "
|
|
80
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(
|
|
81
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "
|
|
82
|
-
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
KeycloakAdmin.realm(realm_name).
|
|
87
|
-
KeycloakAdmin.realm(realm_name).
|
|
88
|
-
KeycloakAdmin.realm(realm_name).
|
|
89
|
-
KeycloakAdmin.realm(realm_name).
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
end
|
|
95
|
-
end
|
|
1
|
+
RSpec.describe 'ClientAuthorization' do
|
|
2
|
+
|
|
3
|
+
before(:each) do
|
|
4
|
+
skip("This test requires to be run in a Github action.") unless ENV["GITHUB_ACTIONS"]
|
|
5
|
+
|
|
6
|
+
KeycloakAdmin.configure do |config|
|
|
7
|
+
config.use_service_account = false
|
|
8
|
+
config.server_url = "http://localhost:8080/"
|
|
9
|
+
config.client_id = "admin-cli"
|
|
10
|
+
config.client_realm_name = "master"
|
|
11
|
+
config.username = "admin"
|
|
12
|
+
config.password = "admin"
|
|
13
|
+
config.rest_client_options = { timeout: 5, verify_ssl: false }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
after(:each) do
|
|
18
|
+
configure
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
describe "ClientAuthorization Suite" do
|
|
22
|
+
it do
|
|
23
|
+
realm_name = "dummy"
|
|
24
|
+
|
|
25
|
+
client = KeycloakAdmin.realm(realm_name).clients.find_by_client_id("dummy-client")
|
|
26
|
+
client.authorization_services_enabled = true
|
|
27
|
+
KeycloakAdmin.realm(realm_name).clients.update(client)
|
|
28
|
+
|
|
29
|
+
expect(KeycloakAdmin.realm(realm_name).authz_scopes(client.id).list.size).to eql(0)
|
|
30
|
+
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).list.size).to eql(1)
|
|
31
|
+
expect(KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').list.size).to eql(0)
|
|
32
|
+
|
|
33
|
+
realm_role = KeycloakAdmin.realm(realm_name).roles.get("default-roles-dummy")
|
|
34
|
+
|
|
35
|
+
scope_1 = KeycloakAdmin.realm(realm_name).authz_scopes(client.id).create!("POST_1", "POST 1 scope", "http://asdas")
|
|
36
|
+
scope_2 = KeycloakAdmin.realm(realm_name).authz_scopes(client.id).create!("POST_2", "POST 2 scope", "http://asdas")
|
|
37
|
+
expect(KeycloakAdmin.realm(realm_name).authz_scopes(client.id).search("POST").first.name).to eql("POST_1")
|
|
38
|
+
expect(KeycloakAdmin.realm(realm_name).authz_scopes(client.id).get(scope_1.id).name).to eql("POST_1")
|
|
39
|
+
|
|
40
|
+
resource = KeycloakAdmin.realm(realm_name).authz_resources(client.id).create!("Dummy Resource", "type", ["/asdf/*", "/tmp/"], true, "display_name", [], {"a": ["b", "c"]})
|
|
41
|
+
|
|
42
|
+
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).find_by("Dummy Resource", "", "", "", "").first.name).to eql("Dummy Resource")
|
|
43
|
+
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).find_by("", "type", "", "", "").first.name).to eql("Dummy Resource")
|
|
44
|
+
|
|
45
|
+
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).get(resource.id).scopes.count).to eql(0)
|
|
46
|
+
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).get(resource.id).uris.count).to eql(2)
|
|
47
|
+
KeycloakAdmin.realm(realm_name).authz_resources(client.id).update(resource.id,
|
|
48
|
+
{
|
|
49
|
+
"name": "Dummy Resource",
|
|
50
|
+
"type": "type",
|
|
51
|
+
"owner_managed_access": true,
|
|
52
|
+
"display_name": "display_name",
|
|
53
|
+
"attributes": {"a":["b","c"]},
|
|
54
|
+
"uris": [ "/asdf/*" , "/tmp/45" ],
|
|
55
|
+
"scopes":[
|
|
56
|
+
{name: scope_1.name},{name: scope_2.name}
|
|
57
|
+
],
|
|
58
|
+
"icon_uri": "https://icon.ico"
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
expect(KeycloakAdmin.realm(realm_name).authz_resources(client.id).get(resource.id).scopes.count).to eql(2)
|
|
63
|
+
|
|
64
|
+
policy = KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').create!("Policy 1", "description", "role", "POSITIVE", "UNANIMOUS", true, [{id: realm_role.id, required: true}])
|
|
65
|
+
expect(KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').find_by("Policy 1", "role").first.name).to eql("Policy 1")
|
|
66
|
+
expect(KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').get(policy.id).name).to eql("Policy 1")
|
|
67
|
+
scope_permission = KeycloakAdmin.realm(realm_name).authz_permissions(client.id, :scope).create!("Dummy Scope Permission", "scope description", "UNANIMOUS", "POSITIVE", [resource.id], [policy.id], [scope_1.id, scope_2.id], "")
|
|
68
|
+
resource_permission = KeycloakAdmin.realm(realm_name).authz_permissions(client.id, :resource).create!("Dummy Resource Permission", "resource description", "UNANIMOUS", "POSITIVE", [resource.id], [policy.id], nil, "")
|
|
69
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "", resource.id).list.size).to eql(2)
|
|
70
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "resource").get(resource_permission.id).name).to eql("Dummy Resource Permission")
|
|
71
|
+
expect(KeycloakAdmin.realm(realm_name).authz_scopes(client.id, resource.id).list.size).to eql(2)
|
|
72
|
+
|
|
73
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, 'scope').list.size).to eql(3)
|
|
74
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, 'resource').list.size).to eql(3)
|
|
75
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "resource").find_by(resource_permission.name, nil).first.name).to eql("Dummy Resource Permission")
|
|
76
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "resource").find_by(resource_permission.name, resource.id).first.name).to eql("Dummy Resource Permission")
|
|
77
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(scope_permission.name, resource.id).first.name).to eql("Dummy Scope Permission")
|
|
78
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(scope_permission.name, resource.id, "POST_1").first.name).to eql("Dummy Scope Permission")
|
|
79
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "resource").find_by(nil, resource.id).first.name).to eql("Dummy Resource Permission")
|
|
80
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(nil, resource.id).first.name).to eql("Dummy Scope Permission")
|
|
81
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(nil, resource.id, "POST_1").first.name).to eql("Dummy Scope Permission")
|
|
82
|
+
expect(KeycloakAdmin.realm(realm_name).authz_permissions(client.id, "scope").find_by(scope_permission.name, nil).first.name).to eql("Dummy Scope Permission")
|
|
83
|
+
|
|
84
|
+
KeycloakAdmin.realm(realm_name).authz_permissions(client.id, 'scope').delete(scope_permission.id)
|
|
85
|
+
KeycloakAdmin.realm(realm_name).authz_permissions(client.id, 'resource').delete(resource_permission.id)
|
|
86
|
+
KeycloakAdmin.realm(realm_name).authz_policies(client.id, 'role').delete(policy.id)
|
|
87
|
+
KeycloakAdmin.realm(realm_name).authz_resources(client.id).delete(resource.id)
|
|
88
|
+
KeycloakAdmin.realm(realm_name).authz_scopes(client.id).delete(scope_1.id)
|
|
89
|
+
KeycloakAdmin.realm(realm_name).authz_scopes(client.id).delete(scope_2.id)
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe KeycloakAdmin::AttackDetectionRepresentation do
|
|
4
|
-
describe '.from_hash' do
|
|
5
|
-
it 'converts json response to class structure' do
|
|
6
|
-
rep = described_class.from_hash({
|
|
7
|
-
'numFailures' => 2,
|
|
8
|
-
'disabled' => true,
|
|
9
|
-
'lastIPFailure' => 12345,
|
|
10
|
-
'last_failure' => 12345678
|
|
11
|
-
})
|
|
12
|
-
expect(rep.num_failures).to eq 2
|
|
13
|
-
expect(rep).to be_a described_class
|
|
14
|
-
end
|
|
15
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe KeycloakAdmin::AttackDetectionRepresentation do
|
|
4
|
+
describe '.from_hash' do
|
|
5
|
+
it 'converts json response to class structure' do
|
|
6
|
+
rep = described_class.from_hash({
|
|
7
|
+
'numFailures' => 2,
|
|
8
|
+
'disabled' => true,
|
|
9
|
+
'lastIPFailure' => 12345,
|
|
10
|
+
'last_failure' => 12345678
|
|
11
|
+
})
|
|
12
|
+
expect(rep.num_failures).to eq 2
|
|
13
|
+
expect(rep).to be_a described_class
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
16
|
end
|
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::ClientAuthzPermissionRepresentation do
|
|
2
|
-
describe '.from_hash, #resource based permission' do
|
|
3
|
-
it 'converts json response to class structure' do
|
|
4
|
-
rep = described_class.from_hash({
|
|
5
|
-
"id" => "e9e3bc49-fe11-4287-b6fc-fa8be4930ffa",
|
|
6
|
-
"resources" => ["4f55e984-d1ec-405c-a25c-1387f88acd5c"],
|
|
7
|
-
"policies" => ["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"],
|
|
8
|
-
"name" => "delme policy",
|
|
9
|
-
"description" => "Delme policy description",
|
|
10
|
-
"decisionStrategy" => "UNANIMOUS",
|
|
11
|
-
"resourceType" => ""
|
|
12
|
-
})
|
|
13
|
-
expect(rep.id).to eq "e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"
|
|
14
|
-
expect(rep.resources).to eq ["4f55e984-d1ec-405c-a25c-1387f88acd5c"]
|
|
15
|
-
expect(rep.policies).to eq ["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"]
|
|
16
|
-
expect(rep.name).to eq "delme policy"
|
|
17
|
-
expect(rep.description).to eq "Delme policy description"
|
|
18
|
-
expect(rep.decision_strategy).to eq "UNANIMOUS"
|
|
19
|
-
expect(rep.resource_type).to eq ""
|
|
20
|
-
expect(rep).to be_a described_class
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
describe '.from_hash, #scope based permission' do
|
|
25
|
-
it 'converts json response to class structure' do
|
|
26
|
-
rep = described_class.from_hash(
|
|
27
|
-
|
|
28
|
-
{ "id" => "4d762e5d-bf3d-4641-8f94-97e8a1869d1d",
|
|
29
|
-
"name" => "permission name",
|
|
30
|
-
"description" => "permission description",
|
|
31
|
-
"type" => "scope",
|
|
32
|
-
"policies" => ["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"],
|
|
33
|
-
"resources" => ["4f55e984-d1ec-405c-a25c-1387f88acd5c"],
|
|
34
|
-
"scopes" => ["7c4809c5-33b6-4668-a318-19b302214d20"],
|
|
35
|
-
"logic" => "POSITIVE",
|
|
36
|
-
"decisionStrategy" => "UNANIMOUS"
|
|
37
|
-
})
|
|
38
|
-
expect(rep.id).to eq "4d762e5d-bf3d-4641-8f94-97e8a1869d1d"
|
|
39
|
-
expect(rep.resources).to eq ["4f55e984-d1ec-405c-a25c-1387f88acd5c"]
|
|
40
|
-
expect(rep.policies).to eq ["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"]
|
|
41
|
-
expect(rep.scopes).to eq ["7c4809c5-33b6-4668-a318-19b302214d20"]
|
|
42
|
-
expect(rep.name).to eq "permission name"
|
|
43
|
-
expect(rep.description).to eq "permission description"
|
|
44
|
-
expect(rep.decision_strategy).to eq "UNANIMOUS"
|
|
45
|
-
expect(rep.logic).to eq "POSITIVE"
|
|
46
|
-
expect(rep.type).to eq "scope"
|
|
47
|
-
expect(rep.resource_type).to eq nil
|
|
48
|
-
expect(rep).to be_a described_class
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
end
|
|
1
|
+
RSpec.describe KeycloakAdmin::ClientAuthzPermissionRepresentation do
|
|
2
|
+
describe '.from_hash, #resource based permission' do
|
|
3
|
+
it 'converts json response to class structure' do
|
|
4
|
+
rep = described_class.from_hash({
|
|
5
|
+
"id" => "e9e3bc49-fe11-4287-b6fc-fa8be4930ffa",
|
|
6
|
+
"resources" => ["4f55e984-d1ec-405c-a25c-1387f88acd5c"],
|
|
7
|
+
"policies" => ["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"],
|
|
8
|
+
"name" => "delme policy",
|
|
9
|
+
"description" => "Delme policy description",
|
|
10
|
+
"decisionStrategy" => "UNANIMOUS",
|
|
11
|
+
"resourceType" => ""
|
|
12
|
+
})
|
|
13
|
+
expect(rep.id).to eq "e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"
|
|
14
|
+
expect(rep.resources).to eq ["4f55e984-d1ec-405c-a25c-1387f88acd5c"]
|
|
15
|
+
expect(rep.policies).to eq ["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"]
|
|
16
|
+
expect(rep.name).to eq "delme policy"
|
|
17
|
+
expect(rep.description).to eq "Delme policy description"
|
|
18
|
+
expect(rep.decision_strategy).to eq "UNANIMOUS"
|
|
19
|
+
expect(rep.resource_type).to eq ""
|
|
20
|
+
expect(rep).to be_a described_class
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe '.from_hash, #scope based permission' do
|
|
25
|
+
it 'converts json response to class structure' do
|
|
26
|
+
rep = described_class.from_hash(
|
|
27
|
+
|
|
28
|
+
{ "id" => "4d762e5d-bf3d-4641-8f94-97e8a1869d1d",
|
|
29
|
+
"name" => "permission name",
|
|
30
|
+
"description" => "permission description",
|
|
31
|
+
"type" => "scope",
|
|
32
|
+
"policies" => ["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"],
|
|
33
|
+
"resources" => ["4f55e984-d1ec-405c-a25c-1387f88acd5c"],
|
|
34
|
+
"scopes" => ["7c4809c5-33b6-4668-a318-19b302214d20"],
|
|
35
|
+
"logic" => "POSITIVE",
|
|
36
|
+
"decisionStrategy" => "UNANIMOUS"
|
|
37
|
+
})
|
|
38
|
+
expect(rep.id).to eq "4d762e5d-bf3d-4641-8f94-97e8a1869d1d"
|
|
39
|
+
expect(rep.resources).to eq ["4f55e984-d1ec-405c-a25c-1387f88acd5c"]
|
|
40
|
+
expect(rep.policies).to eq ["e9e3bc49-fe11-4287-b6fc-fa8be4930ffa"]
|
|
41
|
+
expect(rep.scopes).to eq ["7c4809c5-33b6-4668-a318-19b302214d20"]
|
|
42
|
+
expect(rep.name).to eq "permission name"
|
|
43
|
+
expect(rep.description).to eq "permission description"
|
|
44
|
+
expect(rep.decision_strategy).to eq "UNANIMOUS"
|
|
45
|
+
expect(rep.logic).to eq "POSITIVE"
|
|
46
|
+
expect(rep.type).to eq "scope"
|
|
47
|
+
expect(rep.resource_type).to eq nil
|
|
48
|
+
expect(rep).to be_a described_class
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
end
|