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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +40 -4
  4. data/keycloak-admin.gemspec +14 -6
  5. data/lib/keycloak-admin/client/client.rb +22 -10
  6. data/lib/keycloak-admin/client/client_authz_permission_client.rb +1 -1
  7. data/lib/keycloak-admin/client/client_authz_policy_client.rb +1 -1
  8. data/lib/keycloak-admin/client/client_authz_resource_client.rb +1 -1
  9. data/lib/keycloak-admin/client/client_authz_scope_client.rb +1 -1
  10. data/lib/keycloak-admin/client/group_client.rb +2 -5
  11. data/lib/keycloak-admin/client/organization_client.rb +7 -7
  12. data/lib/keycloak-admin/client/user_client.rb +8 -4
  13. data/lib/keycloak-admin/error.rb +62 -0
  14. data/lib/keycloak-admin/version.rb +1 -1
  15. data/lib/keycloak-admin.rb +1 -0
  16. metadata +21 -56
  17. data/.github/workflows/Dockerfile +0 -24
  18. data/.github/workflows/ci.yml +0 -94
  19. data/.github/workflows/release.yml +0 -112
  20. data/.gitignore +0 -10
  21. data/.rspec +0 -2
  22. data/Dockerfile +0 -13
  23. data/Gemfile +0 -3
  24. data/Gemfile.lock +0 -54
  25. data/Rakefile +0 -6
  26. data/bin/console +0 -9
  27. data/spec/client/attack_detection_client_spec.rb +0 -102
  28. data/spec/client/client_authz_permission_client_spec.rb +0 -170
  29. data/spec/client/client_authz_policy_client_spec.rb +0 -170
  30. data/spec/client/client_authz_resource_client_spec.rb +0 -150
  31. data/spec/client/client_authz_scope_client_spec.rb +0 -134
  32. data/spec/client/client_client_spec.rb +0 -133
  33. data/spec/client/client_role_mappings_client_spec.rb +0 -83
  34. data/spec/client/client_scope_client_spec.rb +0 -220
  35. data/spec/client/client_scope_protocol_mapper_client_spec.rb +0 -230
  36. data/spec/client/client_spec.rb +0 -101
  37. data/spec/client/configurable_token_client_spec.rb +0 -34
  38. data/spec/client/group_client_spec.rb +0 -328
  39. data/spec/client/identity_provider_client_spec.rb +0 -92
  40. data/spec/client/organization_client_spec.rb +0 -595
  41. data/spec/client/realm_client_spec.rb +0 -155
  42. data/spec/client/resource_spec.rb +0 -223
  43. data/spec/client/response_spec.rb +0 -68
  44. data/spec/client/role_client_spec.rb +0 -79
  45. data/spec/client/role_mapper_client_spec.rb +0 -113
  46. data/spec/client/token_client_spec.rb +0 -68
  47. data/spec/client/user_client_spec.rb +0 -418
  48. data/spec/configuration_spec.rb +0 -150
  49. data/spec/gemspec_spec.rb +0 -25
  50. data/spec/integration/client_authorization_spec.rb +0 -93
  51. data/spec/representation/attack_detection_representation_spec.rb +0 -16
  52. data/spec/representation/client_authz_permission_representation_spec.rb +0 -52
  53. data/spec/representation/client_authz_policy_representation_spec.rb +0 -47
  54. data/spec/representation/client_authz_resource_representation_spec.rb +0 -33
  55. data/spec/representation/client_authz_scope_representation_spec.rb +0 -19
  56. data/spec/representation/client_representation_spec.rb +0 -119
  57. data/spec/representation/client_scope_representation_spec.rb +0 -125
  58. data/spec/representation/credential_representation_spec.rb +0 -68
  59. data/spec/representation/group_representation_spec.rb +0 -22
  60. data/spec/representation/identity_provider_mapper_representation_spec.rb +0 -24
  61. data/spec/representation/identity_provider_representation_spec.rb +0 -113
  62. data/spec/representation/impersonation_representation_spec.rb +0 -163
  63. data/spec/representation/organization_representation_spec.rb +0 -64
  64. data/spec/representation/protocol_mapper_representation_spec.rb +0 -57
  65. data/spec/representation/role_representation_spec.rb +0 -37
  66. data/spec/representation/session_representation_spec.rb +0 -16
  67. data/spec/representation/user_representation_spec.rb +0 -15
  68. data/spec/resource/group_resource_spec.rb +0 -14
  69. data/spec/resource/user_resource_spec.rb +0 -14
  70. data/spec/spec_helper.rb +0 -36
