keycloak-admin 2.0.1 → 2.0.3
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/CHANGELOG.md +40 -0
- data/MIT-LICENSE +18 -17
- data/README.md +102 -5
- data/keycloak-admin.gemspec +15 -6
- data/lib/keycloak-admin/client/attack_detection_client.rb +2 -1
- data/lib/keycloak-admin/client/client.rb +36 -11
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +5 -4
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +4 -3
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +15 -11
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +5 -4
- data/lib/keycloak-admin/client/client_client.rb +6 -2
- data/lib/keycloak-admin/client/client_role_client.rb +2 -1
- data/lib/keycloak-admin/client/client_role_mappings_client.rb +3 -2
- data/lib/keycloak-admin/client/client_scope_client.rb +2 -1
- data/lib/keycloak-admin/client/client_scope_protocol_mapper_client.rb +3 -2
- data/lib/keycloak-admin/client/configurable_token_client.rb +2 -1
- data/lib/keycloak-admin/client/group_client.rb +15 -9
- data/lib/keycloak-admin/client/identity_provider_client.rb +2 -1
- data/lib/keycloak-admin/client/organization_client.rb +12 -11
- data/lib/keycloak-admin/client/realm_client.rb +3 -2
- data/lib/keycloak-admin/client/resource.rb +8 -6
- data/lib/keycloak-admin/client/response.rb +1 -0
- data/lib/keycloak-admin/client/role_client.rb +3 -6
- data/lib/keycloak-admin/client/role_mapper_client.rb +2 -1
- data/lib/keycloak-admin/client/token_client.rb +1 -0
- data/lib/keycloak-admin/client/user_client.rb +70 -47
- data/lib/keycloak-admin/configuration.rb +37 -2
- data/lib/keycloak-admin/error.rb +63 -0
- data/lib/keycloak-admin/path_encoding.rb +24 -0
- data/lib/keycloak-admin/representation/attack_detection_representation.rb +1 -0
- data/lib/keycloak-admin/representation/camel_json.rb +7 -3
- data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +1 -0
- data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +1 -0
- data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +1 -0
- data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +1 -0
- data/lib/keycloak-admin/representation/client_representation.rb +4 -5
- data/lib/keycloak-admin/representation/client_scope_representation.rb +1 -0
- data/lib/keycloak-admin/representation/credential_representation.rb +1 -0
- data/lib/keycloak-admin/representation/federated_identity_representation.rb +1 -0
- data/lib/keycloak-admin/representation/group_representation.rb +1 -0
- data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +1 -0
- data/lib/keycloak-admin/representation/identity_provider_representation.rb +1 -0
- data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +1 -0
- data/lib/keycloak-admin/representation/impersonation_representation.rb +1 -0
- data/lib/keycloak-admin/representation/member_representation.rb +1 -0
- data/lib/keycloak-admin/representation/organization_domain_representation.rb +1 -0
- data/lib/keycloak-admin/representation/organization_representation.rb +1 -1
- data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +1 -0
- data/lib/keycloak-admin/representation/realm_representation.rb +1 -0
- data/lib/keycloak-admin/representation/representation.rb +7 -5
- data/lib/keycloak-admin/representation/role_representation.rb +2 -1
- data/lib/keycloak-admin/representation/session_representation.rb +2 -1
- data/lib/keycloak-admin/representation/token_representation.rb +1 -0
- data/lib/keycloak-admin/representation/user_representation.rb +1 -0
- data/lib/keycloak-admin/resource/base_role_containing_resource.rb +4 -1
- data/lib/keycloak-admin/resource/group_resource.rb +1 -0
- data/lib/keycloak-admin/resource/user_resource.rb +1 -0
- data/lib/keycloak-admin/version.rb +2 -1
- data/lib/keycloak-admin.rb +4 -0
- metadata +36 -56
- data/.github/workflows/Dockerfile +0 -24
- data/.github/workflows/ci.yml +0 -94
- data/.github/workflows/release.yml +0 -112
- data/.gitignore +0 -10
- data/.rspec +0 -2
- data/Dockerfile +0 -13
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -54
- data/Rakefile +0 -6
- data/bin/console +0 -9
- data/spec/client/attack_detection_client_spec.rb +0 -102
- data/spec/client/client_authz_permission_client_spec.rb +0 -170
- data/spec/client/client_authz_policy_client_spec.rb +0 -170
- data/spec/client/client_authz_resource_client_spec.rb +0 -150
- data/spec/client/client_authz_scope_client_spec.rb +0 -134
- data/spec/client/client_client_spec.rb +0 -133
- data/spec/client/client_role_mappings_client_spec.rb +0 -83
- data/spec/client/client_scope_client_spec.rb +0 -220
- data/spec/client/client_scope_protocol_mapper_client_spec.rb +0 -230
- data/spec/client/client_spec.rb +0 -101
- data/spec/client/configurable_token_client_spec.rb +0 -34
- data/spec/client/group_client_spec.rb +0 -328
- data/spec/client/identity_provider_client_spec.rb +0 -92
- data/spec/client/organization_client_spec.rb +0 -595
- data/spec/client/realm_client_spec.rb +0 -155
- data/spec/client/resource_spec.rb +0 -223
- data/spec/client/response_spec.rb +0 -68
- data/spec/client/role_client_spec.rb +0 -79
- data/spec/client/role_mapper_client_spec.rb +0 -113
- data/spec/client/token_client_spec.rb +0 -68
- data/spec/client/user_client_spec.rb +0 -418
- data/spec/configuration_spec.rb +0 -150
- data/spec/gemspec_spec.rb +0 -25
- data/spec/integration/client_authorization_spec.rb +0 -93
- data/spec/representation/attack_detection_representation_spec.rb +0 -16
- data/spec/representation/client_authz_permission_representation_spec.rb +0 -52
- data/spec/representation/client_authz_policy_representation_spec.rb +0 -47
- data/spec/representation/client_authz_resource_representation_spec.rb +0 -33
- data/spec/representation/client_authz_scope_representation_spec.rb +0 -19
- data/spec/representation/client_representation_spec.rb +0 -119
- data/spec/representation/client_scope_representation_spec.rb +0 -125
- data/spec/representation/credential_representation_spec.rb +0 -68
- data/spec/representation/group_representation_spec.rb +0 -22
- data/spec/representation/identity_provider_mapper_representation_spec.rb +0 -24
- data/spec/representation/identity_provider_representation_spec.rb +0 -113
- data/spec/representation/impersonation_representation_spec.rb +0 -163
- data/spec/representation/organization_representation_spec.rb +0 -64
- data/spec/representation/protocol_mapper_representation_spec.rb +0 -57
- data/spec/representation/role_representation_spec.rb +0 -37
- data/spec/representation/session_representation_spec.rb +0 -16
- data/spec/representation/user_representation_spec.rb +0 -15
- data/spec/resource/group_resource_spec.rb +0 -14
- data/spec/resource/user_resource_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -36
data/.rspec
DELETED
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
data/Gemfile.lock
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
keycloak-admin (2.0.1)
|
|
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
|
-
rake (13.4.2)
|
|
29
|
-
rspec (3.13.2)
|
|
30
|
-
rspec-core (~> 3.13.0)
|
|
31
|
-
rspec-expectations (~> 3.13.0)
|
|
32
|
-
rspec-mocks (~> 3.13.0)
|
|
33
|
-
rspec-core (3.13.6)
|
|
34
|
-
rspec-support (~> 3.13.0)
|
|
35
|
-
rspec-expectations (3.13.5)
|
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
|
-
rspec-support (~> 3.13.0)
|
|
38
|
-
rspec-mocks (3.13.8)
|
|
39
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
|
40
|
-
rspec-support (~> 3.13.0)
|
|
41
|
-
rspec-support (3.13.7)
|
|
42
|
-
uri (1.1.1)
|
|
43
|
-
|
|
44
|
-
PLATFORMS
|
|
45
|
-
ruby
|
|
46
|
-
|
|
47
|
-
DEPENDENCIES
|
|
48
|
-
byebug (= 12.0.0)
|
|
49
|
-
keycloak-admin!
|
|
50
|
-
rake (>= 13.0)
|
|
51
|
-
rspec (= 3.13.2)
|
|
52
|
-
|
|
53
|
-
BUNDLED WITH
|
|
54
|
-
2.6.9
|
data/Rakefile
DELETED
data/bin/console
DELETED
|
@@ -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
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::ClientAuthzPermissionClient do
|
|
2
|
-
|
|
3
|
-
describe "#initialize" do
|
|
4
|
-
let(:realm_name) { nil }
|
|
5
|
-
let(:type) { :scope }
|
|
6
|
-
before(:each) do
|
|
7
|
-
@realm = KeycloakAdmin.realm(realm_name)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "when realm_name is defined" do
|
|
11
|
-
let(:realm_name) { "master" }
|
|
12
|
-
it "does not raise any error" do
|
|
13
|
-
expect {
|
|
14
|
-
@realm.authz_permissions("", type)
|
|
15
|
-
}.to_not raise_error
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context "when realm_name is not defined" do
|
|
20
|
-
let(:realm_name) { nil }
|
|
21
|
-
it "raises any error" do
|
|
22
|
-
expect {
|
|
23
|
-
@realm.authz_permissions("", type)
|
|
24
|
-
}.to raise_error(ArgumentError)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context "when type is bad value" do
|
|
29
|
-
let(:realm_name) { "master" }
|
|
30
|
-
let(:type) { "bad-type" }
|
|
31
|
-
it "does not raise any error" do
|
|
32
|
-
expect {
|
|
33
|
-
@realm.authz_permissions("", type)
|
|
34
|
-
}.to raise_error(ArgumentError)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe '#delete' do
|
|
40
|
-
let(:realm_name) { "valid-realm" }
|
|
41
|
-
let(:client_id) { "valid-client-id" }
|
|
42
|
-
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource") }
|
|
43
|
-
before(:each) do
|
|
44
|
-
stub_token_client
|
|
45
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return 'true'
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it "deletes a permission" do
|
|
49
|
-
expect(client_authz_permission.delete("valid-permission-id")).to be_truthy
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe '#find_by' do
|
|
54
|
-
let(:realm_name) { "valid-realm" }
|
|
55
|
-
let(:client_id) { "valid-client-id" }
|
|
56
|
-
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource") }
|
|
57
|
-
before(:each) do
|
|
58
|
-
stub_token_client
|
|
59
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"245ce612-ccdc-4426-8ea7-e0e29a718033","name":"Default Permission","description":"A permission that applies to the default resource type","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"urn:dummy-client:resources:default"},{"id":"06a21e38-4e92-466d-8647-ffcd9c7b51c3","name":"delme policy","description":"delme polidy ","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"asdfasdf"}]'
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "finds permissions" do
|
|
63
|
-
response = client_authz_permission.find_by("name", "resource", "scope")
|
|
64
|
-
expect(response[0].id).to eql "245ce612-ccdc-4426-8ea7-e0e29a718033"
|
|
65
|
-
expect(response[1].id).to eql "06a21e38-4e92-466d-8647-ffcd9c7b51c3"
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
describe '#create!' do
|
|
70
|
-
let(:realm_name) { "valid-realm" }
|
|
71
|
-
let(:client_id) { "valid-client-id" }
|
|
72
|
-
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource") }
|
|
73
|
-
before(:each) do
|
|
74
|
-
stub_token_client
|
|
75
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return '{"id":"245ce612-ccdc-4426-8ea7-e0e29a718033","name":"Default Permission","description":"A permission that applies to the default resource type","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"urn:dummy-client:resources:default"}'
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "creates a permission" do
|
|
79
|
-
response = client_authz_permission.create!("name", "description", "UNANIMOUS", "POSITIVE", [], [], [], "resource")
|
|
80
|
-
expect(response.id).to eql "245ce612-ccdc-4426-8ea7-e0e29a718033"
|
|
81
|
-
expect(response.name).to eql "Default Permission"
|
|
82
|
-
expect(response.description).to eql "A permission that applies to the default resource type"
|
|
83
|
-
expect(response.logic).to eql "POSITIVE"
|
|
84
|
-
expect(response.decision_strategy).to eql "UNANIMOUS"
|
|
85
|
-
expect(response.resource_type).to eql "urn:dummy-client:resources:default"
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe '#list' do
|
|
90
|
-
let(:realm_name) { "valid-realm" }
|
|
91
|
-
let(:client_id) { "valid-client-id" }
|
|
92
|
-
before(:each) do
|
|
93
|
-
@client_authz_permission = KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource")
|
|
94
|
-
stub_token_client
|
|
95
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"245ce612-ccdc-4426-8ea7-e0e29a718033","name":"Default Permission","description":"A permission that applies to the default resource type","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"urn:dummy-client:resources:default"},{"id":"06a21e38-4e92-466d-8647-ffcd9c7b51c3","name":"delme policy","description":"delme polidy ","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"asdfasdf"}]'
|
|
96
|
-
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "returns list of authz permissions" do
|
|
100
|
-
response = @client_authz_permission.list
|
|
101
|
-
expect(response.size).to eq 2
|
|
102
|
-
expect(response[0].id).to eq "245ce612-ccdc-4426-8ea7-e0e29a718033"
|
|
103
|
-
expect(response[0].name).to eq "Default Permission"
|
|
104
|
-
expect(response[0].description).to eq "A permission that applies to the default resource type"
|
|
105
|
-
expect(response[0].logic).to eq "POSITIVE"
|
|
106
|
-
expect(response[0].decision_strategy).to eq "UNANIMOUS"
|
|
107
|
-
expect(response[0].resource_type).to eq "urn:dummy-client:resources:default"
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
describe '#get' do
|
|
112
|
-
let(:realm_name) { "valid-realm" }
|
|
113
|
-
let(:client_id) { "valid-client-id" }
|
|
114
|
-
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource") }
|
|
115
|
-
before(:each) do
|
|
116
|
-
stub_token_client
|
|
117
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"245ce612-ccdc-4426-8ea7-e0e29a718033","name":"Default Permission","description":"A permission that applies to the default resource type","type":"resource","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","resourceType":"urn:dummy-client:resources:default"}'
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it "gets a permission" do
|
|
121
|
-
response = client_authz_permission.get("245ce612-ccdc-4426-8ea7-e0e29a718033")
|
|
122
|
-
expect(response.id).to eql "245ce612-ccdc-4426-8ea7-e0e29a718033"
|
|
123
|
-
expect(response.name).to eql "Default Permission"
|
|
124
|
-
expect(response.description).to eql "A permission that applies to the default resource type"
|
|
125
|
-
expect(response.logic).to eql "POSITIVE"
|
|
126
|
-
expect(response.decision_strategy).to eql "UNANIMOUS"
|
|
127
|
-
expect(response.resource_type).to eql "urn:dummy-client:resources:default"
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
describe '#authz_permission_url' do
|
|
132
|
-
let(:realm_name) { "valid-realm" }
|
|
133
|
-
let(:client_id) { "valid-client-id" }
|
|
134
|
-
let(:resource_id){ "valid-resource-id" }
|
|
135
|
-
let(:type){ "resource" }
|
|
136
|
-
let(:client_authz_permission) { KeycloakAdmin.realm(realm_name).authz_permissions(client_id, type, resource_id) }
|
|
137
|
-
context 'when resource_id is nil' do
|
|
138
|
-
it "return a proper url" do
|
|
139
|
-
expect(client_authz_permission.authz_permission_url(client_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/permission/"
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
context 'when resource_id is not nil' do
|
|
143
|
-
it "return a proper url" do
|
|
144
|
-
expect(client_authz_permission.authz_permission_url(client_id, resource_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/resource/valid-resource-id/permissions"
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
context 'when id is not nil' do
|
|
148
|
-
it "return a proper url" do
|
|
149
|
-
expect(client_authz_permission.authz_permission_url(client_id, nil, :resource, "valid-permission-id")).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/permission/resource/valid-permission-id"
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
context 'when resource_id and id are nil' do
|
|
153
|
-
it "return a proper url" do
|
|
154
|
-
expect(client_authz_permission.authz_permission_url(client_id, nil, :resource)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/permission/resource"
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
describe '#authz_permission_url' do
|
|
160
|
-
let(:realm_name) { "valid-realm" }
|
|
161
|
-
let(:client_id) { "valid-client-id" }
|
|
162
|
-
before(:each) do
|
|
163
|
-
@client_authz_permission = KeycloakAdmin.realm(realm_name).authz_permissions(client_id, "resource")
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
it "return a proper url" do
|
|
167
|
-
expect(@client_authz_permission.authz_permission_url(client_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/permission/"
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
RSpec.describe KeycloakAdmin::ClientAuthzPolicyClient do
|
|
2
|
-
|
|
3
|
-
describe '#initialize' do
|
|
4
|
-
let(:realm_name) { nil }
|
|
5
|
-
let(:type) { :role }
|
|
6
|
-
before(:each) do
|
|
7
|
-
@realm = KeycloakAdmin.realm(realm_name)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
context "when realm_name is defined" do
|
|
11
|
-
let(:realm_name) { "master" }
|
|
12
|
-
it "does not raise any error" do
|
|
13
|
-
expect {
|
|
14
|
-
@realm.authz_policies("", type)
|
|
15
|
-
}.to_not raise_error
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context "when realm_name is not defined" do
|
|
20
|
-
let(:realm_name) { nil }
|
|
21
|
-
it "raises any error" do
|
|
22
|
-
expect {
|
|
23
|
-
@realm.authz_policies("", type)
|
|
24
|
-
}.to raise_error(ArgumentError)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context "when type is bad value" do
|
|
29
|
-
let(:realm_name) { "master" }
|
|
30
|
-
let(:type) { "bad-type" }
|
|
31
|
-
it "does not raise any error" do
|
|
32
|
-
expect {
|
|
33
|
-
@realm.authz_policies("", type)
|
|
34
|
-
}.to raise_error(ArgumentError)
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe '#create!' do
|
|
40
|
-
let(:realm_name) { "valid-realm" }
|
|
41
|
-
let(:client_id) { "valid-client-id" }
|
|
42
|
-
let(:type) { :role }
|
|
43
|
-
let(:name) { "policy name" }
|
|
44
|
-
let(:description) { "policy description" }
|
|
45
|
-
let(:logic) { "POSITIVE" }
|
|
46
|
-
let(:decision_strategy) { "UNANIMOUS" }
|
|
47
|
-
let(:fetch_roles) { true }
|
|
48
|
-
let(:config) { { roles: [{ id: "1d305dbe-6379-4900-8e63-96541006160a", required: false }] } }
|
|
49
|
-
let(:client_authz_policy){ KeycloakAdmin.realm(realm_name).authz_policies(client_id, type) }
|
|
50
|
-
|
|
51
|
-
before(:each) do
|
|
52
|
-
stub_token_client
|
|
53
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:post).and_return '{"id":"234f6f33-ef03-4f3f-a8c0-ad7bca27b720","name":"policy name","description":"policy description","type":"role","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","config":{"roles":"[{\"id\":\"1d305dbe-6379-4900-8e63-96541006160a\",\"required\":false}]"}}'
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "creates a new authz policy" do
|
|
57
|
-
response = client_authz_policy.create!(name, description, type, logic, decision_strategy, fetch_roles, config[:roles])
|
|
58
|
-
expect(response.id).to eq "234f6f33-ef03-4f3f-a8c0-ad7bca27b720"
|
|
59
|
-
expect(response.name).to eq "policy name"
|
|
60
|
-
expect(response.type).to eq "role"
|
|
61
|
-
expect(response.logic).to eq "POSITIVE"
|
|
62
|
-
expect(response.decision_strategy).to eq "UNANIMOUS"
|
|
63
|
-
expect(response.config.roles[0].id).to eq "1d305dbe-6379-4900-8e63-96541006160a"
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe '#get' do
|
|
68
|
-
let(:realm_name) { "valid-realm" }
|
|
69
|
-
let(:client_id) { "valid-client-id" }
|
|
70
|
-
let(:type) { :role }
|
|
71
|
-
let(:policy_id) { "234f6f33-ef03-4f3f-a8c0-ad7bca27b720" }
|
|
72
|
-
let(:client_authz_policy){ KeycloakAdmin.realm(realm_name).authz_policies(client_id, type) }
|
|
73
|
-
before(:each) do
|
|
74
|
-
stub_token_client
|
|
75
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '{"id":"234f6f33-ef03-4f3f-a8c0-ad7bca27b720","name":"policy name","description":"policy description","type":"role","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","config":{"roles":"[{\"id\":\"1d305dbe-6379-4900-8e63-96541006160a\",\"required\":false}]"}}'
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it "returns an authz policy" do
|
|
79
|
-
response = client_authz_policy.get(policy_id)
|
|
80
|
-
expect(response.id).to eq "234f6f33-ef03-4f3f-a8c0-ad7bca27b720"
|
|
81
|
-
expect(response.name).to eq "policy name"
|
|
82
|
-
expect(response.type).to eq "role"
|
|
83
|
-
expect(response.logic).to eq "POSITIVE"
|
|
84
|
-
expect(response.decision_strategy).to eq "UNANIMOUS"
|
|
85
|
-
expect(response.config.roles[0].id).to eq "1d305dbe-6379-4900-8e63-96541006160a"
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
describe '#find_by' do
|
|
90
|
-
let(:realm_name) { "valid-realm" }
|
|
91
|
-
let(:client_id) { "valid-client-id" }
|
|
92
|
-
let(:type) { :role }
|
|
93
|
-
let(:name) { "policy name" }
|
|
94
|
-
let(:client_authz_policy){ KeycloakAdmin.realm(realm_name).authz_policies(client_id, type) }
|
|
95
|
-
before(:each) do
|
|
96
|
-
stub_token_client
|
|
97
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"234f6f33-ef03-4f3f-a8c0-ad7bca27b720","name":"policy name","description":"policy description","type":"role","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","config":{"roles":"[{\"id\":\"1d305dbe-6379-4900-8e63-96541006160a\",\"required\":false}]"}}]'
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "returns list of authz policies" do
|
|
101
|
-
response = client_authz_policy.find_by(name, type)
|
|
102
|
-
expect(response.size).to eq 1
|
|
103
|
-
expect(response[0].id).to eq "234f6f33-ef03-4f3f-a8c0-ad7bca27b720"
|
|
104
|
-
expect(response[0].name).to eq "policy name"
|
|
105
|
-
expect(response[0].type).to eq "role"
|
|
106
|
-
expect(response[0].logic).to eq "POSITIVE"
|
|
107
|
-
expect(response[0].decision_strategy).to eq "UNANIMOUS"
|
|
108
|
-
expect(response[0].config.roles[0].id).to eq "1d305dbe-6379-4900-8e63-96541006160a"
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
describe '#delete' do
|
|
113
|
-
let(:realm_name) { "valid-realm" }
|
|
114
|
-
let(:client_id) { "valid-client-id" }
|
|
115
|
-
let(:type) { :role }
|
|
116
|
-
let(:policy_id) { "234f6f33-ef03-4f3f-a8c0-ad7bca27b720" }
|
|
117
|
-
before(:each) do
|
|
118
|
-
@client_authz_policy = KeycloakAdmin.realm(realm_name).authz_policies(client_id, type)
|
|
119
|
-
stub_token_client
|
|
120
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:delete).and_return 'true'
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
it "deletes an authz policy" do
|
|
124
|
-
response = @client_authz_policy.delete(policy_id)
|
|
125
|
-
expect(response).to eq true
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
describe '#list' do
|
|
130
|
-
let(:realm_name) { "valid-realm" }
|
|
131
|
-
let(:client_id) { "valid-client-id" }
|
|
132
|
-
let(:type) { :role }
|
|
133
|
-
before(:each) do
|
|
134
|
-
@client_authz_policy = KeycloakAdmin.realm(realm_name).authz_policies(client_id, type)
|
|
135
|
-
stub_token_client
|
|
136
|
-
allow_any_instance_of(KeycloakAdmin::Resource).to receive(:get).and_return '[{"id":"234f6f33-ef03-4f3f-a8c0-ad7bca27b720","name":"policy name","description":"policy description","type":"role","logic":"POSITIVE","decisionStrategy":"UNANIMOUS","config":{"roles":"[{\"id\":\"1d305dbe-6379-4900-8e63-96541006160a\",\"required\":false}]"}}]'
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
it "returns list of authz policies" do
|
|
140
|
-
response = @client_authz_policy.list
|
|
141
|
-
expect(response.size).to eq 1
|
|
142
|
-
expect(response[0].id).to eq "234f6f33-ef03-4f3f-a8c0-ad7bca27b720"
|
|
143
|
-
expect(response[0].name).to eq "policy name"
|
|
144
|
-
expect(response[0].type).to eq "role"
|
|
145
|
-
expect(response[0].logic).to eq "POSITIVE"
|
|
146
|
-
expect(response[0].decision_strategy).to eq "UNANIMOUS"
|
|
147
|
-
expect(response[0].config.roles[0].id).to eq "1d305dbe-6379-4900-8e63-96541006160a"
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
describe '#authz_policy_url' do
|
|
152
|
-
let(:realm_name) { "valid-realm" }
|
|
153
|
-
let(:client_id) { "valid-client-id" }
|
|
154
|
-
let(:type) { :role }
|
|
155
|
-
let(:client_authz_policy){ KeycloakAdmin.realm(realm_name).authz_policies(client_id, type) }
|
|
156
|
-
|
|
157
|
-
context 'when policy_id is nil' do
|
|
158
|
-
let(:policy_id) { nil }
|
|
159
|
-
it "return a proper url" do
|
|
160
|
-
expect(client_authz_policy.authz_policy_url(client_id, type, policy_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/policy/role?permission=false"
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
context 'when policy_id is not nil' do
|
|
164
|
-
let(:policy_id) { "234f6f33-ef03-4f3f-a8c0-ad7bca27b720" }
|
|
165
|
-
it "return a proper url" do
|
|
166
|
-
expect(client_authz_policy.authz_policy_url(client_id, type, policy_id)).to eq "http://auth.service.io/auth/admin/realms/valid-realm/clients/valid-client-id/authz/resource-server/policy/role/234f6f33-ef03-4f3f-a8c0-ad7bca27b720"
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
end
|