Class: Wire4ExamplesTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/wire4_auth/tokens_test.rb

Overview

noinspection RubyTooManyMethodsInspection

Constant Summary collapse

CLIENT_ID =
"6PqWzT6DgbEyLNu7d4YItJyuT2Ea"
CLIENT_SECRET =
"00cRaDHZimyDENOJOQbA5psoVNoa"
USER_KEY =
"[email protected]"
SECRET_KEY =
"e9c24e4aa064a34bd6357400fab7c0"
SUBSCRIPTION =
"73be6d4e-fa70-4732-8eab-a47b2b798a83"

Instance Method Summary collapse

Instance Method Details

#test_different_scopes_for_same_user_credentials_should_return_different_tokensObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# 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_tokensObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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_errorObject



38
39
40
41
42
43
# 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_errorObject



132
133
134
135
136
137
# 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_cacheObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# 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_cacheObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# 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_tokenObject



45
46
47
48
49
50
51
# 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_tokenObject



139
140
141
142
143
144
145
# 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_tokenObject



53
54
55
56
57
58
59
60
# 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_tokenObject



147
148
149
150
151
152
153
154
# 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_tokenObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# 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_tokenObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# 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