gocardless 1.11.2 → 1.12.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -0
- data/gocardless.gemspec +5 -5
- data/lib/gocardless.rb +11 -2
- data/lib/gocardless/client.rb +1 -0
- data/lib/gocardless/version.rb +1 -1
- data/spec/bill_spec.rb +7 -7
- data/spec/client_spec.rb +109 -104
- data/spec/gocardless_spec.rb +20 -2
- data/spec/page_spec.rb +11 -11
- data/spec/paginator_spec.rb +16 -16
- data/spec/pre_authorization_spec.rb +1 -1
- data/spec/resource_spec.rb +61 -61
- data/spec/spec_helper.rb +4 -4
- data/spec/subscription_spec.rb +1 -1
- data/spec/user_spec.rb +4 -4
- data/spec/utils_spec.rb +62 -58
- metadata +14 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 994ce7a109fb1c42f0f66f94e7fb38cff7ea1197
|
4
|
+
data.tar.gz: 8ac64f43f760b62644faccb532fadc0f86b89413
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 815fb08aef927dbdfc4f285534b4cea78e346949fb0cbee8a5c36ba2cd679f978ebfa5bc652dd5925854feaf17a3d977b7563d9a887cd69904de99c6c25b9c6e
|
7
|
+
data.tar.gz: 47e2766271e9d6df79f1909409c8f128632e4ff1d9476bc81b5bbd3e810eb8a4a14ac360475dd0459c534375151b8a073261ae5a2c40a3727726ae23903ea4f6
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## 1.12.0 - October 31, 2014
|
2
|
+
|
3
|
+
- Update Gem Dependencies
|
4
|
+
- Prevent setting bad GoCardless environments
|
5
|
+
- Fix timezone-brittle specs
|
6
|
+
- Upgrade RSpec & Convert specs to RSpec 3.1.7
|
7
|
+
- Handle nil signatures in signature_valid? method
|
8
|
+
- Stop testing against Ruby 1.8
|
9
|
+
|
10
|
+
|
1
11
|
## 1.11.2 - October 27, 2014
|
2
12
|
|
3
13
|
- Use a constant time string comparison to avoid timing attacks
|
data/Gemfile
CHANGED
data/gocardless.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require File.expand_path('../lib/gocardless/version', __FILE__)
|
2
2
|
|
3
3
|
Gem::Specification.new do |gem|
|
4
|
-
gem.add_runtime_dependency 'oauth2', '~> 0
|
5
|
-
gem.add_runtime_dependency 'multi_json', '~> 1.
|
4
|
+
gem.add_runtime_dependency 'oauth2', '~> 1.0'
|
5
|
+
gem.add_runtime_dependency 'multi_json', '~> 1.10'
|
6
6
|
|
7
7
|
gem.add_development_dependency 'rspec', '~> 2.13'
|
8
|
-
gem.add_development_dependency 'yard', '~> 0.
|
9
|
-
gem.add_development_dependency 'activesupport', '~> 3.
|
10
|
-
gem.add_development_dependency 'rake', '~> 10.
|
8
|
+
gem.add_development_dependency 'yard', '~> 0.8'
|
9
|
+
gem.add_development_dependency 'activesupport', '~> 3.2'
|
10
|
+
gem.add_development_dependency 'rake', '~> 10.3'
|
11
11
|
|
12
12
|
gem.authors = ['Harry Marr', 'Tom Blomfield']
|
13
13
|
gem.description = %q{A Ruby wrapper for the GoCardless API}
|
data/lib/gocardless.rb
CHANGED
@@ -12,8 +12,7 @@ module GoCardless
|
|
12
12
|
require 'gocardless/payout'
|
13
13
|
|
14
14
|
class << self
|
15
|
-
|
16
|
-
attr_reader :account_details, :client
|
15
|
+
attr_reader :account_details, :environment, :client
|
17
16
|
|
18
17
|
def account_details=(details)
|
19
18
|
raise ClientError.new("You must provide a token") unless details[:token]
|
@@ -21,6 +20,16 @@ module GoCardless
|
|
21
20
|
@client = Client.new(details)
|
22
21
|
end
|
23
22
|
|
23
|
+
def environment=(gc_env)
|
24
|
+
valid_environments = GoCardless::Client::BASE_URLS.keys
|
25
|
+
if !gc_env.nil? && !valid_environments.include?(gc_env)
|
26
|
+
raise ClientError.new("The GoCardless environment must be one of " +
|
27
|
+
valid_environments.join(", "))
|
28
|
+
end
|
29
|
+
|
30
|
+
@environment = gc_env
|
31
|
+
end
|
32
|
+
|
24
33
|
%w(new_subscription_url new_pre_authorization_url new_bill_url confirm_resource webhook_valid?).each do |name|
|
25
34
|
class_eval <<-EOM
|
26
35
|
def #{name}(*args)
|
data/lib/gocardless/client.rb
CHANGED
data/lib/gocardless/version.rb
CHANGED
data/spec/bill_spec.rb
CHANGED
@@ -13,28 +13,28 @@ describe GoCardless::Bill do
|
|
13
13
|
bill.source_type = :subscription
|
14
14
|
stub_get(client, :id => 123)
|
15
15
|
source = bill.source
|
16
|
-
source.
|
17
|
-
source.id.
|
16
|
+
expect(source).to be_a GoCardless::Subscription
|
17
|
+
expect(source.id).to eq(123)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "source setter works" do
|
21
21
|
bill.source = GoCardless::Subscription.new(:id => 123)
|
22
|
-
bill.source_id.
|
23
|
-
bill.source_type.
|
22
|
+
expect(bill.source_id).to eq(123)
|
23
|
+
expect(bill.source_type.to_s).to eq('subscription')
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should be able to be retried" do
|
27
|
-
client.
|
27
|
+
expect(client).to receive(:api_post).with('/bills/123/retry')
|
28
28
|
bill.retry!
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should be able to be cancelled" do
|
32
|
-
client.
|
32
|
+
expect(client).to receive(:api_put).with('/bills/123/cancel')
|
33
33
|
bill.cancel!
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should be able to be refunded" do
|
37
|
-
client.
|
37
|
+
expect(client).to receive(:api_post).with('/bills/123/refund')
|
38
38
|
bill.refund!
|
39
39
|
end
|
40
40
|
|
data/spec/client_spec.rb
CHANGED
@@ -10,36 +10,36 @@ describe GoCardless::Client do
|
|
10
10
|
describe ".base_url" do
|
11
11
|
it "and_return the correct url for the production environment" do
|
12
12
|
GoCardless.environment = :production
|
13
|
-
GoCardless::Client.base_url.
|
13
|
+
expect(GoCardless::Client.base_url).to eq('https://gocardless.com')
|
14
14
|
end
|
15
15
|
|
16
16
|
it "and_return the correct url for the sandbox environment" do
|
17
17
|
GoCardless.environment = :sandbox
|
18
|
-
GoCardless::Client.base_url.
|
18
|
+
expect(GoCardless::Client.base_url).to eq('https://sandbox.gocardless.com')
|
19
19
|
end
|
20
20
|
|
21
21
|
it "and_return the correct url when it's set manually" do
|
22
22
|
GoCardless::Client.base_url = 'https://abc.gocardless.com'
|
23
|
-
GoCardless::Client.base_url.
|
23
|
+
expect(GoCardless::Client.base_url).to eq('https://abc.gocardless.com')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#new" do
|
28
28
|
it "without an app id should raise an error" do
|
29
|
-
|
29
|
+
expect do
|
30
30
|
GoCardless::Client.new({:app_secret => @app_secret})
|
31
|
-
end.
|
31
|
+
end.to raise_exception(GoCardless::ClientError)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "without an app_secret should raise an error" do
|
35
|
-
|
35
|
+
expect do
|
36
36
|
GoCardless::Client.new({:app_id => @app_id})
|
37
|
-
end.
|
37
|
+
end.to raise_exception(GoCardless::ClientError)
|
38
38
|
end
|
39
39
|
|
40
40
|
it "does not raise an error if the credentials are provided as environment variables" do
|
41
|
-
ENV.
|
42
|
-
ENV.
|
41
|
+
expect(ENV).to receive(:[]).with('GOCARDLESS_APP_ID').and_return(@app_id)
|
42
|
+
expect(ENV).to receive(:[]).with('GOCARDLESS_APP_SECRET').and_return(@app_secret)
|
43
43
|
|
44
44
|
GoCardless::Client.new
|
45
45
|
end
|
@@ -50,7 +50,7 @@ describe GoCardless::Client do
|
|
50
50
|
:app_secret => @app_secret,
|
51
51
|
:merchant_id => 'xyz'
|
52
52
|
})
|
53
|
-
client.send('merchant_id').
|
53
|
+
expect(client.send('merchant_id')).to eq('xyz')
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -60,15 +60,15 @@ describe GoCardless::Client do
|
|
60
60
|
|
61
61
|
describe "#authorize_url" do
|
62
62
|
it "fails without a redirect uri" do
|
63
|
-
|
63
|
+
expect { @client.authorize_url }.to raise_exception(ArgumentError)
|
64
64
|
end
|
65
65
|
|
66
66
|
it "generates the authorize url correctly" do
|
67
67
|
url = URI.parse(@client.authorize_url(:redirect_uri => @redirect_uri))
|
68
68
|
query = CGI.parse(url.query)
|
69
|
-
query['response_type'].first.
|
70
|
-
query['redirect_uri'].first.
|
71
|
-
query['client_id'].first.
|
69
|
+
expect(query['response_type'].first).to eq('code')
|
70
|
+
expect(query['redirect_uri'].first).to eq(@redirect_uri)
|
71
|
+
expect(query['client_id'].first).to eq(@app_id)
|
72
72
|
end
|
73
73
|
|
74
74
|
it "includes the cancel uri if present" do
|
@@ -78,14 +78,14 @@ describe GoCardless::Client do
|
|
78
78
|
:cancel_uri => cancel_uri
|
79
79
|
))
|
80
80
|
query = CGI.parse(url.query)
|
81
|
-
query['cancel_uri'].first.
|
81
|
+
expect(query['cancel_uri'].first).to eq(cancel_uri)
|
82
82
|
end
|
83
83
|
|
84
84
|
it "encodes prefilling parameters correctly" do
|
85
85
|
params = {:merchant => {:user => {:email => "a@b.com"}}}
|
86
86
|
url = @client.authorize_url(params.merge(:redirect_uri => @redirect_uri))
|
87
87
|
encoded_key = GoCardless::Utils.percent_encode('merchant[user][email]')
|
88
|
-
URI.parse(url).query.
|
88
|
+
expect(URI.parse(url).query).to match /#{encoded_key}=a%40b\.com/
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -93,9 +93,9 @@ describe GoCardless::Client do
|
|
93
93
|
access_token_url = "#{GoCardless::Client.base_url}/oauth/access_token"
|
94
94
|
|
95
95
|
it "fails without a redirect uri" do
|
96
|
-
|
96
|
+
expect do
|
97
97
|
@client.fetch_access_token('code', {})
|
98
|
-
end.
|
98
|
+
end.to raise_exception(ArgumentError)
|
99
99
|
end
|
100
100
|
|
101
101
|
describe "with valid params" do
|
@@ -104,12 +104,12 @@ describe GoCardless::Client do
|
|
104
104
|
double(:params => {'scope' => 'manage_merchant:x'}, :token => 'abc')
|
105
105
|
end
|
106
106
|
|
107
|
-
before { oauth_client.auth_code.
|
107
|
+
before { allow(oauth_client.auth_code).to receive(:get_token).and_return(fake_token) }
|
108
108
|
|
109
109
|
it "calls correct method with correct args" do
|
110
110
|
auth_code = 'fakecode'
|
111
111
|
|
112
|
-
oauth_client.auth_code.
|
112
|
+
expect(oauth_client.auth_code).to receive(:get_token).with(
|
113
113
|
auth_code, hash_including(:redirect_uri => @redirect_uri)
|
114
114
|
).and_return(fake_token)
|
115
115
|
|
@@ -117,15 +117,15 @@ describe GoCardless::Client do
|
|
117
117
|
end
|
118
118
|
|
119
119
|
it "sets @access_token" do
|
120
|
-
@client.instance_variable_get(:@access_token).
|
120
|
+
expect(@client.instance_variable_get(:@access_token)).to be_nil
|
121
121
|
@client.fetch_access_token('code', {:redirect_uri => @redirect_uri})
|
122
|
-
@client.instance_variable_get(:@access_token).
|
122
|
+
expect(@client.instance_variable_get(:@access_token)).to eq(fake_token)
|
123
123
|
end
|
124
124
|
|
125
125
|
it "sets @merchant_id" do
|
126
|
-
@client.instance_variable_get(:@merchant_id).
|
126
|
+
expect(@client.instance_variable_get(:@merchant_id)).to be_nil
|
127
127
|
@client.fetch_access_token('code', {:redirect_uri => @redirect_uri})
|
128
|
-
@client.instance_variable_get(:@merchant_id).
|
128
|
+
expect(@client.instance_variable_get(:@merchant_id)).to eq('x')
|
129
129
|
end
|
130
130
|
end
|
131
131
|
end
|
@@ -137,11 +137,11 @@ describe GoCardless::Client do
|
|
137
137
|
token.params['scope'] = 'a:1 b:2'
|
138
138
|
@client.instance_variable_set(:@access_token, token)
|
139
139
|
|
140
|
-
@client.scoped_access_token.
|
140
|
+
expect(@client.scoped_access_token).to eq('TOKEN123 a:1 b:2')
|
141
141
|
end
|
142
142
|
|
143
143
|
it "and_return nil when there's no token" do
|
144
|
-
@client.scoped_access_token.
|
144
|
+
expect(@client.scoped_access_token).to be_nil
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -152,31 +152,31 @@ describe GoCardless::Client do
|
|
152
152
|
token.params['scope'] = 'a:1 b:2'
|
153
153
|
@client.instance_variable_set(:@access_token, token)
|
154
154
|
|
155
|
-
@client.unscoped_access_token.
|
155
|
+
expect(@client.unscoped_access_token).to eq('TOKEN123')
|
156
156
|
end
|
157
157
|
|
158
158
|
it "and_return nil when there's no token" do
|
159
|
-
@client.unscoped_access_token.
|
159
|
+
expect(@client.unscoped_access_token).to be_nil
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
163
|
describe "#access_token" do
|
164
|
-
before { @client.
|
164
|
+
before { allow(@client).to receive(:warn) }
|
165
165
|
it "serializes access token correctly" do
|
166
166
|
oauth_client = @client.instance_variable_get(:@oauth_client)
|
167
167
|
token = OAuth2::AccessToken.new(oauth_client, 'TOKEN123')
|
168
168
|
token.params['scope'] = 'a:1 b:2'
|
169
169
|
@client.instance_variable_set(:@access_token, token)
|
170
170
|
|
171
|
-
@client.access_token.
|
171
|
+
expect(@client.access_token).to eq('TOKEN123 a:1 b:2')
|
172
172
|
end
|
173
173
|
|
174
174
|
it "and_return nil when there's no token" do
|
175
|
-
@client.access_token.
|
175
|
+
expect(@client.access_token).to be_nil
|
176
176
|
end
|
177
177
|
|
178
178
|
it "issues a deprecation warning" do
|
179
|
-
@client.
|
179
|
+
expect(@client).to receive(:warn)
|
180
180
|
@client.access_token
|
181
181
|
end
|
182
182
|
end
|
@@ -188,44 +188,44 @@ describe GoCardless::Client do
|
|
188
188
|
token.params['scope'] = 'a:1 b:2'
|
189
189
|
@client.instance_variable_set(:@access_token, token)
|
190
190
|
|
191
|
-
@client.scope.
|
191
|
+
expect(@client.scope).to eq('a:1 b:2')
|
192
192
|
end
|
193
193
|
|
194
194
|
it "and_return nil when there's no token" do
|
195
|
-
@client.scope.
|
195
|
+
expect(@client.scope).to be_nil
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
199
199
|
describe "#access_token=" do
|
200
|
-
before { @client.
|
200
|
+
before { allow(@client).to receive(:warn) }
|
201
201
|
|
202
202
|
it "deserializes access token correctly" do
|
203
203
|
@client.access_token = 'TOKEN123 a:1 b:2'
|
204
204
|
token = @client.instance_variable_get(:@access_token)
|
205
|
-
token.token.
|
206
|
-
token.params['scope'].
|
205
|
+
expect(token.token).to eq('TOKEN123')
|
206
|
+
expect(token.params['scope']).to eq('a:1 b:2')
|
207
207
|
end
|
208
208
|
|
209
209
|
it "pulls out the merchant_id when present" do
|
210
210
|
@client.access_token = 'TOKEN123 manage_merchant:xyz'
|
211
|
-
@client.send('merchant_id').
|
211
|
+
expect(@client.send('merchant_id')).to eq('xyz')
|
212
212
|
end
|
213
213
|
|
214
214
|
it "issues a deprecation warning when the scope is present" do
|
215
|
-
@client.
|
215
|
+
expect(@client).to receive(:warn)
|
216
216
|
@client.access_token = 'TOKEN123 manage_merchant:xyz'
|
217
217
|
end
|
218
218
|
|
219
219
|
it "doesn't issue a deprecation warning when the scope is missing" do
|
220
|
-
@client.
|
220
|
+
expect(@client).to receive(:warn).never
|
221
221
|
@client.access_token = 'TOKEN123'
|
222
222
|
end
|
223
223
|
|
224
224
|
it "ignores 'bearer' if it is present at the start of the string" do
|
225
225
|
@client.access_token = 'Bearer TOKEN manage_merchant:123'
|
226
226
|
token = @client.instance_variable_get(:@access_token)
|
227
|
-
token.token.
|
228
|
-
token.params['scope'].
|
227
|
+
expect(token.token).to eq('TOKEN')
|
228
|
+
expect(token.params['scope']).to eq('manage_merchant:123')
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
@@ -234,10 +234,10 @@ describe GoCardless::Client do
|
|
234
234
|
@client.access_token = 'TOKEN123'
|
235
235
|
token = @client.instance_variable_get(:@access_token)
|
236
236
|
r = double
|
237
|
-
r.
|
238
|
-
token.
|
237
|
+
allow(r).to receive(:parsed)
|
238
|
+
expect(token).to receive(:get) { |p, o|
|
239
239
|
expect(p).to satisfy { |v| v =~ %r|/api/v1/test| }
|
240
|
-
|
240
|
+
}.and_return(r)
|
241
241
|
@client.api_get('/test')
|
242
242
|
end
|
243
243
|
|
@@ -251,10 +251,10 @@ describe GoCardless::Client do
|
|
251
251
|
@client.access_token = 'TOKEN123'
|
252
252
|
token = @client.instance_variable_get(:@access_token)
|
253
253
|
r = double
|
254
|
-
r.
|
255
|
-
token.
|
254
|
+
allow(r).to receive(:parsed)
|
255
|
+
expect(token).to receive(:post) { |p,opts|
|
256
256
|
expect(opts[:body]).to eq('{"a":1}')
|
257
|
-
|
257
|
+
}.and_return(r)
|
258
258
|
@client.api_post('/test', {:a => 1})
|
259
259
|
end
|
260
260
|
|
@@ -268,10 +268,10 @@ describe GoCardless::Client do
|
|
268
268
|
@client.access_token = 'TOKEN123'
|
269
269
|
token = @client.instance_variable_get(:@access_token)
|
270
270
|
r = double
|
271
|
-
r.
|
272
|
-
token.
|
271
|
+
allow(r).to receive(:parsed)
|
272
|
+
expect(token).to receive(:delete) { |p,opts|
|
273
273
|
expect(opts[:body]).to eq('{"a":1}')
|
274
|
-
|
274
|
+
}.and_return(r)
|
275
275
|
@client.api_delete('/test', {:a => 1})
|
276
276
|
end
|
277
277
|
|
@@ -285,15 +285,15 @@ describe GoCardless::Client do
|
|
285
285
|
@client.access_token = 'TOKEN'
|
286
286
|
@client.merchant_id = '123'
|
287
287
|
response = double
|
288
|
-
response.
|
288
|
+
expect(response).to receive(:parsed)
|
289
289
|
|
290
290
|
token = @client.instance_variable_get(:@access_token)
|
291
291
|
merchant_url = '/api/v1/merchants/123'
|
292
|
-
token.
|
292
|
+
expect(token).to receive(:get) { |p,o|
|
293
293
|
expect(p).to eq(merchant_url)
|
294
|
-
|
294
|
+
}.and_return response
|
295
295
|
|
296
|
-
GoCardless::Merchant.
|
296
|
+
allow(GoCardless::Merchant).to receive(:new_with_client)
|
297
297
|
|
298
298
|
@client.merchant
|
299
299
|
end
|
@@ -302,15 +302,15 @@ describe GoCardless::Client do
|
|
302
302
|
@client.access_token = 'TOKEN'
|
303
303
|
@client.merchant_id = '123'
|
304
304
|
response = double
|
305
|
-
response.
|
305
|
+
expect(response).to receive(:parsed).and_return({:name => 'test', :id => 123})
|
306
306
|
|
307
307
|
token = @client.instance_variable_get(:@access_token)
|
308
|
-
token.
|
308
|
+
expect(token).to receive(:get).and_return response
|
309
309
|
|
310
310
|
merchant = @client.merchant
|
311
|
-
merchant.
|
312
|
-
merchant.id.
|
313
|
-
merchant.name.
|
311
|
+
expect(merchant).to be_an_instance_of GoCardless::Merchant
|
312
|
+
expect(merchant.id).to eq(123)
|
313
|
+
expect(merchant.name).to eq('test')
|
314
314
|
end
|
315
315
|
end
|
316
316
|
|
@@ -321,8 +321,8 @@ describe GoCardless::Client do
|
|
321
321
|
@client.merchant_id = '123'
|
322
322
|
stub_get(@client, {:id => 123})
|
323
323
|
obj = @client.send(resource, 123)
|
324
|
-
obj.
|
325
|
-
obj.id.
|
324
|
+
expect(obj).to be_a GoCardless.const_get(GoCardless::Utils.camelize(resource))
|
325
|
+
expect(obj.id).to eq(123)
|
326
326
|
end
|
327
327
|
end
|
328
328
|
end
|
@@ -331,7 +331,7 @@ describe GoCardless::Client do
|
|
331
331
|
@client.instance_variable_set(:@app_secret, 'testsecret')
|
332
332
|
params = {:test => true}
|
333
333
|
sig = '6e4613b729ce15c288f70e72463739feeb05fc0b89b55d248d7f259b5367148b'
|
334
|
-
@client.send(:sign_params, params)[:signature].
|
334
|
+
expect(@client.send(:sign_params, params)[:signature]).to eq(sig)
|
335
335
|
end
|
336
336
|
|
337
337
|
describe "#signature_valid?" do
|
@@ -339,12 +339,17 @@ describe GoCardless::Client do
|
|
339
339
|
|
340
340
|
it "succeeds with a valid signature" do
|
341
341
|
params = @client.send(:sign_params, @params)
|
342
|
-
@client.send(:signature_valid?, params).
|
342
|
+
expect(@client.send(:signature_valid?, params)).to be_truthy
|
343
343
|
end
|
344
344
|
|
345
345
|
it "fails with an invalid signature" do
|
346
346
|
params = {:signature => 'invalid'}.merge(@params)
|
347
|
-
@client.send(:signature_valid?, params).
|
347
|
+
expect(@client.send(:signature_valid?, params)).to be_falsey
|
348
|
+
end
|
349
|
+
|
350
|
+
it "fails with a nil signature" do
|
351
|
+
params = {:signature => nil}.merge(@params)
|
352
|
+
expect(@client.send(:signature_valid?, params)).to be_falsey
|
348
353
|
end
|
349
354
|
end
|
350
355
|
|
@@ -358,7 +363,7 @@ describe GoCardless::Client do
|
|
358
363
|
end
|
359
364
|
|
360
365
|
it "doesn't confirm the resource when the signature is invalid" do
|
361
|
-
@client.
|
366
|
+
expect(@client).to receive(:request).never
|
362
367
|
@client.confirm_resource({:signature => 'xxx'}.merge(@params)) rescue nil
|
363
368
|
end
|
364
369
|
|
@@ -370,37 +375,37 @@ describe GoCardless::Client do
|
|
370
375
|
|
371
376
|
it "confirms the resource when the signature is valid" do
|
372
377
|
# Once for confirm, once to fetch result
|
373
|
-
@client.
|
378
|
+
expect(@client).to receive(:request).twice.and_return(double(:parsed => {}))
|
374
379
|
@client.confirm_resource(@client.send(:sign_params, @params))
|
375
380
|
end
|
376
381
|
|
377
382
|
it "and_return the correct object when the signature is valid" do
|
378
|
-
@client.
|
383
|
+
allow(@client).to receive(:request).and_return(double(:parsed => {}))
|
379
384
|
subscription = GoCardless::Subscription.new_with_client @client
|
380
|
-
GoCardless::Subscription.
|
385
|
+
expect(GoCardless::Subscription).to receive(:find_with_client).and_return subscription
|
381
386
|
|
382
387
|
# confirm_resource should use the Subcription class because
|
383
388
|
# the :response_type is set to subscription
|
384
389
|
resource = @client.confirm_resource(@client.send(:sign_params, @params))
|
385
|
-
resource.
|
390
|
+
expect(resource).to be_a GoCardless::Subscription
|
386
391
|
end
|
387
392
|
|
388
393
|
it "includes valid http basic credentials" do
|
389
|
-
GoCardless::Subscription.
|
394
|
+
allow(GoCardless::Subscription).to receive(:find_with_client)
|
390
395
|
auth = 'Basic YWJjOnh5eg=='
|
391
|
-
@client.
|
392
|
-
opts.
|
393
|
-
opts[:headers].
|
394
|
-
opts[:headers]['Authorization'].
|
395
|
-
|
396
|
+
expect(@client).to receive(:request) { |type, path, opts|
|
397
|
+
expect(opts).to include :headers
|
398
|
+
expect(opts[:headers]).to include 'Authorization'
|
399
|
+
expect(opts[:headers]['Authorization']).to eq(auth)
|
400
|
+
}.once
|
396
401
|
@client.confirm_resource(@client.send(:sign_params, @params))
|
397
402
|
end
|
398
403
|
|
399
404
|
it "works with string params" do
|
400
|
-
@client.
|
401
|
-
GoCardless::Subscription.
|
405
|
+
allow(@client).to receive(:request)
|
406
|
+
allow(GoCardless::Subscription).to receive(:find_with_client)
|
402
407
|
params = Hash[@params.dup.map { |k,v| [k.to_s, v] }]
|
403
|
-
params.keys.each { |p| p.
|
408
|
+
params.keys.each { |p| expect(p).to be_a String }
|
404
409
|
# No ArgumentErrors should be raised
|
405
410
|
@client.confirm_resource(@client.send(:sign_params, params))
|
406
411
|
end
|
@@ -436,9 +441,9 @@ describe GoCardless::Client do
|
|
436
441
|
end
|
437
442
|
|
438
443
|
it "rejects other params not required for the signature" do
|
439
|
-
@client.
|
444
|
+
expect(@client).to receive(:signature_valid?) { |hash|
|
440
445
|
!hash.keys.include?(:foo) && !hash.keys.include?('foo')
|
441
|
-
|
446
|
+
}.and_return(true)
|
442
447
|
|
443
448
|
params = @client.send(:sign_params, @params).merge('foo' => 'bar')
|
444
449
|
@client.response_params_valid?(params)
|
@@ -446,17 +451,17 @@ describe GoCardless::Client do
|
|
446
451
|
|
447
452
|
it "and_return false when the signature is invalid" do
|
448
453
|
params = {:signature => 'xxx'}.merge(@params)
|
449
|
-
@client.response_params_valid?(params).
|
454
|
+
expect(@client.response_params_valid?(params)).to be_falsey
|
450
455
|
end
|
451
456
|
|
452
457
|
it "and_return true when the signature is valid" do
|
453
458
|
params = @client.send(:sign_params, @params)
|
454
|
-
@client.response_params_valid?(params).
|
459
|
+
expect(@client.response_params_valid?(params)).to be_truthy
|
455
460
|
end
|
456
461
|
end
|
457
462
|
|
458
463
|
it "#generate_nonce should generate a random string" do
|
459
|
-
@client.send(:generate_nonce).
|
464
|
+
expect(@client.send(:generate_nonce)).not_to eq(@client.send(:generate_nonce))
|
460
465
|
end
|
461
466
|
|
462
467
|
describe "#new_limit_url" do
|
@@ -472,7 +477,7 @@ describe GoCardless::Client do
|
|
472
477
|
|
473
478
|
it "should use the correct path" do
|
474
479
|
url = @client.send(:new_limit_url, :test_limit, {})
|
475
|
-
URI.parse(url).path.
|
480
|
+
expect(URI.parse(url).path).to eq('/connect/test_limits/new')
|
476
481
|
end
|
477
482
|
|
478
483
|
it "should include the params in the URL query" do
|
@@ -480,64 +485,64 @@ describe GoCardless::Client do
|
|
480
485
|
url = @client.send(:new_limit_url, :subscription, params)
|
481
486
|
url_params = get_params(url)
|
482
487
|
params.each do |key, value|
|
483
|
-
url_params["subscription[#{key}]"].
|
488
|
+
expect(url_params["subscription[#{key}]"]).to eq(value)
|
484
489
|
end
|
485
490
|
end
|
486
491
|
|
487
492
|
it "should include the state in the URL query" do
|
488
493
|
params = { 'a' => '1', 'b' => '2', :state => "blah" }
|
489
494
|
url = @client.send(:new_limit_url, :subscription, params)
|
490
|
-
get_params(url)["state"].
|
495
|
+
expect(get_params(url)["state"]).to eq("blah")
|
491
496
|
end
|
492
497
|
|
493
498
|
it "should include the redirect_uri in the URL query" do
|
494
499
|
params = { 'a' => '1', 'b' => '2', :redirect_uri => "http://www.google.com" }
|
495
500
|
url = @client.send(:new_limit_url, :subscription, params)
|
496
|
-
get_params(url)["redirect_uri"].
|
501
|
+
expect(get_params(url)["redirect_uri"]).to eq("http://www.google.com")
|
497
502
|
end
|
498
503
|
|
499
504
|
it "should include the cancel_uri in the URL query" do
|
500
505
|
params = { 'a' => '1', 'b' => '2', :cancel_uri => "http://www.google.com" }
|
501
506
|
url = @client.send(:new_limit_url, :subscription, params)
|
502
|
-
get_params(url)["cancel_uri"].
|
507
|
+
expect(get_params(url)["cancel_uri"]).to eq("http://www.google.com")
|
503
508
|
end
|
504
509
|
|
505
510
|
it "should add merchant_id to the limit" do
|
506
511
|
url = @client.send(:new_limit_url, :subscription, {})
|
507
|
-
get_params(url)['subscription[merchant_id]'].
|
512
|
+
expect(get_params(url)['subscription[merchant_id]']).to eq(@merchant_id)
|
508
513
|
end
|
509
514
|
|
510
515
|
it "should include a valid signature" do
|
511
516
|
params = get_params(@client.send(:new_limit_url, :subscription, :x => 1))
|
512
|
-
params.key?('signature').
|
517
|
+
expect(params.key?('signature')).to be_truthy
|
513
518
|
sig = params.delete('signature')
|
514
|
-
sig.
|
519
|
+
expect(sig).to eq(@client.send(:sign_params, params.clone)[:signature])
|
515
520
|
end
|
516
521
|
|
517
522
|
it "should include a nonce" do
|
518
523
|
params = get_params(@client.send(:new_limit_url, :subscription, :x => 1))
|
519
|
-
params['nonce'].
|
524
|
+
expect(params['nonce']).to be_a String
|
520
525
|
end
|
521
526
|
|
522
527
|
it "should include a client_id" do
|
523
528
|
params = get_params(@client.send(:new_limit_url, :subscription, :x => 1))
|
524
|
-
params['client_id'].
|
529
|
+
expect(params['client_id']).to eq(@client.instance_variable_get(:@app_id))
|
525
530
|
end
|
526
531
|
|
527
532
|
it "should include a timestamp" do
|
528
533
|
# Time.now returning Pacific time
|
529
534
|
time = Time.parse('Sat Jan 01 2011 00:00:00 -0800')
|
530
|
-
Time.
|
535
|
+
expect(Time).to receive(:now).and_return time
|
531
536
|
params = get_params(@client.send(:new_limit_url, :subscription, :x => 1))
|
532
537
|
# Check that timezone is ISO formatted UTC
|
533
|
-
params['timestamp'].
|
538
|
+
expect(params['timestamp']).to eq("2011-01-01T08:00:00Z")
|
534
539
|
end
|
535
540
|
end
|
536
541
|
|
537
542
|
describe "#merchant_id" do
|
538
543
|
it "and_return the merchant id when an access token is set" do
|
539
544
|
@client.merchant_id = '123'
|
540
|
-
@client.send(:merchant_id).
|
545
|
+
expect(@client.send(:merchant_id)).to eq('123')
|
541
546
|
end
|
542
547
|
|
543
548
|
it "fails if there's no access token" do
|
@@ -549,26 +554,26 @@ describe GoCardless::Client do
|
|
549
554
|
|
550
555
|
describe "#webhook_valid?" do
|
551
556
|
it "and_return false when the webhook signature is invalid" do
|
552
|
-
@client.webhook_valid?({:some => 'stuff', :signature => 'invalid'}).
|
553
|
-
|
557
|
+
expect(@client.webhook_valid?({:some => 'stuff', :signature => 'invalid'})).
|
558
|
+
to be_falsey
|
554
559
|
end
|
555
560
|
|
556
561
|
it "and_return true when the webhook signature is valid" do
|
557
562
|
valid_signature = '175e814f0f64e5e86d41fb8fe06a857cedda715a96d3dc3d885e6d97dbeb7e49'
|
558
|
-
@client.webhook_valid?({:some => 'stuff', :signature => valid_signature}).
|
559
|
-
|
563
|
+
expect(@client.webhook_valid?({:some => 'stuff', :signature => valid_signature})).
|
564
|
+
to be_truthy
|
560
565
|
end
|
561
566
|
end
|
562
567
|
|
563
568
|
describe "base_url" do
|
564
569
|
it "and_return a custom base URL when one has been set" do
|
565
570
|
@client.base_url = 'http://test.com/'
|
566
|
-
@client.base_url.
|
571
|
+
expect(@client.base_url).to eq('http://test.com/')
|
567
572
|
end
|
568
573
|
|
569
574
|
it "and_return the default value when base_url is not set for the instance" do
|
570
|
-
GoCardless::Client.
|
571
|
-
@client.base_url.
|
575
|
+
allow(GoCardless::Client).to receive_messages(:base_url => 'http://gc.com/')
|
576
|
+
expect(@client.base_url).to eq('http://gc.com/')
|
572
577
|
end
|
573
578
|
end
|
574
579
|
|