telesign_lib 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,225 @@
1
+ module TeleSign
2
+ class PhoneId
3
+ include Helpers
4
+
5
+ attr_accessor :conn, :customer_id, :secret_key
6
+
7
+ def initialize opts = {}
8
+ @conn = opts[:conn]
9
+ @customer_id = opts[:customer_id]
10
+ @secret_key = opts[:secret_key]
11
+ end
12
+
13
+ def standard phone_number
14
+ # Retrieves the standard set of details about the specified phone number.
15
+ # This includes the type of phone (e.g., land line or mobile),
16
+ # and it's approximate geographic location.
17
+
18
+ # * - Parameters
19
+ # -
20
+ # * - `phone_number`
21
+ # - The phone number you want details about. You must specify the phone number
22
+ # in its entirety. That is, it must begin with the country code, followed by
23
+ # the area code, and then by the local number.
24
+ # For example, you would specify the phone number (310) 555-1212 as 13105551212.
25
+
26
+ # **Example**::
27
+
28
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
29
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
30
+ # phone_number = "13107409700"
31
+
32
+ # phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object.
33
+
34
+ # try:
35
+ # phone_info = phoneid.standard(phone_number)
36
+
37
+ # except AuthorizationError as ex:
38
+ # # API authorization failed. Check the API response for details.
39
+ # ...
40
+
41
+ # except TeleSignError as ex:
42
+ # # Failed to completely execute the PhoneID service. Check the API response
43
+ # # for details. Data returned might be incomplete or invalid.
44
+ # ...
45
+
46
+ resource = "/v1/phoneid/standard/%s" % phone_number
47
+ method = 'GET'
48
+
49
+ headers = TeleSign::Auth.generate_auth_headers(
50
+ customer_id: @customer_id,
51
+ secret_key: @secret_key,
52
+ resource: resource,
53
+ method: method)
54
+
55
+ response = @conn.get do |req|
56
+ req.url resource
57
+ req.headers = headers
58
+ # proxies=@proxy
59
+ end
60
+
61
+ return TeleSign::Response.new validate_response(response), response
62
+ end
63
+
64
+ def score phone_number, use_case_code
65
+ # Retrieves a score for the specified phone number.
66
+ # This ranks the phone number's "risk level" on a scale from 0 to 1000,
67
+ # so you can code your web application to handle particular use cases
68
+ # (e.g., to stop things like chargebacks, identity theft, fraud, and spam).
69
+
70
+ # * - Parameters
71
+ # -
72
+ # * - `phone_number`
73
+ # - The phone number you want details about. You must specify the phone number in its entirety.
74
+ # That is, it must begin with the country code, followed by the area code, and then by the local number.
75
+ # For example, you would specify the phone number (310) 555-1212 as 13105551212.
76
+ # * - `use_case_code`
77
+ # - A four letter code used to specify a particular usage scenario for the web service.
78
+
79
+ # The following table list the available use-case codes, and includes a description of each.
80
+
81
+ # http://docs.telesign.com/rest/content/xt/xt-use-case-codes.html#xref-use-case-codes
82
+
83
+ # **Example**::
84
+
85
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
86
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
87
+ # phone_number = "13107409700"
88
+ # use_case_code = "ATCK"
89
+
90
+ # phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object.
91
+
92
+ # try:
93
+ # score_info = phoneid.score(phone_number, use_case_code)
94
+ # except AuthorizationError as ex:
95
+ # ...
96
+ # except TeleSignError as ex:
97
+ # ...
98
+
99
+ resource = "/v1/phoneid/score/%s" % phone_number
100
+ method = 'GET'
101
+
102
+ headers = TeleSign::Auth.generate_auth_headers(
103
+ customer_id: @customer_id,
104
+ secret_key: @secret_key,
105
+ resource: resource,
106
+ method: method)
107
+
108
+ response = @conn.get do |req|
109
+ req.url resource
110
+ req.params[:ucid] = use_case_code
111
+ req.headers = headers
112
+ # proxies=@proxy
113
+ end
114
+
115
+ return TeleSign::Response.new validate_response(response), response
116
+ end
117
+
118
+ def contact phone_number, use_case_code
119
+ # In addition to the information retrieved by **standard**,
120
+ # this service provides the Name & Address associated with the specified phone number.
121
+
122
+ # * - Parameters
123
+ # -
124
+ # * - `phone_number`
125
+ # - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212.
126
+ # * - `use_case_code`
127
+ # - A four letter code used to specify a particular usage scenario for the web service.
128
+
129
+ # http://docs.telesign.com/rest/content/xt/xt-use-case-codes.html#xref-use-case-codes
130
+
131
+ # **Example**::
132
+
133
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
134
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
135
+ # phone_number = "13107409700"
136
+ # use_case_code = "LEAD"
137
+
138
+ # phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object.
139
+
140
+ # try:
141
+ # phone_info = phoneid.contact(phone_number, use_case_code)
142
+ # except AuthorizationError as ex:
143
+ # # API authorization failed, the API response should tell you the reason
144
+ # ...
145
+ # except TeleSignError as ex:
146
+ # # failed to completely execute the PhoneID service, check the API response
147
+ # # for details; data returned may be incomplete or not be valid
148
+ # ...
149
+
150
+ resource = "/v1/phoneid/contact/%s" % phone_number
151
+ method = 'GET'
152
+
153
+ headers = TeleSign::Auth.generate_auth_headers(
154
+ customer_id: @customer_id,
155
+ secret_key: @secret_key,
156
+ resource: resource,
157
+ method: method)
158
+
159
+ response = @conn.get do |req|
160
+ req.url resource
161
+ req.params[:ucid] = use_case_code
162
+ req.headers = headers
163
+ # proxies=@proxy
164
+ end
165
+
166
+ return TeleSign::Response.new validate_response(response), response
167
+ end
168
+
169
+ def live phone_number, use_case_code
170
+ # In addition to the information retrieved by **standard**,
171
+ # this service provides actionable data associated with the specified phone number.
172
+
173
+ # * - Parameters
174
+ # -
175
+ # * - `phone_number`
176
+ # - The phone number you want details about. You must specify the phone number in its entirety.
177
+ # That is, it must begin with the country code, followed by the area code,
178
+ # and then by the local number.
179
+ # For example, you would specify the phone number (310) 555-1212 as 13105551212.
180
+ # * - `use_case_code`
181
+ # - A four letter code used to specify a particular usage scenario for the web service.
182
+
183
+ # The following table list the available use-case codes, and includes a description of each.
184
+
185
+ # http://docs.telesign.com/rest/content/xt/xt-use-case-codes.html#xref-use-case-codes
186
+
187
+ # **Example**::
188
+
189
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
190
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
191
+ # phone_number = "13107409700"
192
+ # use_case_code = "RXPF"
193
+
194
+ # phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object.
195
+
196
+ # try:
197
+ # phone_info = phoneid.live(phone_number, use_case_code)
198
+ # except AuthorizationError as ex:
199
+ # # API authorization failed, the API response should tell you the reason
200
+ # ...
201
+ # except TeleSignError as ex:
202
+ # # failed to completely execute the PhoneID service, check the API response
203
+ # # for details; data returned may be incomplete or not be valid
204
+ # ...
205
+
206
+ resource = "/v1/phoneid/live/%s" % phone_number
207
+ method = 'GET'
208
+
209
+ headers = TeleSign::Auth.generate_auth_headers(
210
+ customer_id: @customer_id,
211
+ secret_key: @secret_key,
212
+ resource: resource,
213
+ method: method)
214
+
215
+ response = @conn.get do |req|
216
+ req.url resource
217
+ req.params[:ucid] = use_case_code
218
+ req.headers = headers
219
+ # proxies=@proxy
220
+ end
221
+
222
+ return TeleSign::Response.new validate_response(response), response
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,13 @@
1
+ module TeleSign
2
+ class Response
3
+ attr_accessor :data, :headers, :status, :raw_data, :verify_code
4
+
5
+ def initialize data, http_response, verify_code=nil
6
+ @data = data
7
+ @headers = http_response.headers
8
+ @status = http_response.status
9
+ @raw_data = http_response.body
10
+ @verify_code = verify_code
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ module TeleSign
2
+ class TeleSignError < ::StandardError
3
+ # The **exceptions** base class.
4
+
5
+ # * - Attributes
6
+ # -
7
+ # * - `data`
8
+ # - The data returned by the service, in a dictionary form.
9
+ # * - `http_response`
10
+ # - The full HTTP Response object, including the HTTP status code, headers, and raw returned data.
11
+
12
+ attr_accessor :errors, :headers, :status, :data
13
+
14
+ def initialize response_json, http_response
15
+ @errors = response_json['errors']
16
+ @headers = http_response.headers
17
+ @status = http_response.status
18
+ @data = http_response.body
19
+ super()
20
+ end
21
+
22
+ def to_s
23
+ @errors.inject(''){|ret, x| ret += "#{x['description']}\n" }
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ module TeleSign
2
+ class ValidationError < TeleSignError
3
+ # """
4
+ # The submitted data failed the intial validation, and the service was not executed.
5
+
6
+ # * - Attributes
7
+ # -
8
+ # * - `data`
9
+ # - The data returned by the service, in a dictionary form.
10
+ # * - `http_response`
11
+ # - The full HTTP Response object, including the HTTP status code, headers, and raw returned data.
12
+
13
+ # """
14
+
15
+ def initialize errors, http_response
16
+ super
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,231 @@
1
+ module TeleSign
2
+ class Verify
3
+ include Helpers
4
+
5
+ attr_accessor :conn, :customer_id, :secret_key
6
+
7
+ def initialize opts = {}
8
+ @conn = opts[:conn]
9
+ @customer_id = opts[:customer_id]
10
+ @secret_key = opts[:secret_key]
11
+ end
12
+
13
+ # The **Verify** class exposes two services for sending users a verification token (a three to five-digit number).
14
+ # You can use this mechanism to simply test whether you can reach users at the phone number they supplied,
15
+ # or you can have them use the token to authenticate themselves with your web application.
16
+
17
+ # This class also exposes a service that is used in conjunction with the first two services,
18
+ # in that it allows you to confirm the result of the authentication.
19
+
20
+ # You can use this verification factor in combination with username & password to provide two-factor authentication for higher security.
21
+
22
+ def sms opts = {}
23
+ phone_number = opts[:phone_number]
24
+ verify_code = opts[:verify_code]
25
+ language = opts[:language] || 'en-US'
26
+ template = opts[:template] || ''
27
+
28
+ # Sends a text message containing the verification code, to the specified phone number (supported for mobile phones only).
29
+
30
+ # * - Parameters
31
+ # -
32
+ # * - `phone_number`
33
+ # - The phone number to receive the text message. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212.
34
+ # * - `verify_code`
35
+ # - (optional) The verification code to send to the user. If omitted, TeleSign will automatically generate a random value for you.
36
+ # * - `language`
37
+ # - (optional) The written language used in the message. The default is English.
38
+ # * - `template`
39
+ # - (optional) A standard form for the text message. It must contain the token ``$$CODE$$``, which TeleSign auto-populates with the verification code.
40
+
41
+ # **Example**::
42
+
43
+ # from telesign.api import Verify
44
+ # from telesign.exceptions import AuthorizationError, TeleSignError
45
+
46
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
47
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
48
+ # phone_number = "13107409700"
49
+
50
+ # verify = Verify(cust_id, secret_key) # Instantiate a Verify object.
51
+
52
+ # try:
53
+ # phone_info = verify.sms(phone_number)
54
+ # except AuthorizationError as ex:
55
+ # # API authorization failed, the API response should tell you the reason
56
+ # ...
57
+ # except TeleSignError as ex:
58
+ # # failed to execute the Verify service, check the API response for details
59
+ # ...
60
+
61
+ # # When the user inputs the validation code, you can verify that it matches the one that you sent.
62
+ # if (phone_info != None):
63
+ # try:
64
+ # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code)
65
+ # except AuthorizationError as ex:
66
+ # ...
67
+ # except TeleSignError as ex:
68
+ # ...
69
+
70
+ if verify_code.nil?
71
+ verify_code = random_with_N_digits(5)
72
+ end
73
+
74
+ resource = '/v1/verify/sms'
75
+ method = 'POST'
76
+
77
+ fields = {
78
+ phone_number: phone_number,
79
+ language: language,
80
+ verify_code: verify_code,
81
+ template: template}
82
+
83
+ headers = TeleSign::Auth.generate_auth_headers(
84
+ customer_id: @customer_id,
85
+ secret_key: @secret_key,
86
+ resource: resource,
87
+ method: method,
88
+ fields: fields)
89
+
90
+ response = @conn.post do |req|
91
+ req.url resource
92
+ req.body = URI.encode_www_form(fields)
93
+ req.headers = headers
94
+ # proxies=@proxy
95
+ end
96
+
97
+ return TeleSign::Response.new validate_response(response), response, verify_code
98
+ end
99
+
100
+ def call opts = {}
101
+ phone_number = opts[:phone_number]
102
+ verify_code = opts[:verify_code]
103
+ language = opts[:language] || 'en-US'
104
+
105
+ # Calls the specified phone number, and using speech synthesis, speaks the verification code to the user.
106
+
107
+ # * - Parameters
108
+ # -
109
+ # * - `phone_number`
110
+ # - The phone number to receive the text message. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212.
111
+ # * - `verify_code`
112
+ # - (optional) The verification code to send to the user. If omitted, TeleSign will automatically generate a random value for you.
113
+ # * - `language`
114
+ # - (optional) The written language used in the message. The default is English.
115
+
116
+
117
+ # **Example**::
118
+
119
+ # from telesign.api import Verify
120
+ # from telesign.exceptions import AuthorizationError, TeleSignError
121
+
122
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
123
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
124
+ # phone_number = "13107409700"
125
+
126
+ # verify = Verify(cust_id, secret_key) # Instantiate a Verify object.
127
+
128
+ # try:
129
+ # phone_info = verify.call(phone_number)
130
+ # except AuthorizationError as ex:
131
+ # # API authorization failed, the API response should tell you the reason
132
+ # ...
133
+ # except TeleSignError as ex:
134
+ # # failed to execute the Verify service, check the API response for details
135
+ # ...
136
+
137
+ # # When the user inputs the validation code, you can verify that it matches the one that you sent.
138
+ # if (phone_info != None):
139
+ # try:
140
+ # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code)
141
+ # except AuthorizationError as ex:
142
+ # ...
143
+ # except TeleSignError as ex:
144
+ # ...
145
+
146
+ if verify_code.nil?
147
+ verify_code = random_with_N_digits(5)
148
+ end
149
+
150
+ resource = '/v1/verify/call'
151
+ method = 'POST'
152
+
153
+ fields = {
154
+ phone_number: phone_number,
155
+ language: language,
156
+ verify_code: verify_code}
157
+
158
+ headers = TeleSign::Auth.generate_auth_headers(
159
+ customer_id: @customer_id,
160
+ secret_key: @secret_key,
161
+ resource: resource,
162
+ method: method,
163
+ fields: fields)
164
+
165
+ response = @conn.post do |req|
166
+ req.url resource
167
+ req.body = URI.encode_www_form(fields)
168
+ req.headers = headers
169
+ # proxies=@proxy
170
+ end
171
+
172
+ return TeleSign::Response.new validate_response(response), response, verify_code
173
+ end
174
+
175
+ def status ref_id, verify_code=nil
176
+ # Retrieves the verification result. You make this call in your web application after users complete the authentication transaction (using either a call or sms).
177
+
178
+ # * - Parameters
179
+ # -
180
+ # * - `ref_id`
181
+ # - The Reference ID returned in the response from the TeleSign server, after you called either **call** or **sms**.
182
+ # * - `verify_code`
183
+ # - The verification code received from the user.
184
+
185
+ # **Example**::
186
+
187
+ # from telesign.api import Verify
188
+ # from telesign.exceptions import AuthorizationError, TeleSignError
189
+
190
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
191
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
192
+ # phone_number = "13107409700"
193
+
194
+ # verify = Verify(cust_id, secret_key) # Instantiate a Verify object.
195
+
196
+ # phone_info = verify.sms(phone_number) # Send a text message that contains an auto-generated validation code, to the user.
197
+
198
+ # # When the user inputs the validation code, you can verify that it matches the one that you sent.
199
+ # if (phone_info != None):
200
+ # try:
201
+ # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code)
202
+ # except AuthorizationError as ex:
203
+ # ...
204
+ # except TeleSignError as ex:
205
+ # ...
206
+
207
+ resource = "/v1/verify/%s" % ref_id
208
+ method = 'GET'
209
+
210
+ headers = TeleSign::Auth.generate_auth_headers(
211
+ customer_id: @customer_id,
212
+ secret_key: @secret_key,
213
+ resource: resource,
214
+ method: method)
215
+
216
+ fields = nil
217
+ if !verify_code.nil?
218
+ fields = {verify_code: verify_code}
219
+ end
220
+
221
+ response = @conn.get do |req|
222
+ req.url resource
223
+ fields.each{|k,v| req.params[k] = v} if fields
224
+ req.headers = headers
225
+ # proxies=@proxy
226
+ end
227
+
228
+ return TeleSign::Response.new validate_response(response), response
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,3 @@
1
+ module TeleSign
2
+ VERSION = '0.0.12'
3
+ end
data/lib/telesign.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'telesign/version'
2
+ require 'telesign/mock_service/railtie' if defined? Rails
3
+
4
+ module TeleSign
5
+ autoload :TeleSignError, 'telesign/telesign_error'
6
+ autoload :AuthorizationError, 'telesign/authorization_error'
7
+ autoload :ValidationError, 'telesign/validation_error'
8
+ autoload :Auth, 'telesign/auth'
9
+ autoload :Response, 'telesign/response'
10
+ autoload :Helpers, 'telesign/helpers'
11
+ autoload :Verify, 'telesign/verify'
12
+ autoload :PhoneId, 'telesign/phone_id'
13
+ autoload :Api, 'telesign/api'
14
+ end
data/telesign.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'telesign/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'telesign_lib'
8
+ spec.version = TeleSign::VERSION
9
+ spec.authors = ['Practice Fusion', 'Andy Koch', 'Andrej Antas']
10
+ spec.email = ['akoch@practicefusion.com']
11
+ spec.description = %q{Library for comunication with TeleSign REST API}
12
+ spec.summary = %q{Client gem for TeleSign REST API}
13
+ spec.homepage = 'https://github.com/redrick/ruby_telesign'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^(test)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'faraday', '~> 0.9'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake', '~> 10.4'
24
+ spec.add_development_dependency 'minitest', '~> 5.5'
25
+ spec.add_development_dependency 'webmock', '~> 1.20'
26
+ spec.add_development_dependency 'pry', '~> 0.10'
27
+ spec.add_development_dependency 'mimic', '~> 0.4'
28
+ end
data/test/auth_test.rb ADDED
@@ -0,0 +1,79 @@
1
+ require 'test_helper'
2
+
3
+ class TestAuth < Minitest::Test
4
+ def setup
5
+ @expected_cid = '99999999-1F7E-11E1-B760-000000000000'
6
+ @expected_secret_key = '8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M=='
7
+ @expected_resource = '/foo/bar/baz/'
8
+ end
9
+
10
+ def test_headers_are_set_on_get
11
+ TeleSign::Auth.generate_auth_headers(
12
+ customer_id: @expected_cid,
13
+ secret_key: @expected_secret_key,
14
+ resource: @expected_resource,
15
+ method: 'GET')
16
+ end
17
+
18
+ def test_nonce_is_set
19
+ expected_nonce = '1234'
20
+
21
+ headers = SecureRandom.stub :uuid, expected_nonce do
22
+ TeleSign::Auth.generate_auth_headers(
23
+ customer_id: @expected_cid,
24
+ secret_key: @expected_secret_key,
25
+ resource: @expected_resource,
26
+ method: 'GET')
27
+ end
28
+
29
+ assert_equal headers['x-ts-nonce'], expected_nonce
30
+ end
31
+
32
+ def test_date_is_set
33
+ headers = TeleSign::Auth.generate_auth_headers(
34
+ customer_id: @expected_cid,
35
+ secret_key: @expected_secret_key,
36
+ resource: @expected_resource,
37
+ method: 'GET')
38
+
39
+ # Can't mock datetime
40
+ refute_match headers['x-ts-date'], nil
41
+ end
42
+
43
+ def test_sha1_default_auth_method
44
+ expected_auth_method = 'HMAC-SHA1'
45
+
46
+ headers = TeleSign::Auth.generate_auth_headers(
47
+ customer_id: @expected_cid,
48
+ secret_key: @expected_secret_key,
49
+ resource: @expected_resource,
50
+ method: 'GET')
51
+
52
+ assert_equal headers['x-ts-auth-method'], expected_auth_method, 'Auth method did not match'
53
+ end
54
+
55
+ def test_sha256_auth_method
56
+ expected_auth_method = 'HMAC-SHA256'
57
+
58
+ headers = TeleSign::Auth.generate_auth_headers(
59
+ customer_id: @expected_cid,
60
+ secret_key: @expected_secret_key,
61
+ resource: @expected_resource,
62
+ method: 'GET',
63
+ auth_method: :sha256)
64
+
65
+ assert_equal headers['x-ts-auth-method'], expected_auth_method, 'Auth method did not match'
66
+ end
67
+
68
+ def test_customer_id_in_auth
69
+ expected_auth_start = "TSA %s:" % @expected_cid
70
+
71
+ headers = TeleSign::Auth.generate_auth_headers(
72
+ customer_id: @expected_cid,
73
+ secret_key: @expected_secret_key,
74
+ resource: @expected_resource,
75
+ method: 'GET')
76
+
77
+ assert_match /^#{expected_auth_start}/, headers['Authorization'], 'Authorization did not start with TSA and customer ID'
78
+ end
79
+ end