keycloak-admin 1.1.2 → 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.
Files changed (94) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/Dockerfile +24 -0
  3. data/.github/workflows/ci.yml +80 -0
  4. data/.gitignore +9 -9
  5. data/.rspec +2 -2
  6. data/CHANGELOG.md +194 -183
  7. data/Dockerfile +12 -12
  8. data/Gemfile +3 -3
  9. data/Gemfile.lock +51 -49
  10. data/MIT-LICENSE +20 -20
  11. data/README.md +748 -482
  12. data/bin/console +9 -9
  13. data/keycloak-admin.gemspec +24 -24
  14. data/lib/keycloak-admin/client/attack_detection_client.rb +41 -41
  15. data/lib/keycloak-admin/client/client.rb +56 -56
  16. data/lib/keycloak-admin/client/client_authz_permission_client.rb +81 -0
  17. data/lib/keycloak-admin/client/client_authz_policy_client.rb +76 -0
  18. data/lib/keycloak-admin/client/client_authz_resource_client.rb +93 -0
  19. data/lib/keycloak-admin/client/client_authz_scope_client.rb +71 -0
  20. data/lib/keycloak-admin/client/client_client.rb +71 -71
  21. data/lib/keycloak-admin/client/client_role_client.rb +20 -20
  22. data/lib/keycloak-admin/client/client_role_mappings_client.rb +32 -32
  23. data/lib/keycloak-admin/client/configurable_token_client.rb +35 -35
  24. data/lib/keycloak-admin/client/group_client.rb +148 -131
  25. data/lib/keycloak-admin/client/identity_provider_client.rb +51 -51
  26. data/lib/keycloak-admin/client/realm_client.rb +122 -106
  27. data/lib/keycloak-admin/client/role_client.rb +59 -59
  28. data/lib/keycloak-admin/client/role_mapper_client.rb +47 -45
  29. data/lib/keycloak-admin/client/token_client.rb +29 -29
  30. data/lib/keycloak-admin/client/user_client.rb +266 -266
  31. data/lib/keycloak-admin/configuration.rb +52 -52
  32. data/lib/keycloak-admin/representation/attack_detection_representation.rb +17 -17
  33. data/lib/keycloak-admin/representation/camel_json.rb +12 -12
  34. data/lib/keycloak-admin/representation/client_authz_permission_representation.rb +34 -0
  35. data/lib/keycloak-admin/representation/client_authz_policy_config_representation.rb +15 -0
  36. data/lib/keycloak-admin/representation/client_authz_policy_representation.rb +27 -0
  37. data/lib/keycloak-admin/representation/client_authz_resource_representation.rb +26 -0
  38. data/lib/keycloak-admin/representation/client_authz_scope_representation.rb +17 -0
  39. data/lib/keycloak-admin/representation/client_representation.rb +71 -71
  40. data/lib/keycloak-admin/representation/credential_representation.rb +38 -38
  41. data/lib/keycloak-admin/representation/federated_identity_representation.rb +15 -15
  42. data/lib/keycloak-admin/representation/group_representation.rb +21 -21
  43. data/lib/keycloak-admin/representation/identity_provider_mapper_representation.rb +19 -19
  44. data/lib/keycloak-admin/representation/identity_provider_representation.rb +67 -67
  45. data/lib/keycloak-admin/representation/impersonation_redirection_representation.rb +16 -16
  46. data/lib/keycloak-admin/representation/impersonation_representation.rb +43 -43
  47. data/lib/keycloak-admin/representation/protocol_mapper_representation.rb +19 -19
  48. data/lib/keycloak-admin/representation/realm_representation.rb +14 -14
  49. data/lib/keycloak-admin/representation/representation.rb +23 -23
  50. data/lib/keycloak-admin/representation/role_representation.rb +19 -19
  51. data/lib/keycloak-admin/representation/session_representation.rb +22 -22
  52. data/lib/keycloak-admin/representation/token_representation.rb +39 -39
  53. data/lib/keycloak-admin/representation/user_representation.rb +47 -47
  54. data/lib/keycloak-admin/resource/base_role_containing_resource.rb +28 -28
  55. data/lib/keycloak-admin/resource/group_resource.rb +11 -11
  56. data/lib/keycloak-admin/resource/user_resource.rb +7 -7
  57. data/lib/keycloak-admin/version.rb +3 -3
  58. data/lib/keycloak-admin.rb +84 -75
  59. data/spec/client/attack_detection_client_spec.rb +102 -102
  60. data/spec/client/client_authz_permission_client_spec.rb +170 -0
  61. data/spec/client/client_authz_policy_client_spec.rb +170 -0
  62. data/spec/client/client_authz_resource_client_spec.rb +150 -0
  63. data/spec/client/client_authz_scope_client_spec.rb +134 -0
  64. data/spec/client/client_client_spec.rb +133 -133
  65. data/spec/client/client_role_mappings_client_spec.rb +82 -82
  66. data/spec/client/client_spec.rb +28 -28
  67. data/spec/client/configurable_token_client_spec.rb +34 -34
  68. data/spec/client/group_client_spec.rb +328 -258
  69. data/spec/client/identity_provider_client_spec.rb +92 -92
  70. data/spec/client/realm_client_spec.rb +155 -155
  71. data/spec/client/role_client_spec.rb +79 -79
  72. data/spec/client/role_mapper_client_spec.rb +113 -68
  73. data/spec/client/token_client_spec.rb +68 -68
  74. data/spec/client/user_client_spec.rb +373 -373
  75. data/spec/configuration_spec.rb +113 -113
  76. data/spec/integration/client_authorization_spec.rb +93 -0
  77. data/spec/representation/attack_detection_representation_spec.rb +15 -15
  78. data/spec/representation/client_authz_permission_representation_spec.rb +52 -0
  79. data/spec/representation/client_authz_policy_representation_spec.rb +47 -0
  80. data/spec/representation/client_authz_resource_representation_spec.rb +33 -0
  81. data/spec/representation/client_authz_scope_representation_spec.rb +19 -0
  82. data/spec/representation/client_representation_spec.rb +119 -119
  83. data/spec/representation/group_representation_spec.rb +22 -22
  84. data/spec/representation/identity_provider_mapper_representation_spec.rb +24 -24
  85. data/spec/representation/identity_provider_representation_spec.rb +113 -113
  86. data/spec/representation/impersonation_representation_spec.rb +163 -163
  87. data/spec/representation/protocol_mapper_representation_spec.rb +57 -57
  88. data/spec/representation/role_representation_spec.rb +37 -37
  89. data/spec/representation/session_representation_spec.rb +15 -15
  90. data/spec/representation/user_representation_spec.rb +15 -15
  91. data/spec/resource/group_resource_spec.rb +14 -14
  92. data/spec/resource/user_resource_spec.rb +14 -14
  93. data/spec/spec_helper.rb +37 -37
  94. metadata +29 -9
