wire4_auth 1.0.3 → 1.0.5

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.
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ # COPYRIGHT © 2017. TCPIP.
5
+ # PATENT PENDING. ALL RIGHTS RESERVED.
6
+ # SPEI GATEWAY IS REGISTERED TRADEMARKS OF TCPIP.
7
+ #
8
+ # This software is confidential and proprietary information of TCPIP.
9
+ # You shall not disclose such Confidential Information and shall use it only
10
+ # in accordance with the company policy.
11
+
12
+ =begin
13
+ #Wire4Auth
14
+
15
+ Fecha de creación: 01 de september, 2020
16
+ author: Juan Mandujano
17
+ version: 1.0
18
+ =end
19
+
20
+ require 'test/unit'
21
+ require 'wire4_auth/auth/oauth_wire4'
22
+ require 'wire4_auth/webhook_verification_signature/utils_compute'
23
+ require 'wire4_client'
24
+
25
+ #noinspection RubyTooManyMethodsInspection
26
+ class Wire4ExamplesTest < Test::Unit::TestCase
27
+
28
+ CLIENT_ID = "6PqWzT6DgbEyLNu7d4YItJyuT2Ea"
29
+
30
+ CLIENT_SECRET = "00cRaDHZimyDENOJOQbA5psoVNoa"
31
+
32
+ USER_KEY = "9548042dccc4790a43c36d919fb677@develop.wire4.mx"
33
+
34
+ SECRET_KEY = "e9c24e4aa064a34bd6357400fab7c0"
35
+
36
+ SUBSCRIPTION = "73be6d4e-fa70-4732-8eab-a47b2b798a83"
37
+
38
+ def test_given_bad_credentials_should_raise_error
39
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,'CLIENT_SECRET',Wire4Auth::EnvironmentEnum::DEVELOPMENT)
40
+ oauth_wire4.config_default_api_client
41
+ puts "Calling token creation..."
42
+ assert_raise( Wire4Client::ApiError){oauth_wire4.obtain_access_token_app('general')}
43
+ end
44
+
45
+ def test_given_valid_credentials_should_return_token
46
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
47
+ oauth_wire4.config_default_api_client
48
+ puts "Calling token creation..."
49
+ token = oauth_wire4.obtain_access_token_app('general')
50
+ assert_not_nil(token, 'the token should not be nil')
51
+ end
52
+
53
+ def test_same_credentials_should_return_same_token
54
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
55
+ oauth_wire4.config_default_api_client
56
+ puts "Calling token creation..."
57
+ token = oauth_wire4.obtain_access_token_app('general')
58
+ second_token = oauth_wire4.obtain_access_token_app('general')
59
+ assert_equal(token, second_token, 'the tokens should be equals')
60
+ end
61
+
62
+ def test_different_scopes_for_same_user_should_return_different_tokens
63
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
64
+ oauth_wire4.config_default_api_client
65
+ puts "Calling token creation..."
66
+ general_token = oauth_wire4.obtain_access_token_app('general')
67
+ spei_admin_token = oauth_wire4.obtain_access_token_app('spei_admin')
68
+ spid_admin_token = oauth_wire4.obtain_access_token_app('spid_admin')
69
+ codi_general_token = oauth_wire4.obtain_access_token_app('codi_general')
70
+ codi_report_token = oauth_wire4.obtain_access_token_app('codi_report')
71
+ double_token = oauth_wire4.obtain_access_token_app('spei_admin codi_report')
72
+ assert_not_equal(general_token, spei_admin_token, 'the tokens should not be equals')
73
+ assert_not_equal(general_token, spid_admin_token, 'the tokens should not be equals')
74
+ assert_not_equal(general_token, codi_general_token, 'the tokens should not be equals')
75
+ assert_not_equal(general_token, codi_report_token, 'the tokens should not be equals')
76
+ assert_not_equal(general_token, double_token, 'the tokens should not be equals')
77
+ assert_not_equal(spei_admin_token, spid_admin_token, 'the tokens should not be equals')
78
+ assert_not_equal(codi_general_token, codi_report_token, 'the tokens should not be equals')
79
+ assert_not_equal(double_token, codi_report_token, 'the tokens should not be equals')
80
+ assert_not_equal(double_token, codi_general_token, 'the tokens should not be equals')
81
+ end
82
+
83
+ def test_given_many_tokens_for_same_user_should_keeps_in_cache
84
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
85
+ oauth_wire4.config_default_api_client
86
+ puts "Calling token creation..."
87
+ general_token = oauth_wire4.obtain_access_token_app('general')
88
+ spei_admin_token = oauth_wire4.obtain_access_token_app('spei_admin')
89
+ spid_admin_token = oauth_wire4.obtain_access_token_app('spid_admin')
90
+ codi_general_token = oauth_wire4.obtain_access_token_app('codi_general')
91
+ codi_report_token = oauth_wire4.obtain_access_token_app('codi_report')
92
+ double_token = oauth_wire4.obtain_access_token_app('spei_admin codi_report')
93
+ general_token_second = oauth_wire4.obtain_access_token_app('general')
94
+ spei_admin_token_second = oauth_wire4.obtain_access_token_app('spei_admin')
95
+ spid_admin_token_second = oauth_wire4.obtain_access_token_app('spid_admin')
96
+ codi_general_token_second = oauth_wire4.obtain_access_token_app('codi_general')
97
+ codi_report_token_second = oauth_wire4.obtain_access_token_app('codi_report')
98
+ double_token_second = oauth_wire4.obtain_access_token_app('spei_admin codi_report')
99
+ assert_equal(general_token, general_token_second, 'the tokens should be equals')
100
+ assert_equal(spei_admin_token, spei_admin_token_second, 'the tokens should be equals')
101
+ assert_equal(spid_admin_token, spid_admin_token_second, 'the tokens should be equals')
102
+ assert_equal(codi_general_token, codi_general_token_second, 'the tokens should be equals')
103
+ assert_equal(codi_report_token, codi_report_token_second, 'the tokens should be equals')
104
+ assert_equal(double_token, double_token_second, 'the tokens should be equals')
105
+ end
106
+
107
+ def test_when_regenerate_token_should_replace_old_token
108
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
109
+ oauth_wire4.config_default_api_client
110
+ puts "Calling token creation..."
111
+ general_token = oauth_wire4.obtain_access_token_app('general')
112
+ spei_admin_token = oauth_wire4.obtain_access_token_app('spei_admin')
113
+ spid_admin_token = oauth_wire4.obtain_access_token_app('spid_admin')
114
+ codi_general_token = oauth_wire4.obtain_access_token_app('codi_general')
115
+ codi_report_token = oauth_wire4.obtain_access_token_app('codi_report')
116
+ double_token = oauth_wire4.obtain_access_token_app('general codi_report')
117
+ puts "#{double_token}"
118
+ general_token_second = oauth_wire4.regenerate_access_token_app('general')
119
+ spei_admin_token_second = oauth_wire4.regenerate_access_token_app('spei_admin')
120
+ spid_admin_token_second = oauth_wire4.regenerate_access_token_app('spid_admin')
121
+ codi_general_token_second = oauth_wire4.regenerate_access_token_app('codi_general')
122
+ codi_report_token_second = oauth_wire4.regenerate_access_token_app('codi_report')
123
+ double_token_second = oauth_wire4.regenerate_access_token_app('general codi_report')
124
+ assert_not_equal(general_token, general_token_second, 'the tokens should not be equals')
125
+ assert_not_equal(spei_admin_token, spei_admin_token_second, 'the tokens should not be equals')
126
+ assert_not_equal(spid_admin_token, spid_admin_token_second, 'the tokens should not be equals')
127
+ assert_not_equal(codi_general_token, codi_general_token_second, 'the tokens should not be equals')
128
+ assert_not_equal(codi_report_token, codi_report_token_second, 'the tokens should not be equals')
129
+ assert_not_equal(double_token, double_token_second, 'the tokens should not be equals')
130
+ end
131
+
132
+ def test_given_bad_user_credentials_should_raise_error
133
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
134
+ oauth_wire4.config_default_api_client
135
+ puts "Calling token creation..."
136
+ assert_raise( Wire4Client::ApiError){oauth_wire4.obtain_access_token_app_user(USER_KEY, 'SECRET_KEY','spei_admin')}
137
+ end
138
+
139
+ def test_given_valid_user_credentials_should_return_token
140
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
141
+ oauth_wire4.config_default_api_client
142
+ puts "Calling token creation..."
143
+ token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
144
+ assert_not_nil(token, 'the token should not be nil')
145
+ end
146
+
147
+ def test_same_user_credentials_should_return_same_token
148
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
149
+ oauth_wire4.config_default_api_client
150
+ puts "Calling token creation..."
151
+ token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
152
+ second_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
153
+ assert_equal(token, second_token, 'the tokens should be equals')
154
+ end
155
+
156
+ def test_different_scopes_for_same_user_credentials_should_return_different_tokens
157
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
158
+ oauth_wire4.config_default_api_client
159
+ puts "Calling token creation..."
160
+
161
+ spei_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
162
+ spid_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
163
+ codi_general_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
164
+ codi_report_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
165
+ double_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
166
+ assert_not_equal(spei_admin_token, spid_admin_token, 'the tokens should not be equals')
167
+ assert_not_equal(spei_admin_token, codi_general_token, 'the tokens should not be equals')
168
+ assert_not_equal(spei_admin_token, codi_report_token, 'the tokens should not be equals')
169
+ assert_not_equal(spei_admin_token, double_token, 'the tokens should not be equals')
170
+ assert_not_equal(spid_admin_token, double_token, 'the tokens should not be equals')
171
+ assert_not_equal(spid_admin_token, codi_report_token, 'the tokens should not be equals')
172
+ assert_not_equal(codi_general_token, codi_report_token, 'the tokens should not be equals')
173
+ assert_not_equal(double_token, codi_report_token, 'the tokens should not be equals')
174
+ assert_not_equal(double_token, codi_general_token, 'the tokens should not be equals')
175
+ end
176
+
177
+ def test_given_many_tokens_for_same_user_credentials_should_keeps_in_cache
178
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
179
+ oauth_wire4.config_default_api_client
180
+ puts "Calling token creation..."
181
+
182
+ spei_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
183
+ spid_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
184
+ codi_general_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
185
+ codi_report_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
186
+ double_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
187
+ spei_admin_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
188
+ spid_admin_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
189
+ codi_general_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
190
+ codi_report_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
191
+ double_token_second = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
192
+ assert_equal(spei_admin_token, spei_admin_token_second, 'the tokens should be equals')
193
+ assert_equal(spid_admin_token, spid_admin_token_second, 'the tokens should be equals')
194
+ assert_equal(codi_general_token, codi_general_token_second, 'the tokens should be equals')
195
+ assert_equal(codi_report_token, codi_report_token_second, 'the tokens should be equals')
196
+ assert_equal(double_token, double_token_second, 'the tokens should be equals')
197
+
198
+ end
199
+
200
+ def test_when_regenerate_user_token_should_replace_old_token
201
+ oauth_wire4 = Wire4Auth::OAuthWire4.new(CLIENT_ID,CLIENT_SECRET,Wire4Auth::EnvironmentEnum::DEVELOPMENT)
202
+ oauth_wire4.config_default_api_client
203
+ puts "Calling token creation..."
204
+
205
+ spei_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
206
+ spid_admin_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
207
+ codi_general_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
208
+ codi_report_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
209
+ double_token = oauth_wire4.obtain_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
210
+ spei_admin_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin')
211
+ spid_admin_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'spid_admin')
212
+ codi_general_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'codi_general')
213
+ codi_report_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'codi_report')
214
+ double_token_second = oauth_wire4.regenerate_access_token_app_user(USER_KEY, SECRET_KEY,'spei_admin, codi_report')
215
+ assert_not_equal(spei_admin_token, spei_admin_token_second, 'the tokens should not be equals')
216
+ assert_not_equal(spid_admin_token, spid_admin_token_second, 'the tokens should not be equals')
217
+ assert_not_equal(codi_general_token, codi_general_token_second, 'the tokens should not be equals')
218
+ assert_not_equal(codi_report_token, codi_report_token_second, 'the tokens should not be equals')
219
+ assert_not_equal(double_token, double_token_second, 'the tokens should not be equals')
220
+ end
221
+
222
+ end
@@ -15,5 +15,5 @@ version: 1.0
15
15
  =end
