class Wire4ExamplesTest

noinspection RubyTooManyMethodsInspection

Constants

CLIENT_ID
CLIENT_SECRET
SECRET_KEY
SUBSCRIPTION
USER_KEY

Public Instance Methods

test_different_scopes_for_same_user_credentials_should_return_different_tokens() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 156
def test_different_scopes_for_same_user_credentials_should_return_different_tokens
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."

  spei_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
  spid_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
  codi_general_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
  codi_report_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
  double_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
  assert_not_equal(spei_admin_token, spid_admin_token, 'the tokens should not be equals')
  assert_not_equal(spei_admin_token, codi_general_token, 'the tokens should not be equals')
  assert_not_equal(spei_admin_token, codi_report_token, 'the tokens should not be equals')
  assert_not_equal(spei_admin_token, double_token, 'the tokens should not be equals')
  assert_not_equal(spid_admin_token, double_token, 'the tokens should not be equals')
  assert_not_equal(spid_admin_token, codi_report_token, 'the tokens should not be equals')
  assert_not_equal(codi_general_token, codi_report_token, 'the tokens should not be equals')
  assert_not_equal(double_token, codi_report_token, 'the tokens should not be equals')
  assert_not_equal(double_token, codi_general_token, 'the tokens should not be equals')
end
test_different_scopes_for_same_user_should_return_different_tokens() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 62
def test_different_scopes_for_same_user_should_return_different_tokens
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  general_token = oauth_wire4.obtain_access_token_app('general')
  spei_admin_token = oauth_wire4.obtain_access_token_app('spei_admin')
  spid_admin_token = oauth_wire4.obtain_access_token_app('spid_admin')
  codi_general_token = oauth_wire4.obtain_access_token_app('codi_general')
  codi_report_token = oauth_wire4.obtain_access_token_app('codi_report')
  double_token = oauth_wire4.obtain_access_token_app('spei_admin codi_report')
  assert_not_equal(general_token, spei_admin_token, 'the tokens should not be equals')
  assert_not_equal(general_token, spid_admin_token, 'the tokens should not be equals')
  assert_not_equal(general_token, codi_general_token, 'the tokens should not be equals')
  assert_not_equal(general_token, codi_report_token, 'the tokens should not be equals')
  assert_not_equal(general_token, double_token, 'the tokens should not be equals')
  assert_not_equal(spei_admin_token, spid_admin_token, 'the tokens should not be equals')
  assert_not_equal(codi_general_token, codi_report_token, 'the tokens should not be equals')
  assert_not_equal(double_token, codi_report_token, 'the tokens should not be equals')
  assert_not_equal(double_token, codi_general_token, 'the tokens should not be equals')
end
test_given_bad_credentials_should_raise_error() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 38
def test_given_bad_credentials_should_raise_error
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,'CLIENT_SECRET',Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  assert_raise( Wire4Client::ApiError){oauth_wire4.obtain_access_token_app('general')}
end
test_given_bad_user_credentials_should_raise_error() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 132
def test_given_bad_user_credentials_should_raise_error
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  assert_raise( Wire4Client::ApiError){oauth_wire4.obtain_access_token_app_user(USER_KEY, 'SECRET_KEY','spei_admin')}
end
test_given_many_tokens_for_same_user_credentials_should_keeps_in_cache() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 177
def test_given_many_tokens_for_same_user_credentials_should_keeps_in_cache
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."

  spei_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
  spid_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
  codi_general_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
  codi_report_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
  double_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
  spei_admin_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
  spid_admin_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
  codi_general_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
  codi_report_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
  double_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
  assert_equal(spei_admin_token, spei_admin_token_second, 'the tokens should be equals')
  assert_equal(spid_admin_token, spid_admin_token_second, 'the tokens should be equals')
  assert_equal(codi_general_token, codi_general_token_second, 'the tokens should be equals')
  assert_equal(codi_report_token, codi_report_token_second, 'the tokens should be equals')
  assert_equal(double_token, double_token_second, 'the tokens should be equals')

