descope 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +15 -27
- data/.github/workflows/publish-gem.yaml +61 -0
- data/Gemfile +12 -14
- data/Gemfile.lock +46 -101
- data/README.md +56 -19
- data/descope.gemspec +25 -20
- data/examples/ruby/.ruby-version +1 -0
- data/examples/ruby/access_key_app.rb +7 -4
- data/examples/ruby/enchantedlink_app.rb +1 -0
- data/examples/ruby/magiclink_app.rb +1 -0
- data/examples/ruby/management/.ruby-version +1 -0
- data/examples/ruby/management/Gemfile +2 -2
- data/examples/ruby/management/Gemfile.lock +2 -2
- data/examples/ruby/management/access_key_app.rb +2 -0
- data/examples/ruby/management/audit_app.rb +32 -8
- data/examples/ruby/management/authz_app.rb +1 -0
- data/examples/ruby/management/flow_app.rb +1 -0
- data/examples/ruby/management/permission_app.rb +3 -2
- data/examples/ruby/management/role_app.rb +10 -4
- data/examples/ruby/management/tenant_app.rb +1 -0
- data/examples/ruby/management/user_app.rb +1 -0
- data/examples/ruby/oauth_app.rb +1 -0
- data/examples/ruby/otp_app.rb +38 -12
- data/examples/ruby/password_app.rb +8 -7
- data/examples/ruby/saml_app.rb +1 -0
- data/examples/ruby/version_check.rb +17 -0
- data/examples/ruby-on-rails-api/descope/.gitignore +58 -28
- data/examples/ruby-on-rails-api/descope/Gemfile +3 -1
- data/examples/ruby-on-rails-api/descope/Gemfile.lock +121 -90
- data/examples/ruby-on-rails-api/descope/README.md +18 -18
- data/examples/ruby-on-rails-api/descope/app/assets/builds/App.css +62 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/App.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/application.css +20131 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/application.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/application.js +40368 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/application.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/App.css +62 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/App.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/App.js +27979 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/App.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Dashboard.css +62 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Dashboard.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Dashboard.js +27118 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Dashboard.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Home.css +62 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Home.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Home.js +27113 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Home.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Login.css +62 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Login.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Login.js +27131 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Login.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Profile.css +62 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Profile.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Profile.js +27168 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/Profile.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/index.css +62 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/index.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/index.js +28236 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/components/index.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/controllers/application.js +2456 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/controllers/application.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/controllers/index.js +2453 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/controllers/index.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/routes/index.css +62 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/routes/index.css.map +7 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/routes/index.js +27973 -0
- data/examples/ruby-on-rails-api/descope/app/assets/builds/routes/index.js.map +7 -0
- data/examples/ruby-on-rails-api/descope/package-lock.json +1021 -19307
- data/examples/ruby-on-rails-api/descope/package.json +8 -16
- data/examples/ruby-on-rails-api/descope/yarn.lock +459 -10641
- data/lib/descope/api/v1/auth/otp.rb +21 -14
- data/lib/descope/api/v1/auth.rb +37 -25
- data/lib/descope/api/v1/management/access_key.rb +5 -4
- data/lib/descope/api/v1/management/audit.rb +24 -0
- data/lib/descope/api/v1/management/common.rb +5 -1
- data/lib/descope/api/v1/management/role.rb +22 -6
- data/lib/descope/api/v1/management/user.rb +17 -0
- data/lib/descope/mixins/common.rb +6 -13
- data/lib/descope/mixins/http.rb +1 -1
- data/lib/descope/mixins/validation.rb +21 -6
- data/lib/descope/version.rb +1 -1
- data/spec/integration/lib.descope/api/v1/auth/enchantedlink_spec.rb +81 -0
- data/spec/integration/lib.descope/api/v1/auth/magiclink_spec.rb +49 -0
- data/spec/integration/lib.descope/api/v1/auth/otp_spec.rb +103 -0
- data/spec/integration/lib.descope/api/v1/auth/password_spec.rb +41 -0
- data/spec/integration/lib.descope/api/v1/auth/totp_spec.rb +76 -0
- data/spec/integration/lib.descope/api/v1/management/access_key_spec.rb +62 -0
- data/spec/integration/lib.descope/api/v1/management/audit_spec.rb +52 -0
- data/spec/integration/lib.descope/api/v1/management/authz_spec.rb +187 -0
- data/spec/integration/lib.descope/api/v1/management/flow_spec.rb +44 -0
- data/spec/integration/lib.descope/api/v1/management/permissions_spec.rb +27 -0
- data/spec/integration/lib.descope/api/v1/management/project_spec.rb +29 -0
- data/spec/integration/lib.descope/api/v1/management/roles_spec.rb +116 -0
- data/spec/integration/lib.descope/api/v1/management/user_spec.rb +262 -0
- data/spec/lib.descope/api/v1/auth/otp_spec.rb +176 -18
- data/spec/lib.descope/api/v1/auth_spec.rb +50 -1
- data/spec/lib.descope/api/v1/management/access_key_spec.rb +4 -2
- data/spec/lib.descope/api/v1/management/audit_spec.rb +92 -0
- data/spec/lib.descope/api/v1/management/role_spec.rb +35 -6
- data/spec/lib.descope/api/v1/management/user_spec.rb +40 -0
- data/spec/spec_helper.rb +9 -38
- data/spec/support/client_config.rb +5 -1
- data/spec/support/dummy_class.rb +15 -1
- data/spec/support/utils.rb +1 -1
- metadata +77 -133
- data/examples/ruby-on-rails-api/descope/tmp/pids/.keep +0 -0
- data/examples/ruby-on-rails-api/descope/tmp/storage/.keep +0 -0
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Descope::Api::V1::Auth::OTP do
|
6
|
+
before(:all) do
|
7
|
+
@client = DescopeClient.new(Configuration.config)
|
8
|
+
|
9
|
+
dummy_instance = DummyClass.new
|
10
|
+
dummy_instance.extend(Descope::Api::V1::Session)
|
11
|
+
dummy_instance.extend(Descope::Api::V1::Auth::OTP)
|
12
|
+
@instance = dummy_instance
|
13
|
+
@user = build(:user)
|
14
|
+
@test_user = @client.create_test_user(**@user)['user']
|
15
|
+
@client.create_test_user(**@user)
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:all) do
|
19
|
+
@client.logger.info('Cleaning up test users...')
|
20
|
+
all_users = @client.search_all_users
|
21
|
+
all_users['users'].each do |user|
|
22
|
+
if user['middleName'] == 'Ruby SDK User'
|
23
|
+
@client.logger.info("Deleting ruby spec test user #{user['loginIds'][0]}")
|
24
|
+
@client.delete_user(user['loginIds'][0])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# SIGN INs
|
30
|
+
context 'test otp sign-in methods' do
|
31
|
+
it 'should sign in a new test user with otp via EMAIL' do
|
32
|
+
res = @client.generate_otp_for_test_user(
|
33
|
+
method: Descope::Mixins::Common::DeliveryMethod::EMAIL,
|
34
|
+
login_id: @test_user['loginIds'][0]
|
35
|
+
)
|
36
|
+
@client.logger.info("res: #{res}")
|
37
|
+
@client.otp_verify_code(
|
38
|
+
method: Descope::Mixins::Common::DeliveryMethod::EMAIL,
|
39
|
+
login_id: @user[:login_id],
|
40
|
+
code: res['code']
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should sign in a new test user with otp via SMS' do
|
45
|
+
res = @client.generate_otp_for_test_user(
|
46
|
+
method: Descope::Mixins::Common::DeliveryMethod::SMS,
|
47
|
+
login_id: @test_user['loginIds'][0]
|
48
|
+
)
|
49
|
+
@client.logger.info("res: #{res}")
|
50
|
+
@client.otp_verify_code(
|
51
|
+
method: Descope::Mixins::Common::DeliveryMethod::SMS,
|
52
|
+
login_id: @user[:login_id],
|
53
|
+
code: res['code']
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# SIGN UPs
|
59
|
+
context 'test otp sign-up methods' do
|
60
|
+
it 'should sign up with otp via email' do
|
61
|
+
email = 'someone@example.com'
|
62
|
+
allow_any_instance_of(Descope::Api::V1::Auth).to receive(:extract_masked_address).and_return({})
|
63
|
+
expect(@instance).to receive(:post).with(
|
64
|
+
otp_compose_signup_url, { loginId: email, email: '' }
|
65
|
+
)
|
66
|
+
|
67
|
+
expect do
|
68
|
+
@instance.otp_sign_up(method: Descope::Mixins::Common::DeliveryMethod::EMAIL, login_id: email)
|
69
|
+
end.not_to raise_error
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should sign up with otp via SMS' do
|
73
|
+
phone = '+12123354465'
|
74
|
+
allow_any_instance_of(Descope::Api::V1::Auth).to receive(:extract_masked_address).and_return({})
|
75
|
+
expect(@instance).to receive(:post).with(
|
76
|
+
otp_compose_signup_url(Descope::Mixins::Common::DeliveryMethod::SMS), { loginId: phone, phone: '' }
|
77
|
+
)
|
78
|
+
|
79
|
+
expect do
|
80
|
+
@instance.otp_sign_up(method: Descope::Mixins::Common::DeliveryMethod::SMS, login_id: phone)
|
81
|
+
end.not_to raise_error
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should sign up with otp via voice' do
|
85
|
+
phone = '+12123354465'
|
86
|
+
allow_any_instance_of(Descope::Api::V1::Auth).to receive(:extract_masked_address).and_return({})
|
87
|
+
expect(@instance).to receive(:post).with(
|
88
|
+
otp_compose_signup_url(Descope::Mixins::Common::DeliveryMethod::VOICE), { loginId: phone, phone: '' }
|
89
|
+
)
|
90
|
+
|
91
|
+
expect do
|
92
|
+
@instance.otp_sign_up(method: Descope::Mixins::Common::DeliveryMethod::VOICE, login_id: phone)
|
93
|
+
end.not_to raise_error
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should fail to signup with invalid phone number via SMS' do
|
97
|
+
phone = '1$234.90'
|
98
|
+
expect do
|
99
|
+
@instance.otp_sign_up(method: Descope::Mixins::Common::DeliveryMethod::SMS, login_id: phone)
|
100
|
+
end.to raise_error(Descope::AuthException, "Invalid pattern for phone number: #{phone}")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'rotp'
|
5
|
+
|
6
|
+
describe Descope::Api::V1::Auth::Password do
|
7
|
+
before(:all) do
|
8
|
+
@password = SpecUtils.generate_password
|
9
|
+
@new_password = SpecUtils.generate_password
|
10
|
+
@user = build(:user)
|
11
|
+
@client = DescopeClient.new(Configuration.config)
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'test password methods' do
|
15
|
+
it 'should get password policy' do
|
16
|
+
# Get the configured password policy for the project.
|
17
|
+
res = @client.get_password_policy
|
18
|
+
@client.logger.info("Password policy: #{res}")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should sign up with password' do
|
22
|
+
res = @client.password_sign_up(login_id: @user[:login_id], password: @password, user: @user)
|
23
|
+
expect { res }.not_to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should sign in with password' do
|
27
|
+
res = @client.password_sign_in(login_id: @user[:login_id], password: @password)
|
28
|
+
expect { res }.not_to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should replace the password' do
|
32
|
+
res = @client.password_replace(login_id: @user[:login_id], old_password: @password, new_password: @new_password)
|
33
|
+
expect { res }.not_to raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should login with new password' do
|
37
|
+
res = @client.password_sign_in(login_id: @user[:login_id], password: @new_password)
|
38
|
+
expect { res }.not_to raise_error
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'rotp'
|
5
|
+
|
6
|
+
describe Descope::Api::V1::Auth::TOTP do
|
7
|
+
before(:all) do
|
8
|
+
@client = DescopeClient.new(Configuration.config)
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:all) do
|
12
|
+
@client.logger.info('Cleaning up test users...')
|
13
|
+
all_users = @client.search_all_users
|
14
|
+
all_users['users'].each do |user|
|
15
|
+
if user['middleName'] == 'Ruby SDK User'
|
16
|
+
@client.logger.info("Deleting ruby spec test user #{user['loginIds'][0]}")
|
17
|
+
@client.delete_user(user['loginIds'][0])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'test totp methods' do
|
23
|
+
it 'should sign up with totp' do
|
24
|
+
# Initiate a TOTP sign-up process for a new end user.
|
25
|
+
# Descope will generate a TOTP key (also called a secret or seed) that will be entered into the end user's
|
26
|
+
# authenticator app so that TOTP codes can be successfully verified.
|
27
|
+
# The new end user will be registered after the full TOTP sign-up flow has successfully completed.
|
28
|
+
|
29
|
+
user = build(:user)
|
30
|
+
|
31
|
+
@client.logger.info('1. Sign up TOTP')
|
32
|
+
totp_key = @client.totp_sign_up(login_id: user[:login_id], user:)['key']
|
33
|
+
totp = ROTP::TOTP.new(totp_key)
|
34
|
+
p "Current OTP: #{totp.now}"
|
35
|
+
|
36
|
+
@client.logger.info('2. TOTP sign in')
|
37
|
+
login_res = @client.totp_sign_in_code(login_id: user[:login_id], code: totp.now)
|
38
|
+
@client.logger.info("login_res: #{login_res}")
|
39
|
+
refresh_token = login_res['refreshSessionToken']['jwt']
|
40
|
+
|
41
|
+
@client.logger.info('3. Verify email')
|
42
|
+
my_details = @client.me(refresh_token)
|
43
|
+
expect(my_details['email']).to eq(user[:email])
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should add or update totp key' do
|
47
|
+
# Add or update TOTP key for existing end user
|
48
|
+
# Update the email address of an end user, after verifying the authenticity of the end user using OTP.
|
49
|
+
|
50
|
+
user = build(:user)
|
51
|
+
|
52
|
+
@client.logger.info('1. Sign up TOTP')
|
53
|
+
totp_key = @client.totp_sign_up(login_id: user[:login_id], user:)['key']
|
54
|
+
totp = ROTP::TOTP.new(totp_key)
|
55
|
+
p "Current OTP: #{totp.now}"
|
56
|
+
|
57
|
+
@client.logger.info('2. TOTP sign in')
|
58
|
+
login_res = @client.totp_sign_in_code(login_id: user[:login_id], code: totp.now)
|
59
|
+
@client.logger.info("login_res: #{login_res}")
|
60
|
+
refresh_token = login_res['refreshSessionToken']['jwt']
|
61
|
+
|
62
|
+
@client.logger.info('3. Add or update TOTP key')
|
63
|
+
new_key = @client.totp_add_update_key(login_id: user[:login_id], refresh_token:)['key']
|
64
|
+
new_totp = ROTP::TOTP.new(new_key)
|
65
|
+
p "New OTP: #{totp.now}"
|
66
|
+
|
67
|
+
@client.logger.info('4. TOTP sign in with new key')
|
68
|
+
login_res = @client.totp_sign_in_code(login_id: user[:login_id], code: new_totp.now)
|
69
|
+
refresh_token = login_res['refreshSessionToken']['jwt']
|
70
|
+
|
71
|
+
@client.logger.info('5. Verify email')
|
72
|
+
my_details = @client.me(refresh_token)
|
73
|
+
expect(my_details['email']).to eq(user[:email])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Descope::Api::V1::Management::AccessKey do
|
6
|
+
before(:all) do
|
7
|
+
@client = DescopeClient.new(Configuration.config)
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'perform access key methods like create, delete load' do
|
11
|
+
before(:all) do
|
12
|
+
@key_name = 'Ruby SDK Test Key'
|
13
|
+
|
14
|
+
keys = @client.search_all_access_keys['keys']
|
15
|
+
keys.each do |key|
|
16
|
+
if key['name'] == @key_name
|
17
|
+
@client.delete_access_key(key['id'])
|
18
|
+
@client.logger.info("deleting test access key #{@key_name}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
res = @client.search_all_tenants(names: ['some-new-tenant'])
|
23
|
+
res['tenants'].each do |tenant|
|
24
|
+
@client.delete_tenant(tenant['id'])
|
25
|
+
end
|
26
|
+
|
27
|
+
@client.logger.info('Creating tenant with name: some-new-tenant')
|
28
|
+
@tenant_id = @client.create_tenant(name: 'some-new-tenant')['id']
|
29
|
+
@client.logger.info('creating access key')
|
30
|
+
@access_key = @client.create_access_key(name: @key_name, key_tenants: [{ tenant_id: @tenant_id }])
|
31
|
+
sleep 60
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should create the access key and load it' do
|
35
|
+
response = @client.load_access_key(@access_key['key']['id'])
|
36
|
+
expect(response['key']['name']).to eq(@key_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should update the access key' do
|
40
|
+
new_name = 'Ruby SDK Test Key Updated'
|
41
|
+
@client.logger.info("access key id: #{@access_key['key']['id']}")
|
42
|
+
response = @client.update_access_key(id: @access_key['key']['id'], name: new_name)
|
43
|
+
expect(response['key']['name']).to eq(new_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should deactivate the access key' do
|
47
|
+
response = @client.deactivate_access_key(@access_key['key']['id'])
|
48
|
+
@client.logger.info("deactivate key response: #{response}")
|
49
|
+
# expect(response['key']['status']).to eq('DEACTIVATED')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should activate the access key' do
|
53
|
+
response = @client.activate_access_key(@access_key['key']['id'])
|
54
|
+
@client.logger.info("activate key response: #{response}")
|
55
|
+
end
|
56
|
+
|
57
|
+
after(:all) do
|
58
|
+
@client.delete_access_key(@access_key['key']['id'])
|
59
|
+
@client.delete_tenant(@tenant_id)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Descope::Api::V1::Management::Audit do
|
6
|
+
before(:all) do
|
7
|
+
@client = DescopeClient.new(Configuration.config)
|
8
|
+
@client.logger.info('Deleting all tenants for Ruby SDK...')
|
9
|
+
@client.search_all_tenants(names: ['Ruby-SDK-test'])['tenants'].each do |tenant|
|
10
|
+
@client.logger.info("Deleting tenant: #{tenant['name']}")
|
11
|
+
@client.delete_tenant(tenant['id'])
|
12
|
+
end
|
13
|
+
@client.logger.info('Cleanup completed. Starting tests...')
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:all) do
|
17
|
+
all_users = @client.search_all_users
|
18
|
+
all_users['users'].each do |user|
|
19
|
+
if user['middleName'] == 'Ruby SDK User'
|
20
|
+
puts "Deleting ruby spec test user #{user['loginIds'][0]}"
|
21
|
+
@client.delete_user(user['loginIds'][0])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should search the audit trail for user operations' do
|
27
|
+
res = @client.audit_search(actions: ['LoginSucceed'])
|
28
|
+
expect(res).to be_a(Hash)
|
29
|
+
expect(res['audits']).to be_a(Array)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should create a new audit event' do
|
33
|
+
# Create tenants
|
34
|
+
@client.logger.info('creating Ruby-SDK-test tenant')
|
35
|
+
tenant_id = @client.create_tenant(name: 'Ruby-SDK-test')['id']
|
36
|
+
|
37
|
+
# Create a user (actor)
|
38
|
+
user = build(:user)
|
39
|
+
created_user = @client.create_user(**user)['user']
|
40
|
+
|
41
|
+
expect do
|
42
|
+
res = @client.audit_create_event(
|
43
|
+
action: 'pencil.created',
|
44
|
+
type: 'info',
|
45
|
+
tenant_id:,
|
46
|
+
actor_id: created_user['loginIds'][0],
|
47
|
+
data: { 'key' => 'value' }
|
48
|
+
)
|
49
|
+
expect(res).to eq({})
|
50
|
+
end.not_to raise_error
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,187 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Descope::Api::V1::Management::Authz do
|
6
|
+
before(:all) do
|
7
|
+
@client = DescopeClient.new(Configuration.config)
|
8
|
+
puts 'authz schema delete'
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'authz ops' do
|
12
|
+
before(:all) do
|
13
|
+
@client.authz_delete_schema
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should create a new schema' do
|
17
|
+
puts 'Creating the ReBAC schema...'
|
18
|
+
schema = {
|
19
|
+
name: '1.0',
|
20
|
+
namespaces: [
|
21
|
+
{
|
22
|
+
name: 'group',
|
23
|
+
relationDefinitions: [
|
24
|
+
{
|
25
|
+
name: 'member'
|
26
|
+
},
|
27
|
+
{
|
28
|
+
name: 'owner'
|
29
|
+
}
|
30
|
+
]
|
31
|
+
},
|
32
|
+
{
|
33
|
+
name: 'note',
|
34
|
+
relationDefinitions: [
|
35
|
+
{
|
36
|
+
name: 'owner'
|
37
|
+
},
|
38
|
+
{
|
39
|
+
name: 'editor',
|
40
|
+
complexDefinition: {
|
41
|
+
nType: 'union',
|
42
|
+
children: [
|
43
|
+
{
|
44
|
+
nType: 'child',
|
45
|
+
expression: {
|
46
|
+
neType: 'self'
|
47
|
+
}
|
48
|
+
},
|
49
|
+
{
|
50
|
+
nType: 'child',
|
51
|
+
expression: {
|
52
|
+
neType: 'targetSet',
|
53
|
+
targetRelationDefinition: 'owner',
|
54
|
+
targetRelationDefinitionNamespace: 'note'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
},
|
60
|
+
{
|
61
|
+
name: 'viewer',
|
62
|
+
complexDefinition: {
|
63
|
+
nType: 'union',
|
64
|
+
children: [
|
65
|
+
{
|
66
|
+
nType: 'child',
|
67
|
+
expression: {
|
68
|
+
neType: 'self'
|
69
|
+
}
|
70
|
+
},
|
71
|
+
{
|
72
|
+
nType: 'child',
|
73
|
+
expression: {
|
74
|
+
neType: 'targetSet',
|
75
|
+
targetRelationDefinition: 'editor',
|
76
|
+
targetRelationDefinitionNamespace: 'note'
|
77
|
+
}
|
78
|
+
}
|
79
|
+
]
|
80
|
+
}
|
81
|
+
}
|
82
|
+
]
|
83
|
+
}
|
84
|
+
]
|
85
|
+
}
|
86
|
+
@client.authz_save_schema(schema:, upgrade: true)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should create relation definition' do
|
90
|
+
@client.authz_save_relation_definition(
|
91
|
+
relation_definition: {
|
92
|
+
name: 'owner'
|
93
|
+
},
|
94
|
+
namespace: 'group'
|
95
|
+
)
|
96
|
+
@client.authz_save_relation_definition(
|
97
|
+
relation_definition: {
|
98
|
+
name: 'member'
|
99
|
+
},
|
100
|
+
namespace: 'group'
|
101
|
+
)
|
102
|
+
@client.authz_save_relation_definition(
|
103
|
+
relation_definition: {
|
104
|
+
name: 'owner'
|
105
|
+
},
|
106
|
+
namespace: 'note'
|
107
|
+
)
|
108
|
+
@client.authz_save_relation_definition(
|
109
|
+
relation_definition: {
|
110
|
+
name: 'editor',
|
111
|
+
complexDefinition: {
|
112
|
+
nType: 'union',
|
113
|
+
children: [
|
114
|
+
{
|
115
|
+
nType: 'child',
|
116
|
+
expression: {
|
117
|
+
neType: 'self'
|
118
|
+
}
|
119
|
+
},
|
120
|
+
{
|
121
|
+
nType: 'child',
|
122
|
+
expression: {
|
123
|
+
neType: 'targetSet',
|
124
|
+
targetRelationDefinition: 'owner',
|
125
|
+
targetRelationDefinitionNamespace: 'note'
|
126
|
+
}
|
127
|
+
}
|
128
|
+
]
|
129
|
+
}
|
130
|
+
},
|
131
|
+
namespace: 'note'
|
132
|
+
)
|
133
|
+
@client.authz_save_relation_definition(
|
134
|
+
relation_definition: {
|
135
|
+
name: 'viewer',
|
136
|
+
complexDefinition: {
|
137
|
+
nType: 'union',
|
138
|
+
children: [
|
139
|
+
{
|
140
|
+
nType: 'child',
|
141
|
+
expression: {
|
142
|
+
neType: 'self'
|
143
|
+
}
|
144
|
+
},
|
145
|
+
{
|
146
|
+
nType: 'child',
|
147
|
+
expression: {
|
148
|
+
neType: 'targetSet',
|
149
|
+
targetRelationDefinition: 'editor',
|
150
|
+
targetRelationDefinitionNamespace: 'note'
|
151
|
+
}
|
152
|
+
}
|
153
|
+
]
|
154
|
+
}
|
155
|
+
},
|
156
|
+
namespace: 'note'
|
157
|
+
)
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should create a relation between a resource and user' do
|
161
|
+
@client.authz_create_relations(
|
162
|
+
[
|
163
|
+
{
|
164
|
+
"resource": 'some-doc',
|
165
|
+
"relationDefinition": 'owner',
|
166
|
+
"namespace": 'note',
|
167
|
+
"target": 'user1'
|
168
|
+
}
|
169
|
+
]
|
170
|
+
)
|
171
|
+
|
172
|
+
# Check if target has the relevant relation
|
173
|
+
# The answer should be true because an owner is also a viewer
|
174
|
+
relations = @client.authz_has_relations?(
|
175
|
+
[
|
176
|
+
{
|
177
|
+
"resource": 'some-doc',
|
178
|
+
"relationDefinition": 'viewer',
|
179
|
+
"namespace": 'note',
|
180
|
+
"target": 'user1'
|
181
|
+
}
|
182
|
+
]
|
183
|
+
)
|
184
|
+
expect(relations['relationQueries'][0]['hasRelation']).to be_truthy
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Descope::Api::V1::Management::Flow do
|
6
|
+
before(:all) do
|
7
|
+
@client = DescopeClient.new(Configuration.config)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should return a list of flows' do
|
11
|
+
flows = @client.list_or_search_flows['flows']
|
12
|
+
expect(flows.length).to be > 5
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should search for the sign-up-or-in flow' do
|
16
|
+
flows = @client.list_or_search_flows(['sign-up-or-in'])['flows']
|
17
|
+
expect(flows.length).to eq(1)
|
18
|
+
expect(flows[0]['name']).to eq('Sign Up or In')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should export the sign-up-or-in flow' do
|
22
|
+
export = @client.export_flow('sign-up-or-in')
|
23
|
+
expect(export['flow']['name']).to eq('Sign Up or In')
|
24
|
+
expect(export['screens'].length).to be > 1
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should import the sign-up-or-in flow' do
|
28
|
+
flow = @client.export_flow('sign-up-or-in')
|
29
|
+
imported_flow = @client.import_flow(flow_id: 'sign-up-or-in', flow: flow['flow'], screens: flow['screens'])
|
30
|
+
expect(imported_flow).not_to be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should export the current project theme' do
|
34
|
+
theme = @client.export_theme
|
35
|
+
expect(theme['theme']['cssTemplate']).not_to be_empty
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should import the current project theme' do
|
39
|
+
export_theme = @client.export_theme
|
40
|
+
export_theme_current_version = export_theme['theme']['version']
|
41
|
+
imported_theme = @client.import_theme(export_theme)
|
42
|
+
expect(imported_theme['theme']['version']).to be(export_theme_current_version + 1)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Descope::Api::V1::Management::Permission do
|
6
|
+
before(:all) do
|
7
|
+
@client = DescopeClient.new(Configuration.config)
|
8
|
+
@client.load_all_permissions['permissions'].each do |perm|
|
9
|
+
if perm['description'] == 'Ruby SDK'
|
10
|
+
puts "Deleting permission: #{perm['name']}"
|
11
|
+
@client.delete_permission(perm['name'])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should create update and delete a permission' do
|
17
|
+
@client.create_permission(name: 'test_permission', description: 'Ruby SDK')
|
18
|
+
all_permissions = @client.load_all_permissions['permissions']
|
19
|
+
expect(all_permissions.any? { |perm| perm['name'] == 'test_permission' }).to eq(true)
|
20
|
+
@client.update_permission(name: 'test_permission', new_name: 'test_permission_2')
|
21
|
+
all_permissions = @client.load_all_permissions['permissions']
|
22
|
+
expect(all_permissions.any? { |perm| perm['name'] == 'test_permission_2' }).to eq(true)
|
23
|
+
@client.delete_permission('test_permission_2')
|
24
|
+
all_permissions = @client.load_all_permissions['permissions']
|
25
|
+
expect(all_permissions.any? { |perm| perm['name'] == 'test_permission_2' }).to eq(false)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Descope::Api::V1::Management::Project do
|
6
|
+
before(:all) do
|
7
|
+
@client = DescopeClient.new(Configuration.config)
|
8
|
+
@export_output = @client.export_project
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'Test project methods' do
|
12
|
+
after(:all) do
|
13
|
+
@client.rename_project('Ruby-SDK-Prod')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should rename a project' do
|
17
|
+
@client.rename_project('TEST-Ruby-SDK-Prod')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should export a project' do
|
21
|
+
expect(@export_output).to_not be_empty
|
22
|
+
expect(@export_output).to be_a(Hash)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should import a project' do
|
26
|
+
@client.import_project(files: @export_output['files'])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|