16
16
 
17
17
  module Wire4Auth
18
- VERSION = '1.0.3'
18
+ VERSION = '1.0.5'
19
19
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.required_ruby_version = ">= 1.9"
33
33
 
34
34
  s.add_runtime_dependency 'oauth2', '~> 1.4', '>= 1.4.3'
35
- s.add_runtime_dependency 'wire4_client', '~> 1.0', '>= 1.0.3'
35
+ s.add_runtime_dependency 'wire4_client', '~> 1.0', '>= 1.0.5'
36
36
 
37
37
  s.add_development_dependency 'test-unit', '~> 3.3', '>= 3.3.5'
38
38
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wire4_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wire4
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-28 00:00:00.000000000 Z
11
+ date: 2020-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '1.0'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 1.0.3
42
+ version: 1.0.5
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '1.0'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 1.0.3
52
+ version: 1.0.5
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: test-unit
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -78,12 +78,12 @@ extensions: []
78
78
  extra_rdoc_files: []
79
79
  files:
80
80
  - Gemfile
81
- - Gemfile.lock
82
81
  - lib/wire4_auth.rb
83
82
  - lib/wire4_auth/auth/oauth_wire4.rb
84
83
  - lib/wire4_auth/core/cached_token.rb
85
84
  - lib/wire4_auth/core/environment_enum.rb
