keycloak-admin 2.0.1 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +40 -4
- data/keycloak-admin.gemspec +14 -6
- data/lib/keycloak-admin/client/client.rb +22 -10
- data/lib/keycloak-admin/client/client_authz_permission_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_policy_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_resource_client.rb +1 -1
- data/lib/keycloak-admin/client/client_authz_scope_client.rb +1 -1
- data/lib/keycloak-admin/client/group_client.rb +2 -5
- data/lib/keycloak-admin/client/organization_client.rb +7 -7
- data/lib/keycloak-admin/client/user_client.rb +8 -4
- data/lib/keycloak-admin/error.rb +62 -0
- data/lib/keycloak-admin/version.rb +1 -1
- data/lib/keycloak-admin.rb +1 -0
- metadata +21 -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
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
name: Release
|
|
2
|
-
|
|
3
|
-
# Publishing is triggered by pushing a version tag, e.g.:
|
|
4
|
-
# git tag -a v1.2.0 -m "Version 1.2.0" && git push origin v1.2.0
|
|
5
|
-
#
|
|
6
|
-
# No RubyGems API key is stored in this repository: the gem is pushed through
|
|
7
|
-
# RubyGems' Trusted Publishing, which exchanges a short-lived GitHub OIDC token
|
|
8
|
-
# for a scoped RubyGems credential. This requires a trusted publisher declared on
|
|
9
|
-
# https://rubygems.org/gems/keycloak-admin pointing to this repository, this
|
|
10
|
-
# workflow file name and the 'release' environment.
|
|
11
|
-
on:
|
|
12
|
-
push:
|
|
13
|
-
tags: [ "v*" ]
|
|
14
|
-
|
|
15
|
-
permissions:
|
|
16
|
-
contents: read
|
|
17
|
-
|
|
18
|
-
jobs:
|
|
19
|
-
release:
|
|
20
|
-
name: Push gem to RubyGems.org
|
|
21
|
-
# Pinned rather than 'ubuntu-latest', for the same reason as in ci.yml.
|
|
22
|
-
runs-on: ubuntu-24.04
|
|
23
|
-
|
|
24
|
-
environment: release
|
|
25
|
-
|
|
26
|
-
permissions:
|
|
27
|
-
contents: write # 'rake release' pushes the version tag when it does not exist yet
|
|
28
|
-
id-token: write # mandatory to request the OIDC token used by trusted publishing
|
|
29
|
-
|
|
30
|
-
steps:
|
|
31
|
-
# The test suite includes an integration spec that talks to a real Keycloak
|
|
32
|
-
# (spec/integration/client_authorization_spec.rb, gated on ENV["GITHUB_ACTIONS"],
|
|
33
|
-
# which GitHub Actions sets on every run regardless of workflow). Keycloak is
|
|
34
|
-
# provisioned here the same way ci.yml does it, so 'bundle exec rspec' below is a
|
|
35
|
-
# real, complete gate rather than skipping that spec for lack of a server.
|
|
36
|
-
- name: Start Keycloak
|
|
37
|
-
run: |
|
|
38
|
-
docker run -d --name keycloak -p 8080:8080 \
|
|
39
|
-
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
|
|
40
|
-
-e KC_BOOTSTRAP_ADMIN_PASSWORD=admin \
|
|
41
|
-
-e KC_HOSTNAME=http://localhost:8080 \
|
|
42
|
-
-e KC_HOSTNAME_ADMIN=http://localhost:8080 \
|
|
43
|
-
-e KC_HTTP_ENABLED=true \
|
|
44
|
-
-e KC_DB=dev-file \
|
|
45
|
-
quay.io/keycloak/keycloak:26.7.0 \
|
|
46
|
-
start-dev
|
|
47
|
-
|
|
48
|
-
- name: Wait for Keycloak to be ready
|
|
49
|
-
run: |
|
|
50
|
-
for i in $(seq 1 30); do
|
|
51
|
-
if curl --silent --fail http://localhost:8080/realms/master > /dev/null; then
|
|
52
|
-
echo "Keycloak is ready"
|
|
53
|
-
exit 0
|
|
54
|
-
fi
|
|
55
|
-
sleep 5
|
|
56
|
-
done
|
|
57
|
-
echo "Keycloak did not become ready in time"
|
|
58
|
-
docker logs keycloak
|
|
59
|
-
exit 1
|
|
60
|
-
|
|
61
|
-
- name: create realm
|
|
62
|
-
run: |
|
|
63
|
-
TOKEN=$(curl --silent --location --request POST "http://localhost:8080/realms/master/protocol/openid-connect/token" \
|
|
64
|
-
--header 'Content-Type: application/x-www-form-urlencoded' \
|
|
65
|
-
--data-urlencode 'grant_type=password' \
|
|
66
|
-
--data-urlencode 'username=admin' \
|
|
67
|
-
--data-urlencode 'password=admin' \
|
|
68
|
-
--data-urlencode 'client_id=admin-cli' | jq -r '.access_token')
|
|
69
|
-
|
|
70
|
-
curl --silent --show-error -L -X POST "http://localhost:8080/admin/realms" \
|
|
71
|
-
--header "Content-Type: application/json" \
|
|
72
|
-
--header "Authorization: Bearer ${TOKEN}" \
|
|
73
|
-
--data '{"realm":"dummy","enabled":true}'
|
|
74
|
-
|
|
75
|
-
curl --silent --show-error --request POST 'http://localhost:8080/admin/realms/dummy/clients' \
|
|
76
|
-
--header 'Authorization: Bearer '$TOKEN \
|
|
77
|
-
--header 'Content-Type: application/json' \
|
|
78
|
-
--data-raw '{
|
|
79
|
-
"clientId":"dummy-client",
|
|
80
|
-
"enabled":true,
|
|
81
|
-
"consentRequired": false,
|
|
82
|
-
"attributes":{},
|
|
83
|
-
"serviceAccountsEnabled": true,
|
|
84
|
-
"protocol":"openid-connect",
|
|
85
|
-
"publicClient":false,
|
|
86
|
-
"authorizationServicesEnabled": true,
|
|
87
|
-
"clientAuthenticatorType":"client-secret",
|
|
88
|
-
"redirectUris":["http://localhost:8180/demo"]
|
|
89
|
-
}'
|
|
90
|
-
|
|
91
|
-
- uses: actions/checkout@v4
|
|
92
|
-
|
|
93
|
-
- name: Set up Ruby
|
|
94
|
-
uses: ruby/setup-ruby@v1
|
|
95
|
-
with:
|
|
96
|
-
ruby-version: '3.4'
|
|
97
|
-
bundler-cache: true
|
|
98
|
-
|
|
99
|
-
- name: Check that the tag matches KeycloakAdmin::VERSION
|
|
100
|
-
run: |
|
|
101
|
-
tag="${GITHUB_REF_NAME#v}"
|
|
102
|
-
version="$(ruby -Ilib -r keycloak-admin/version -e 'print KeycloakAdmin::VERSION')"
|
|
103
|
-
if [ "$tag" != "$version" ]; then
|
|
104
|
-
echo "::error::Tag '${GITHUB_REF_NAME}' does not match KeycloakAdmin::VERSION '${version}'"
|
|
105
|
-
exit 1
|
|
106
|
-
fi
|
|
107
|
-
|
|
108
|
-
- name: Run tests
|
|
109
|
-
run: bundle exec rspec
|
|
110
|
-
|
|
111
|
-
# Builds the gem, pushes it to RubyGems.org and waits for it to be available.
|
|
112
|
-
- uses: rubygems/release-gem@v1
|
data/.gitignore
DELETED
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
|