end
test_given_many_tokens_for_same_user_should_keeps_in_cache() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 83
def test_given_many_tokens_for_same_user_should_keeps_in_cache
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  general_token = oauth_wire4.obtain_access_token_app('general')
  spei_admin_token = oauth_wire4.obtain_access_token_app('spei_admin')
  spid_admin_token = oauth_wire4.obtain_access_token_app('spid_admin')
  codi_general_token = oauth_wire4.obtain_access_token_app('codi_general')
  codi_report_token = oauth_wire4.obtain_access_token_app('codi_report')
  double_token = oauth_wire4.obtain_access_token_app('spei_admin codi_report')
  general_token_second = oauth_wire4.obtain_access_token_app('general')
  spei_admin_token_second = oauth_wire4.obtain_access_token_app('spei_admin')
  spid_admin_token_second = oauth_wire4.obtain_access_token_app('spid_admin')
  codi_general_token_second = oauth_wire4.obtain_access_token_app('codi_general')
  codi_report_token_second = oauth_wire4.obtain_access_token_app('codi_report')
  double_token_second = oauth_wire4.obtain_access_token_app('spei_admin codi_report')
  assert_equal(general_token, general_token_second, 'the tokens should be equals')
  assert_equal(spei_admin_token, spei_admin_token_second, 'the tokens should be equals')
  assert_equal(spid_admin_token, spid_admin_token_second, 'the tokens should be equals')
  assert_equal(codi_general_token, codi_general_token_second, 'the tokens should be equals')
  assert_equal(codi_report_token, codi_report_token_second, 'the tokens should be equals')
  assert_equal(double_token, double_token_second, 'the tokens should be equals')
end
test_given_valid_credentials_should_return_token() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 45
def test_given_valid_credentials_should_return_token
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  token = oauth_wire4.obtain_access_token_app('general')
  assert_not_nil(token, 'the token should not be nil')
end
test_given_valid_user_credentials_should_return_token() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 139
def test_given_valid_user_credentials_should_return_token
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
  assert_not_nil(token, 'the token should not be nil')
end
test_same_credentials_should_return_same_token() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 53
def test_same_credentials_should_return_same_token
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  token = oauth_wire4.obtain_access_token_app('general')
  second_token = oauth_wire4.obtain_access_token_app('general')
  assert_equal(token, second_token, 'the tokens should be equals')
end
test_same_user_credentials_should_return_same_token() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 147
def test_same_user_credentials_should_return_same_token
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
  second_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
  assert_equal(token, second_token, 'the tokens should be equals')
end
test_when_regenerate_token_should_replace_old_token() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 107
def test_when_regenerate_token_should_replace_old_token
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."
  general_token = oauth_wire4.obtain_access_token_app('general')
  spei_admin_token = oauth_wire4.obtain_access_token_app('spei_admin')
  spid_admin_token = oauth_wire4.obtain_access_token_app('spid_admin')
  codi_general_token = oauth_wire4.obtain_access_token_app('codi_general')
  codi_report_token = oauth_wire4.obtain_access_token_app('codi_report')
  double_token = oauth_wire4.obtain_access_token_app('general codi_report')
  puts "#{double_token}"
  general_token_second = oauth_wire4.regenerate_access_token_app('general')
  spei_admin_token_second = oauth_wire4.regenerate_access_token_app('spei_admin')
  spid_admin_token_second = oauth_wire4.regenerate_access_token_app('spid_admin')
  codi_general_token_second = oauth_wire4.regenerate_access_token_app('codi_general')
  codi_report_token_second = oauth_wire4.regenerate_access_token_app('codi_report')
  double_token_second = oauth_wire4.regenerate_access_token_app('general codi_report')
  assert_not_equal(general_token, general_token_second, 'the tokens should not be equals')
  assert_not_equal(spei_admin_token, spei_admin_token_second, 'the tokens should not be equals')
  assert_not_equal(spid_admin_token, spid_admin_token_second, 'the tokens should not be equals')
  assert_not_equal(codi_general_token, codi_general_token_second, 'the tokens should not be equals')
  assert_not_equal(codi_report_token, codi_report_token_second, 'the tokens should not be equals')
  assert_not_equal(double_token, double_token_second, 'the tokens should not be equals')
end
test_when_regenerate_user_token_should_replace_old_token() click to toggle source
# File lib/wire4_auth/tokens_test.rb, line 200
def test_when_regenerate_user_token_should_replace_old_token
  oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
  oauth_wire4.config_default_api_client
  puts "Calling token creation..."

  spei_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
  spid_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
  codi_general_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
  codi_report_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
  double_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
  spei_admin_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
  spid_admin_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
  codi_general_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
  codi_report_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
  double_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
  assert_not_equal(spei_admin_token, spei_admin_token_second, 'the tokens should not be equals')
  assert_not_equal(spid_admin_token, spid_admin_token_second, 'the tokens should not be equals')
  assert_not_equal(codi_general_token, codi_general_token_second, 'the tokens should not be equals')
  assert_not_equal(codi_report_token, codi_report_token_second, 'the tokens should not be equals')
  assert_not_equal(double_token, double_token_second, 'the tokens should not be equals')
end