86
85
  - lib/wire4_auth/testing.rb
86
+ - lib/wire4_auth/tokens_test.rb
87
87
  - lib/wire4_auth/version.rb
88
88
  - lib/wire4_auth/webhook_verification_signature/utils_compute.rb
89
89
  - wire4_auth.gemspec
@@ -1,51 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- wire4_auth (1.0.3)
5
- oauth2 (~> 1.4, >= 1.4.3)
6
- wire4_client (~> 1.0, >= 1.0.3)
7
-
8
- PATH
9
- remote: /Users/saintiago/tcpip/git-repositories/speiok/wire4-api-sdk-ruby/sdk-client
10
- specs:
11
- wire4_client (1.0.3)
12
- json (~> 2.1, >= 2.1.0)
13
- typhoeus (~> 1.0, >= 1.0.1)
14
-
15
- GEM
16
- remote: https://rubygems.org/
17
- specs:
18
- ethon (0.12.0)
19
- ffi (>= 1.3.0)
20
- faraday (1.0.0)
21
- multipart-post (>= 1.2, < 3)
22
- ffi (1.12.1)
23
- json (2.3.0)
24
- jwt (2.2.1)
25
- multi_json (1.14.1)
26
- multi_xml (0.6.0)
27
- multipart-post (2.1.1)
28
- oauth2 (1.4.3)
29
- faraday (>= 0.8, < 2.0)
30
- jwt (>= 1.0, < 3.0)
31
- multi_json (~> 1.3)
32
- multi_xml (~> 0.5)
33
- rack (>= 1.2, < 3)
34
- power_assert (1.1.3)
35
- rack (2.1.2)
36
- test-unit (3.3.5)
37
- power_assert
38
- typhoeus (1.3.1)
39
- ethon (>= 0.9.0)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- oauth2 (~> 1.4.3)
46
- test-unit (~> 3.3, >= 3.3.5)
47
- wire4_auth!
48
- wire4_client (~> 1.0.3)!
49
-
50
- BUNDLED WITH
51
- 1.17.3