-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3569b06
commit 6fcaaff
Showing
23 changed files
with
1,033 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
spec/integration/lib.descope/api/v1/auth/enchantedlink_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
def poll_for_session(descope_client, pending_ref) | ||
max_tries = 15 | ||
i = 0 | ||
done = false | ||
while !done && i < max_tries | ||
begin | ||
i += 1 | ||
@client.logger.info('waiting 4 seconds for session to be created...') | ||
sleep(4) | ||
print '.' | ||
@client.logger.info("Getting session for pending_ref: #{pending_ref}...") | ||
jwt_response = descope_client.enchanted_link_get_session(pending_ref) | ||
done = true | ||
rescue Descope::AuthException, Descope::Unauthorized => e | ||
@client.logger.info("Failed pending session, err: #{e}") | ||
nil | ||
end | ||
|
||
next unless jwt_response | ||
|
||
@client.logger.info("jwt_response: #{jwt_response}") | ||
refresh_token = jwt_response[Descope::Mixins::Common::REFRESH_SESSION_TOKEN_NAME]['jwt'] | ||
|
||
@client.logger.info("refresh_token: #{refresh_token}") | ||
done = true | ||
return refresh_token | ||
end | ||
end | ||
|
||
def verify_session(descope_client: nil, res: nil, user: nil) | ||
raise StandardError, 'Missing required parameters' if descope_client.nil? || res.nil? || user.nil? | ||
|
||
token = res['link'].match(/.+verify\?t=(.+)/)[1] | ||
@client.logger.info("token: #{token}") | ||
|
||
expect do | ||
descope_client.enchanted_link_verify_token(token) | ||
@client.logger.info('EnchantedLink Token Verified! now getting session information...') | ||
@client.logger.info('Polling for session...') | ||
refresh_token = poll_for_session(descope_client, res['pendingRef']) | ||
my_details = descope_client.me(refresh_token) | ||
expect(my_details['email']).to eq(user['email']) | ||
@client.logger.info('EnchantedLink Token Verified via sign in!') | ||
rescue StandardError => e | ||
raise StandardError, "Verification failed - Could not verify token #{e.message}" | ||
|
||
end.to_not raise_error | ||
end | ||
|
||
describe Descope::Api::V1::Auth::EnchantedLink do | ||
before(:all) do | ||
@client = DescopeClient.new(Configuration.config) | ||
end | ||
|
||
after(:all) do | ||
@client.logger.info('Cleaning up test users...') | ||
all_users = @client.search_all_users | ||
all_users['users'].each do |user| | ||
if user['middleName'] == 'Ruby SDK User' | ||
@client.logger.info("Deleting ruby spec test user #{user['loginIds'][0]}") | ||
@client.delete_user(user['loginIds'][0]) | ||
end | ||
end | ||
end | ||
|
||
context 'test EnchantedLink for test user' do | ||
it 'should sign in with enchanted link' do | ||
user = build(:user) | ||
test_user = @client.create_test_user(**user)['user'] | ||
@client.logger.info("Should sign in a test user => #{test_user['loginIds'][0]} with enchanted link...") | ||
res = @client.generate_enchanted_link_for_test_user(login_id: test_user['loginIds'][0], uri: 'http://localhost:3000/verify') | ||
@client.logger.info("res: #{res}") | ||
@client.logger.info('Verifying session...') | ||
verify_session(descope_client: @client, res:, user: test_user) | ||
end | ||
end | ||
end |
49 changes: 49 additions & 0 deletions
49
spec/integration/lib.descope/api/v1/auth/magiclink_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Descope::Api::V1::Auth::MagicLink do | ||
before(:all) do | ||
@client = DescopeClient.new(Configuration.config) | ||
end | ||
|
||
after(:all) do | ||
@client.logger.info('Cleaning up test users...') | ||
all_users = @client.search_all_users | ||
all_users['users'].each do |user| | ||
if user['middleName'] == 'Ruby SDK User' | ||
@client.logger.info("Deleting ruby spec test user #{user['loginIds'][0]}") | ||
@client.delete_user(user['loginIds'][0]) | ||
end | ||
end | ||
end | ||
|
||
context 'test Magiclink for test user' do | ||
it 'should sign in with magiclink' do | ||
user = build(:user) | ||
test_user = @client.create_test_user(**user)['user'] | ||
@client.create_test_user(**user) | ||
res = @client.generate_magic_link_for_test_user( | ||
method: Descope::Mixins::Common::DeliveryMethod::EMAIL, | ||
login_id: test_user['loginIds'][0], | ||
uri: 'http://localhost:3000/verify' | ||
) | ||
@client.logger.info("res: #{res}") | ||
token = res['link'].match(/^http.+verify\?t=(.+)/)[1] | ||
@client.logger.info("token: #{token}") | ||
|
||
expect do | ||
@client.logger.info('Verifying token...') | ||
jwt_response = @client.magiclink_verify_token(token) | ||
@client.logger.info("jwt_response #{jwt_response}") | ||
my_details = @client.me(jwt_response['refreshSessionToken']['jwt']) | ||
@client.logger.info('verifying session...') | ||
expect(my_details['email']).to eq(test_user['email']) | ||
@client.logger.info('Magiclink Token Verified via sign in!') | ||
rescue StandardError => e | ||
raise StandardError, "Verification failed - Could not verify token: #{e.message}" | ||
|
||
end.to_not raise_error | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe Descope::Api::V1::Auth::OTP do | ||
before(:all) do | ||
@client = DescopeClient.new(Configuration.config) | ||
end | ||
|
||
after(:all) do | ||
@client.logger.info('Cleaning up test users...') | ||
all_users = @client.search_all_users | ||
all_users['users'].each do |user| | ||
if user['middleName'] == 'Ruby SDK User' | ||
@client.logger.info("Deleting ruby spec test user #{user['loginIds'][0]}") | ||
@client.delete_user(user['loginIds'][0]) | ||
end | ||
end | ||
end | ||
|
||
context 'test otp sign-in with test user' do | ||
it 'should sign in with otp' do | ||
user = build(:user) | ||
test_user = @client.create_test_user(**user)['user'] | ||
@client.create_test_user(**user) | ||
res = @client.generate_otp_for_test_user( | ||
method: Descope::Mixins::Common::DeliveryMethod::EMAIL, | ||
login_id: test_user['loginIds'][0] | ||
) | ||
@client.logger.info("res: #{res}") | ||
@client.otp_verify_code( | ||
method: Descope::Mixins::Common::DeliveryMethod::EMAIL, | ||
login_id: user[:login_id], | ||
code: res['code'] | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'rotp' | ||
|
||
describe Descope::Api::V1::Auth::Password do | ||
before(:all) do | ||
@password = SpecUtils.generate_password | ||
@new_password = SpecUtils.generate_password | ||
@user = build(:user) | ||
@client = DescopeClient.new(Configuration.config) | ||
end | ||
|
||
context 'test password methods' do | ||
it 'should get password policy' do | ||
# Get the configured password policy for the project. | ||
res = @client.get_password_policy | ||
@client.logger.info("Password policy: #{res}") | ||
end | ||
|
||
it 'should sign up with password' do | ||
res = @client.password_sign_up(login_id: @user[:login_id], password: @password, user: @user) | ||
expect { res }.not_to raise_error | ||
end | ||
|
||
it 'should sign in with password' do | ||
res = @client.password_sign_in(login_id: @user[:login_id], password: @password) | ||
expect { res }.not_to raise_error | ||
end | ||
|
||
it 'should replace the password' do | ||
res = @client.password_replace(login_id: @user[:login_id], old_password: @password, new_password: @new_password) | ||
expect { res }.not_to raise_error | ||
end | ||
|
||
it 'should login with new password' do | ||
res = @client.password_sign_in(login_id: @user[:login_id], password: @new_password) | ||
expect { res }.not_to raise_error | ||
end | ||
end | ||
end |
Oops, something went wrong.