@@ -1,113 +0,0 @@
1
- RSpec.describe KeycloakAdmin::IdentityProviderRepresentation do
2
- describe "#from_hash" do
3
- before(:each) do
4
- json = <<-JSON
5
- {
6
- "alias": "acme",
7
- "displayName": "ACME",
8
- "internalId": "20fea77e-ae3d-411e-9467-2b3a20cd3e6d",
9
- "providerId": "saml",
10
- "enabled": true,
11
- "updateProfileFirstLoginMode": "on",
12
- "trustEmail": true,
13
- "storeToken": false,
14
- "addReadTokenRoleOnCreate": false,
15
- "authenticateByDefault": false,
16
- "linkOnly": false,
17
- "firstBrokerLoginFlowAlias": "first broker login",
18
- "config": {
19
- "hideOnLoginPage": "",
20
- "validateSignature": "true",
21
- "samlXmlKeyNameTranformer": "KEY_ID",
22
- "signingCertificate": "",
23
- "postBindingLogout": "false",
24
- "nameIDPolicyFormat": "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
25
- "postBindingResponse": "true",
26
- "backchannelSupported": "",
27
- "signatureAlgorithm": "RSA_SHA256",
28
- "wantAssertionsEncrypted": "false",
29
- "xmlSigKeyInfoKeyNameTransformer": "CERT_SUBJECT",
30
- "useJwksUrl": "true",
31
- "wantAssertionsSigned": "true",
32
- "postBindingAuthnRequest": "true",
33
- "forceAuthn": "",
34
- "wantAuthnRequestsSigned": "true",
35
- "singleSignOnServiceUrl": "https://login.microsoftonline.com/test/saml2",
36
- "addExtensionsElementWithKeyInfo": "false"
37
- }
38
- }
39
- JSON
40
- payload = JSON.parse(json)
41
- @identity_provider = KeycloakAdmin::IdentityProviderRepresentation.from_hash(payload)
42
- end
43
-
44
- it "parses the alias" do
45
- expect(@identity_provider.alias).to eq "acme"
46
- end
47
-
48
- it "parses the display name" do
49
- expect(@identity_provider.display_name).to eq "ACME"
50
- end
51
-
52
- it "parses the internalId" do
53
- expect(@identity_provider.internal_id).to eq "20fea77e-ae3d-411e-9467-2b3a20cd3e6d"
54
- end
55
-
56
- it "parses the provider id" do
57
- expect(@identity_provider.provider_id).to eq "saml"
58
- end
59
-
60
- it "parses the enabled" do
61
- expect(@identity_provider.enabled).to eq true
62
- end
63
-
64
- it "parses the update_profile_first_login_mode" do
65
- expect(@identity_provider.update_profile_first_login_mode).to eq "on"
66
- end
67
-
68
- it "parses the trust_email" do
69
- expect(@identity_provider.trust_email).to eq true
70
- end
71
-
72
- it "parses the store_token" do
73
- expect(@identity_provider.store_token).to eq false
74
- end
75
-
76
- it "parses the add_read_token_role_on_create" do
77
- expect(@identity_provider.add_read_token_role_on_create).to eq false
78
- end
79
-
80
- it "parses the authenticate_by_default" do
81
- expect(@identity_provider.authenticate_by_default).to eq false
82
- end
83
-
84
- it "parses the link_only" do
85
- expect(@identity_provider.link_only).to eq false
86
- end
87
-
88
- it "parses the first_broker_login_flow_alias" do
89
- expect(@identity_provider.first_broker_login_flow_alias).to eq "first broker login"
90
- end
91
-
92
- it "parses the configuration as a hash with camel properties" do
93
- expect(@identity_provider.config["hideOnLoginPage"]).to eq ""
94
- expect(@identity_provider.config["validateSignature"]).to eq "true"
95
- expect(@identity_provider.config["samlXmlKeyNameTranformer"]).to eq "KEY_ID"
96
- expect(@identity_provider.config["signingCertificate"]).to eq ""
97
- expect(@identity_provider.config["postBindingLogout"]).to eq "false"
98
- expect(@identity_provider.config["nameIDPolicyFormat"]).to eq "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
99
- expect(@identity_provider.config["postBindingResponse"]).to eq "true"
100
- expect(@identity_provider.config["backchannelSupported"]).to eq ""
101
- expect(@identity_provider.config["signatureAlgorithm"]).to eq "RSA_SHA256"
102
- expect(@identity_provider.config["wantAssertionsEncrypted"]).to eq "false"
103
- expect(@identity_provider.config["xmlSigKeyInfoKeyNameTransformer"]).to eq "CERT_SUBJECT"
104
- expect(@identity_provider.config["useJwksUrl"]).to eq "true"
105
- expect(@identity_provider.config["wantAssertionsSigned"]).to eq "true"
106
- expect(@identity_provider.config["postBindingAuthnRequest"]).to eq "true"
107
- expect(@identity_provider.config["forceAuthn"]).to eq ""
108
- expect(@identity_provider.config["wantAuthnRequestsSigned"]).to eq "true"
109
- expect(@identity_provider.config["singleSignOnServiceUrl"]).to eq "https://login.microsoftonline.com/test/saml2"
110
- expect(@identity_provider.config["addExtensionsElementWithKeyInfo"]).to eq "false"
111
- end
112
- end
113
- end
@@ -1,163 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ImpersonationRepresentation do
2
- describe "#parse_set_cookie_string" do
3
-
4
- let(:origin) { "http://auth.service.io" }
5
- let(:set_cookie_string) { "" }
6
-
7
- before(:each) do
8
- @cookie = KeycloakAdmin::ImpersonationRepresentation.parse_set_cookie_string(set_cookie_string, origin)
9
- end
10
-
11
- shared_context "common properties are read properly" do
12
- it "parses its domain property" do
13
- expect(@cookie.domain).to eq "auth.service.io"
14
- end
15
-
16
- it "parses its for_domain property" do
17
- expect(@cookie.for_domain).to be false
18
- end
19
-
20
- it "parses its Path property" do
21
- expect(@cookie.path).to eq "/auth/realms/a-realm"
22
- end
23
-
24
- it "parses its Secure property" do
25
- expect(@cookie.secure).to be false
26
- end
27
- end
28
-
29
- context "when result is an expiring empty KEYCLOAK_IDENTITY" do
30
- let(:set_cookie_string) { "KEYCLOAK_IDENTITY=; Version=1; Comment=Expiring cookie; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Max-Age=0; Path=/auth/realms/a-realm; HttpOnly" }
31
-
32
- include_examples "common properties are read properly"
33
-
34
- it "parses its name property" do
35
- expect(@cookie.name).to eq "KEYCLOAK_IDENTITY"
36
- end
37
-
38
- it "parses its value property" do
39
- expect(@cookie.value).to eq ""
40
- end
41
-
42
- it "parses its Expires property" do
43
- expect(@cookie.expires).to be <= Time.now
44
- end
45
-
46
- it "parses its Max-Age property" do
47
- expect(@cookie.max_age).to eq 0
48
- end
49
-
50
- it "parses its HttpOnly property" do
51
- expect(@cookie.httponly).to be true
52
- end
53
- end
54
-
55
-
56
- context "when result is an expiring empty KEYCLOAK_SESSION" do
57
- let(:set_cookie_string) { "KEYCLOAK_SESSION=; Version=1; Comment=Expiring cookie; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Max-Age=0; Path=/auth/realms/a-realm" }
58
-
59
- include_examples "common properties are read properly"
60
-
61
- it "parses its name property" do
62
- expect(@cookie.name).to eq "KEYCLOAK_SESSION"
63
- end
64
-
65
- it "parses its value property" do
66
- expect(@cookie.value).to eq ""
67
- end
68
-
69
- it "parses its Expires property" do
70
- expect(@cookie.expires).to be <= Time.now
71
- end
72
-
73
- it "parses its Max-Age property" do
74
- expect(@cookie.max_age).to eq 0
75
- end
76
-
77
- it "parses its HttpOnly property" do
78
- expect(@cookie.httponly).to be false
79
- end
80
- end
81
-
82
-
83
- context "when result is an expiring empty KEYCLOAK_REMEMBER_ME" do
84
- let(:set_cookie_string) { "KEYCLOAK_REMEMBER_ME=; Version=1; Comment=Expiring cookie; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Max-Age=0; Path=/auth/realms/a-realm; HttpOnly" }
85
-
86
- include_examples "common properties are read properly"
87
-
88
- it "parses its name property" do
89
- expect(@cookie.name).to eq "KEYCLOAK_REMEMBER_ME"
90
- end
91
-
92
- it "parses its value property" do
93
- expect(@cookie.value).to eq ""
94
- end
95
-
96
- it "parses its Expires property" do
97
- expect(@cookie.expires).to be <= Time.now
98
- end
99
-
100
- it "parses its Max-Age property" do
101
- expect(@cookie.max_age).to eq 0
102
- end
103
-
104
- it "parses its HttpOnly property" do
105
- expect(@cookie.httponly).to be true
106
- end
107
- end
108
-
109
- context "when result is a new KEYCLOAK_IDENTITY" do
110
- let(:set_cookie_string) { "KEYCLOAK_IDENTITY=eyJhbGciOiJIUzI1NiIsImtpZCIgOiAiMDQyMTcwMWItY2I2Ny00YzQ4LWIzZWYtMDBlMDhhMmE4MjNjIn0.eyJqdGkiOiI5ZTEyODc3MC1mN2U1LTQ0OWYtYWMzYi03OTAzN2Q5NDBhOTMiLCJleHAiOjE1MTY2ODE2ODIsIm5iZiI6MCwiaWF0IjoxNTE2NjQ1NjgyLCJpc3MiOiJodHRwOi8vYXV0aDo4MDgwL2F1dGgvcmVhbG1zL2NvbW11dHkiLCJzdWIiOiI0NGM1MzdmMi1iMzBiLTRlZTctYjI4Ni1lZTY2NjI2NDcwYWMiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiI3ZDI5NTJlZS0xMjllLTRmOGQtYmFjNy1jMWE0YWUxNGRjY2QiLCJyZXNvdXJjZV9hY2Nlc3MiOnt9LCJzdGF0ZV9jaGVja2VyIjoiUEdXZVdXc3hMRmN3WG1QelFmMGxBQTJrN1V3Skg3UUlHU0lrN3hmWUFEbyJ9.Hw9EM1rZLXkUfE97tfS8jw8MFogfMoGpT34yoMupK3E; Version=1; Path=/auth/realms/a-realm; HttpOnly" }
111
-
112
- include_examples "common properties are read properly"
113
-
114
- it "parses its name property" do
115
- expect(@cookie.name).to eq "KEYCLOAK_IDENTITY"
116
- end
117
-
118
- it "parses its value property" do
119
- expect(@cookie.value).to eq "eyJhbGciOiJIUzI1NiIsImtpZCIgOiAiMDQyMTcwMWItY2I2Ny00YzQ4LWIzZWYtMDBlMDhhMmE4MjNjIn0.eyJqdGkiOiI5ZTEyODc3MC1mN2U1LTQ0OWYtYWMzYi03OTAzN2Q5NDBhOTMiLCJleHAiOjE1MTY2ODE2ODIsIm5iZiI6MCwiaWF0IjoxNTE2NjQ1NjgyLCJpc3MiOiJodHRwOi8vYXV0aDo4MDgwL2F1dGgvcmVhbG1zL2NvbW11dHkiLCJzdWIiOiI0NGM1MzdmMi1iMzBiLTRlZTctYjI4Ni1lZTY2NjI2NDcwYWMiLCJhdXRoX3RpbWUiOjAsInNlc3Npb25fc3RhdGUiOiI3ZDI5NTJlZS0xMjllLTRmOGQtYmFjNy1jMWE0YWUxNGRjY2QiLCJyZXNvdXJjZV9hY2Nlc3MiOnt9LCJzdGF0ZV9jaGVja2VyIjoiUEdXZVdXc3hMRmN3WG1QelFmMGxBQTJrN1V3Skg3UUlHU0lrN3hmWUFEbyJ9.Hw9EM1rZLXkUfE97tfS8jw8MFogfMoGpT34yoMupK3E"
120
- end
121
-
122
- it "parses its Expires property" do
123
- expect(@cookie.expires).to be_nil
124
- end
125
-
126
- it "parses its Max-Age property" do
127
- expect(@cookie.max_age).to be nil
128
- end
129
-
130
- it "parses its HttpOnly property" do
131
- expect(@cookie.httponly).to be true
132
- end
133
- end
134
-
135
- context "when result is a new KEYCLOAK_SESSION" do
136
- let(:set_cookie_string) { "KEYCLOAK_SESSION=commuty/44c537f2-b30b-4ee7-b286-ee66626470ac/cd79f3c2-7cee-4c4e-980b-43293aaaff88; Version=1; Expires=Tue, 23-Jan-2018 23:56:32 GMT; Max-Age=36000; Path=/auth/realms/a-realm" }
137
-
138
- include_examples "common properties are read properly"
139
-
140
- it "parses its name property" do
141
- expect(@cookie.name).to eq "KEYCLOAK_SESSION"
142
- end
143
-
144
- it "parses its value property" do
145
- expect(@cookie.value).to eq "commuty/44c537f2-b30b-4ee7-b286-ee66626470ac/cd79f3c2-7cee-4c4e-980b-43293aaaff88"
146
- end
147
-
148
- it "parses its Expires property" do
149
- expect(@cookie.expires).to_not be_nil
150
- end
151
-
152
- it "parses its Max-Age property" do
153
- expect(@cookie.max_age).to be 36000
154
- end
155
-
156
- it "parses its HttpOnly property" do
157
- expect(@cookie.httponly).to be false
158
- end
159
- end
160
- end
161
- end
162
-
163
-
@@ -1,64 +0,0 @@
1
-
2
- RSpec.describe KeycloakAdmin::OrganizationRepresentation do
3
- describe ".from_json" do
4
- it "parse a single organization" do
5
- json_payload = <<-'payload'
6
- {
7
- "id": "8f6e474e-e688-4bec-99ba-5dc862594f4b",
8
- "name": "My organization",
9
- "alias": "myorg",
10
- "enabled": true,
11
- "description": "A single organization",
12
- "redirectUrl": "https://myapp.acme.com",
13
- "attributes": {
14
- "advanced": [
15
- "yes"
16
- ],
17
- "days": [
18
- "monday",
19
- "friday"
20
- ]
21
- },
22
- "domains": [
23
- {
24
- "name": "hello.com",
25
- "verified": false
26
- },
27
- {
28
- "name": "gmail.com",
29
- "verified": true
30
- }
31
- ]
32
- }
33
- payload
34
-
35
- organization = described_class.from_json(json_payload)
36
- expect(organization).to be
37
- expect(organization).to be_a described_class
38
- expect(organization.id).to eq "8f6e474e-e688-4bec-99ba-5dc862594f4b"
39
- expect(organization.name).to eq "My organization"
40
- expect(organization.alias).to eq "myorg"
41
- expect(organization.description).to eq "A single organization"
42
- expect(organization.redirect_url).to eq "https://myapp.acme.com"
43
- expect(organization.enabled).to be true
44
-
45
- expect(organization.domains.size).to eq 2
46
- expect(organization.domains[0]).to be_a KeycloakAdmin::OrganizationDomainRepresentation
47
- expect(organization.domains[0].name).to eq "hello.com"
48
- expect(organization.domains[0].verified).to be false
49
- expect(organization.domains[1]).to be_a KeycloakAdmin::OrganizationDomainRepresentation
50
- expect(organization.domains[1].name).to eq "gmail.com"
51
- expect(organization.domains[1].verified).to be true
52
-
53
- expect(organization.attributes.size).to eq 2
54
- expect(organization.attributes["advanced"].size).to eq 1
55
- expect(organization.attributes["advanced"][0]).to eq "yes"
56
- expect(organization.attributes["days"].size).to eq 2
57
- expect(organization.attributes["days"][0]).to eq "monday"
58
- expect(organization.attributes["days"][1]).to eq "friday"
59
-
60
- expect(organization.members.size).to eq 0
61
- expect(organization.identity_providers.size).to eq 0
62
- end
63
- end
64
- end
@@ -1,57 +0,0 @@
1
- RSpec.describe KeycloakAdmin::ProtocolMapperRepresentation do
2
- describe "#to_json" do
3
- before(:each) do
4
- @mapper = KeycloakAdmin::ProtocolMapperRepresentation.from_hash(
5
- {
6
- "id" => "hello",
7
- "name" => "abcd",
8
- "protocol" => "openid-connect",
9
- "protocolMapper" => "oidc-hardcoded-claim-mapper",
10
- "consentRequired" => false,
11
- "config" => {
12
- "claim.value" => "123456",
13
- "userinfo.token.claim" => "false",
14
- "id.token.claim" => "false",
15
- "access.token.claim" => "true",
16
- "claim.name" => "abcd",
17
- "jsonType.label" => "String",
18
- "access.tokenResponse.claim" => "false"
19
- }
20
- }
21
- )
22
- end
23
-
24
- it "can convert to json" do
25
- expect(@mapper.to_json).to eq "{\"id\":\"hello\",\"config\":{\"claim.value\":\"123456\",\"userinfo.token.claim\":\"false\",\"id.token.claim\":\"false\",\"access.token.claim\":\"true\",\"claim.name\":\"abcd\",\"jsonType.label\":\"String\",\"access.tokenResponse.claim\":\"false\"},\"name\":\"abcd\",\"protocol\":\"openid-connect\",\"protocolMapper\":\"oidc-hardcoded-claim-mapper\"}"
26
- end
27
- end
28
-
29
- describe "array#to_json" do
30
- before(:each) do
31
- @mapper = [
32
- KeycloakAdmin::ProtocolMapperRepresentation.from_hash(
33
- {
34
- "id" => "hello",
35
- "name" => "abcd",
36
- "protocol" => "openid-connect",
37
- "protocolMapper" => "oidc-hardcoded-claim-mapper",
38
- "consentRequired" => false,
39
- "config" => {
40
- "claim.value" => "123456",
41
- "userinfo.token.claim" => "false",
42
- "id.token.claim" => "false",
43
- "access.token.claim" => "true",
44
- "claim.name" => "abcd",
45
- "jsonType.label" => "String",
46
- "access.tokenResponse.claim" => "false"
47
- }
48
- }
49
- )
50
- ]
51
- end
52
-
53
- it "can convert to json" do
54
- expect(@mapper.to_json).to eq "[{\"id\":\"hello\",\"config\":{\"claim.value\":\"123456\",\"userinfo.token.claim\":\"false\",\"id.token.claim\":\"false\",\"access.token.claim\":\"true\",\"claim.name\":\"abcd\",\"jsonType.label\":\"String\",\"access.tokenResponse.claim\":\"false\"},\"name\":\"abcd\",\"protocol\":\"openid-connect\",\"protocolMapper\":\"oidc-hardcoded-claim-mapper\"}]"
55
- end
56
- end
57
- end
@@ -1,37 +0,0 @@
1
- RSpec.describe KeycloakAdmin::RoleRepresentation do
2
- describe "#to_json" do
3
- before(:each) do
4
- @mapper = KeycloakAdmin::RoleRepresentation.from_hash(
5
- {
6
- "id" => "bb79fb10-a7b4-4728-a662-82a4de7844a3",
7
- "name" => "abcd",
8
- "composite" => true,
9
- "clientRole" => false
10
- }
11
- )
12
- end
13
-
14
- it "can convert to json" do
15
- expect(@mapper.to_json).to eq "{\"id\":\"bb79fb10-a7b4-4728-a662-82a4de7844a3\",\"name\":\"abcd\",\"composite\":true,\"clientRole\":false,\"containerId\":null}"
16
- end
17
- end
18
-
19
- describe "array#to_json" do
20
- before(:each) do
21
- @mappers = [
22
- KeycloakAdmin::RoleRepresentation.from_hash(
23
- {
24
- "id" => "bb79fb10-a7b4-4728-a662-82a4de7844a3",
25
- "name" => "abcd",
26
- "composite" => true,
27
- "clientRole" => false
28
- }
29
- )
30
- ]
31
- end
32
-
33
- it "can convert to json" do
34
- expect(@mappers.to_json).to eq "[{\"id\":\"bb79fb10-a7b4-4728-a662-82a4de7844a3\",\"name\":\"abcd\",\"composite\":true,\"clientRole\":false,\"containerId\":null}]"
35
- end
36
- end
37
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe KeycloakAdmin::SessionRepresentation do
4
- describe '.from_hash' do
5
- it 'converts json response to class structure' do
6
- rep = described_class.from_hash({
7
- 'username' => 'test_username',
8
- 'userId' => '95985b21-d884-4bbd-b852-cb8cd365afc2',
9
- 'ipAddress' => '1.1.1.1',
10
- 'start' => 12345678
11
- })
12
- expect(rep.user_id).to eq '95985b21-d884-4bbd-b852-cb8cd365afc2'
13
- expect(rep).to be_a described_class
14
- end
15
- end
16
- end
@@ -1,15 +0,0 @@
1
- RSpec.describe KeycloakAdmin::UserRepresentation do
2
- describe "#to_json" do
3
- before(:each) do
4
- @user = KeycloakAdmin::UserRepresentation.from_hash(
5
- "username" => "test_username",
6
- "createdTimestamp" => Time.at(1559836000).to_i,
7
- "enabled" => true
8
- )
9
- end
10
-
11
- it "can convert to json" do
12
- expect(@user.to_json).to eq '{"id":null,"createdTimestamp":1559836000,"origin":null,"username":"test_username","email":null,"enabled":true,"emailVerified":null,"firstName":null,"lastName":null,"attributes":null,"requiredActions":[],"totp":false,"credentials":[],"federatedIdentities":[]}'
13
- end
14
- end
15
- end
@@ -1,14 +0,0 @@
1
- RSpec.describe KeycloakAdmin::GroupResource do
2
- describe "#resource_url" do
3
- let(:realm_name) { "valid-realm" }
4
- let(:group_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
5
-
6
- before(:each) do
7
- @built_url = KeycloakAdmin.realm(realm_name).group(group_id).resource_url
8
- end
9
-
10
- it "return a proper url" do
11
- expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/groups/95985b21-d884-4bbd-b852-cb8cd365afc2"
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- RSpec.describe KeycloakAdmin::UserResource do
2
- describe "#resource_url" do
3
- let(:realm_name) { "valid-realm" }
4
- let(:user_id) { "95985b21-d884-4bbd-b852-cb8cd365afc2" }
5
-
6
- before(:each) do
7
- @built_url = KeycloakAdmin.realm(realm_name).user(user_id).resource_url
8
- end
9
-
10
- it "return a proper url" do
11
- expect(@built_url).to eq "http://auth.service.io/auth/admin/realms/valid-realm/users/95985b21-d884-4bbd-b852-cb8cd365afc2"
12
- end
13
- end
14
- end
data/spec/spec_helper.rb DELETED
@@ -1,36 +0,0 @@
1
- require_relative "../lib/keycloak-admin"
2
-
3
- require "byebug"
4
-
5
- def configure
6
- KeycloakAdmin.configure do |config|
7
- config.server_url = "http://auth.service.io/auth"
8
- config.server_domain = "auth.service.io"
9
- config.client_id = "admin-cli"
10
- config.client_secret = "aaaaaaaa"
11
- config.client_realm_name = "master2"
12
- config.use_service_account = true
13
- end
14
- end
15
-
16
- RSpec.configure do |config|
17
- config.expect_with :rspec do |expectations|
18
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
19
- end
20
-
21
- configure
22
-
23
- # KeycloakAdmin.config is a global set up once for the whole suite (see 'configure'
24
- # above), not per example, so a token cached in one example would otherwise leak into
25
- # the next one and silently skip its stub_token_client expectations.
26
- config.before(:each) do
27
- KeycloakAdmin.config.clear_cached_token!
28
- end
29
- end
30
-
31
- def stub_token_client
32
- allow_any_instance_of(KeycloakAdmin::TokenClient).to receive(:get).and_return KeycloakAdmin::TokenRepresentation.new(
33
- "test_access_token", "token_type", 3600, "refresh_token",
34
- "refresh_expires_in", "id_token", "not_before_policy", "session_state"
35
- )
36
- end