@@ -1,75 +1,84 @@
1
- require "logger"
2
-
3
- require_relative "keycloak-admin/configuration"
4
- require_relative "keycloak-admin/client/client"
5
- require_relative "keycloak-admin/client/client_client"
6
- require_relative "keycloak-admin/client/client_role_client"
7
- require_relative "keycloak-admin/client/client_role_mappings_client"
8
- require_relative "keycloak-admin/client/group_client"
9
- require_relative "keycloak-admin/client/realm_client"
10
- require_relative "keycloak-admin/client/role_client"
11
- require_relative "keycloak-admin/client/role_mapper_client"
12
- require_relative "keycloak-admin/client/token_client"
13
- require_relative "keycloak-admin/client/user_client"
14
- require_relative "keycloak-admin/client/identity_provider_client"
15
- require_relative "keycloak-admin/client/configurable_token_client"
16
- require_relative "keycloak-admin/client/attack_detection_client"
17
- require_relative "keycloak-admin/representation/camel_json"
18
- require_relative "keycloak-admin/representation/representation"
19
- require_relative "keycloak-admin/representation/protocol_mapper_representation"
20
- require_relative "keycloak-admin/representation/client_representation"
21
- require_relative "keycloak-admin/representation/group_representation"
22
- require_relative "keycloak-admin/representation/token_representation"
23
- require_relative "keycloak-admin/representation/impersonation_redirection_representation"
24
- require_relative "keycloak-admin/representation/impersonation_representation"
25
- require_relative "keycloak-admin/representation/credential_representation"
26
- require_relative "keycloak-admin/representation/realm_representation"
27
- require_relative "keycloak-admin/representation/role_representation"
28
- require_relative "keycloak-admin/representation/federated_identity_representation"
29
- require_relative "keycloak-admin/representation/user_representation"
30
- require_relative "keycloak-admin/representation/identity_provider_mapper_representation"
31
- require_relative "keycloak-admin/representation/identity_provider_representation"
32
- require_relative "keycloak-admin/representation/attack_detection_representation"
33
- require_relative "keycloak-admin/representation/session_representation"
34
- require_relative "keycloak-admin/resource/base_role_containing_resource"
35
- require_relative "keycloak-admin/resource/group_resource"
36
- require_relative "keycloak-admin/resource/user_resource"
37
-
38
- module KeycloakAdmin
39
-
40
- def self.configure
41
- yield @configuration ||= KeycloakAdmin::Configuration.new
42
- end
43
-
44
- def self.config
45
- @configuration
46
- end
47
-
48
- def self.realm(realm_name)
49
- create_client(@configuration, realm_name)
50
- end
51
-
52
- def self.create_client(configuration, realm_name)
53
- RealmClient.new(configuration, realm_name)
54
- end
55
-
56
- def self.logger
57
- config.logger
58
- end
59
-
60
- def self.load_configuration
61
- configure do |config|
62
- config.server_url = nil
63
- config.server_domain = nil
64
- config.client_realm_name = ""
65
- config.client_id = "admin-cli"
66
- config.logger = ::Logger.new(STDOUT)
67
- config.use_service_account = true
68
- config.username = nil
69
- config.password = nil
70
- config.rest_client_options = {}
71
- end
72
- end
73
-
74
- load_configuration
75
- end
1
+ require "logger"
2
+
3
+ require_relative "keycloak-admin/configuration"
4
+ require_relative "keycloak-admin/client/client"
5
+ require_relative "keycloak-admin/client/client_client"
6
+ require_relative "keycloak-admin/client/client_role_client"
7
+ require_relative "keycloak-admin/client/client_role_mappings_client"
8
+ require_relative "keycloak-admin/client/group_client"
9
+ require_relative "keycloak-admin/client/realm_client"
10
+ require_relative "keycloak-admin/client/role_client"
11
+ require_relative "keycloak-admin/client/role_mapper_client"
12
+ require_relative "keycloak-admin/client/token_client"
13
+ require_relative "keycloak-admin/client/user_client"
14
+ require_relative "keycloak-admin/client/identity_provider_client"
15
+ require_relative "keycloak-admin/client/configurable_token_client"
16
+ require_relative "keycloak-admin/client/attack_detection_client"
17
+ require_relative "keycloak-admin/client/client_authz_scope_client"
18
+ require_relative "keycloak-admin/client/client_authz_resource_client"
19
+ require_relative "keycloak-admin/client/client_authz_policy_client"
20
+ require_relative "keycloak-admin/client/client_authz_permission_client"
21
+ require_relative "keycloak-admin/representation/camel_json"
22
+ require_relative "keycloak-admin/representation/representation"
23
+ require_relative "keycloak-admin/representation/protocol_mapper_representation"
24
+ require_relative "keycloak-admin/representation/client_representation"
25
+ require_relative "keycloak-admin/representation/group_representation"
26
+ require_relative "keycloak-admin/representation/token_representation"
27
+ require_relative "keycloak-admin/representation/impersonation_redirection_representation"
28
+ require_relative "keycloak-admin/representation/impersonation_representation"
29
+ require_relative "keycloak-admin/representation/credential_representation"
30
+ require_relative "keycloak-admin/representation/realm_representation"
31
+ require_relative "keycloak-admin/representation/role_representation"
32
+ require_relative "keycloak-admin/representation/federated_identity_representation"
33
+ require_relative "keycloak-admin/representation/user_representation"
34
+ require_relative "keycloak-admin/representation/identity_provider_mapper_representation"
35
+ require_relative "keycloak-admin/representation/identity_provider_representation"
36
+ require_relative "keycloak-admin/representation/attack_detection_representation"
37
+ require_relative "keycloak-admin/representation/session_representation"
38
+ require_relative "keycloak-admin/representation/client_authz_scope_representation"
39
+ require_relative "keycloak-admin/representation/client_authz_resource_representation"
40
+ require_relative "keycloak-admin/representation/client_authz_policy_representation"
41
+ require_relative "keycloak-admin/representation/client_authz_policy_config_representation"
42
+ require_relative "keycloak-admin/representation/client_authz_permission_representation"
43
+ require_relative "keycloak-admin/resource/base_role_containing_resource"
44
+ require_relative "keycloak-admin/resource/group_resource"
45
+ require_relative "keycloak-admin/resource/user_resource"
46
+
47
+ module KeycloakAdmin
48
+
49
+ def self.configure
50
+ yield @configuration ||= KeycloakAdmin::Configuration.new
51
+ end
52
+
53
+ def self.config
54
+ @configuration
55
+ end
56
+
57
+ def self.realm(realm_name)
58
+ create_client(@configuration, realm_name)
59
+ end
60
+
61
+ def self.create_client(configuration, realm_name)
62
+ RealmClient.new(configuration, realm_name)
63
+ end
64
+
65
+ def self.logger
66
+ config.logger
67
+ end
68
+
69
+ def self.load_configuration
70
+ configure do |config|
71
+ config.server_url = nil
72
+ config.server_domain = nil
73
+ config.client_realm_name = ""
74
+ config.client_id = "admin-cli"
75
+ config.logger = ::Logger.new(STDOUT)
76
+ config.use_service_account = true
77
+ config.username = nil
78
+ config.password = nil
79
+ config.rest_client_options = {}
80
+ end
81
+ end
82
+
83
+ load_configuration
84
+ end
@@ -1,102 +1,102 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe KeycloakAdmin::AttackDetectionClient do
4
- describe "#initialize" do
5
- let(:realm_name) { nil }
6
- before(:each) do
7
- @realm = KeycloakAdmin.realm(realm_name)
8
- end
9
- context "when realm_name is defined" do
10
- let(:realm_name) { "master" }
11
- it "does not raise any error" do
12
- expect { @realm.attack_detections }.to_not raise_error
13
- end
14
- end
15
-
16
- context "when realm_name is not defined" do
17
- it "raise argument error" do
18
- expect { @realm.attack_detections }.to raise_error(ArgumentError)
19
- end
20
- end
21
- end
22
-
23
- describe "#lock_status" do
24
- let(:realm_name) { "valid-realm" }
25
- before(:each) do
26
- @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
27
- stub_token_client
28
- allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '{"numFailures":1,"disabled":true, "lastFailure":123456}'
29
- end
30
-
31
- context "when user_id is defined" do
32
- let(:user_id) { "test_user_id" }
33
- it "returns lock details" do
34
- response = @attack_detections.lock_status(user_id)
35
- expect(response.num_failures).to eq 1
36
- end
37
- end
38
-
39
- context "when user_id is not defined" do
40
- let(:user_id) { nil }
41
- it "raise argument error" do
42
- expect { @attack_detections.lock_status(user_id) }.to raise_error(ArgumentError)
43
- end
44
- end
45
- end
46
-
47
- describe "#unlock_user" do
48
- let(:realm_name) { "valid-realm" }
49
- before(:each) do
50
- @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
51
- stub_token_client
52
- allow_any_instance_of(RestClient::Resource).to receive(:delete)
53
- end
54
-
55
- context "when user_id is defined" do
56
- let(:user_id) { "test_user_id" }
57
- it "returns true" do
58
- expect(@attack_detections.unlock_user(user_id)).to be_truthy
59
- end
60
- end
61
-
62
- context "when user_id is not defined" do
63
- let(:user_id) { nil }
64
- it "raise argument error" do
65
- expect { @attack_detections.unlock_user(user_id) }.to raise_error(ArgumentError)
66
- end
67
- end
68
- end
69
-
70
- describe "#unlock_users" do
71
- let(:realm_name) { "valid-realm" }
72
- before(:each) do
73
- @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
74
- stub_token_client
75
- allow_any_instance_of(RestClient::Resource).to receive(:delete)
76
- end
77
- it "returns true" do
78
- expect(@attack_detections.unlock_users).to be_truthy
79
- end
80
- end
81
-
82
- describe "#brute_force_url" do
83
- let(:realm_name) { "valid-realm" }
84
- let(:user_id) { nil }
85
- before(:each) do
86
- @attack_detections_url = KeycloakAdmin.realm(realm_name).attack_detections.brute_force_url(user_id)
87
- end
88
-
89
- context "when user_id is defined" do
90
- let(:user_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
91
- it "returns user specific url" do
92
- expect(@attack_detections_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/attack-detection/brute-force/users/#{user_id}"
93
- end
94
- end
95
-
96
- context "when user_id is not defined" do
97
- it "returns url without user" do
98
- expect(@attack_detections_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/attack-detection/brute-force/users"
99
- end
100
- end
101
- end
102
- end
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe KeycloakAdmin::AttackDetectionClient do
4
+ describe "#initialize" do
5
+ let(:realm_name) { nil }
6
+ before(:each) do
7
+ @realm = KeycloakAdmin.realm(realm_name)
8
+ end
9
+ context "when realm_name is defined" do
10
+ let(:realm_name) { "master" }
11
+ it "does not raise any error" do
12
+ expect { @realm.attack_detections }.to_not raise_error
13
+ end
14
+ end
15
+
16
+ context "when realm_name is not defined" do
17
+ it "raise argument error" do
18
+ expect { @realm.attack_detections }.to raise_error(ArgumentError)
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "#lock_status" do
24
+ let(:realm_name) { "valid-realm" }
25
+ before(:each) do
26
+ @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
27
+ stub_token_client
28
+ allow_any_instance_of(RestClient::Resource).to receive(:get).and_return '{"numFailures":1,"disabled":true, "lastFailure":123456}'
29
+ end
30
+
31
+ context "when user_id is defined" do
32
+ let(:user_id) { "test_user_id" }
33
+ it "returns lock details" do
34
+ response = @attack_detections.lock_status(user_id)
35
+ expect(response.num_failures).to eq 1
36
+ end
37
+ end
38
+
39
+ context "when user_id is not defined" do
40
+ let(:user_id) { nil }
41
+ it "raise argument error" do
42
+ expect { @attack_detections.lock_status(user_id) }.to raise_error(ArgumentError)
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "#unlock_user" do
48
+ let(:realm_name) { "valid-realm" }
49
+ before(:each) do
50
+ @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
51
+ stub_token_client
52
+ allow_any_instance_of(RestClient::Resource).to receive(:delete)
53
+ end
54
+
55
+ context "when user_id is defined" do
56
+ let(:user_id) { "test_user_id" }
57
+ it "returns true" do
58
+ expect(@attack_detections.unlock_user(user_id)).to be_truthy
59
+ end
60
+ end
61
+
62
+ context "when user_id is not defined" do
63
+ let(:user_id) { nil }
64
+ it "raise argument error" do
65
+ expect { @attack_detections.unlock_user(user_id) }.to raise_error(ArgumentError)
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "#unlock_users" do
71
+ let(:realm_name) { "valid-realm" }
72
+ before(:each) do
73
+ @attack_detections = KeycloakAdmin.realm(realm_name).attack_detections
74
+ stub_token_client
75
+ allow_any_instance_of(RestClient::Resource).to receive(:delete)
76
+ end
77
+ it "returns true" do
78
+ expect(@attack_detections.unlock_users).to be_truthy
79
+ end
80
+ end
81
+
82
+ describe "#brute_force_url" do
83
+ let(:realm_name) { "valid-realm" }
84
+ let(:user_id) { nil }
85
+ before(:each) do
86
+ @attack_detections_url = KeycloakAdmin.realm(realm_name).attack_detections.brute_force_url(user_id)
87
+ end
88
+
89
+ context "when user_id is defined" do
90
+ let(:user_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
91
+ it "returns user specific url" do
92
+ expect(@attack_detections_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/attack-detection/brute-force/users/#{user_id}"
93
+ end
94
+ end
95
+
96
+ context "when user_id is not defined" do
97
+ it "returns url without user" do
98
+ expect(@attack_detections_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/attack-detection/brute-force/users"
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,170 @@
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(RestClient::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(RestClient::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(RestClient::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(RestClient::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(RestClient::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