bitpay-sdk 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,29 @@
1
+ require_relative '../spec_helper.rb'
2
+
3
+ describe "pairing a token", javascript: true, type: :feature do
4
+ let(:claimCode) do
5
+ visit ROOT_ADDRESS
6
+ click_link('Login')
7
+ fill_in 'email', :with => TEST_USER
8
+ fill_in 'password', :with => TEST_PASS
9
+ click_button('loginButton')
10
+ click_link "My Account"
11
+ click_link "API Tokens", match: :first
12
+ find(".token-access-new-button").find(".btn").find(".icon-plus").click
13
+ find_button("Add Token", match: :first).click
14
+ find(".token-claimcode", match: :first).text
15
+ end
16
+ let(:pem) { BitPay::KeyUtils.generate_pem }
17
+ let(:client) { BitPay::Client.new(api_uri: ROOT_ADDRESS, pem: pem, insecure: true) }
18
+
19
+ context "pairing an unpaired client" do
20
+ it "should have no tokens before pairing" do
21
+ expect(client.instance_variable_get(:@tokens)).to be_empty
22
+ end
23
+ it "should have a pos token after pairing" do
24
+ client.pair_pos_client(claimCode)
25
+ expect(client.instance_variable_get(:@tokens)['pos']).not_to be_empty
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../spec_helper.rb'
2
+
3
+ describe "create an invoice", javascript: true, type: :feature do
4
+ before :all do
5
+ WebMock.allow_net_connect!
6
+ get_claim_code = -> {
7
+ visit ROOT_ADDRESS
8
+ click_link('Login')
9
+ fill_in 'email', :with => TEST_USER
10
+ fill_in 'password', :with => TEST_PASS
11
+ click_button('loginButton')
12
+ click_link "My Account"
13
+ click_link "API Tokens", match: :first
14
+ find(".token-access-new-button").find(".btn").click
15
+ find_button("Add Token", match: :first).click
16
+ find(".token-claimcode", match: :first).text
17
+ }
18
+ set_client = -> {
19
+ client = BitPay::Client.new(api_uri: ROOT_ADDRESS, pem: PEM, insecure: true)
20
+ client.pair_pos_client(get_claim_code.call)
21
+ client
22
+ }
23
+ @client ||= set_client.call
24
+ @invoice_id ||= SecureRandom.uuid
25
+ @price ||= (100..150).to_a.sample
26
+ @invoice = @client.create_invoice(currency: "USD", price: @price)
27
+ end
28
+
29
+ it "should create an invoice" do
30
+ expect(@invoice["status"]).to eq "new"
31
+ end
32
+
33
+ it "should be able to retrieve an invoice" do
34
+ expect(@client.get_public_invoice(id: @invoice['id'])["price"]).to eq @price
35
+ end
36
+ end
37
+
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ context 'local variables' do
4
+ it "should find the root address" do
5
+ expect(ROOT_ADDRESS).not_to be_nil
6
+ end
7
+ it "should find the user" do
8
+ expect(TEST_USER).not_to be_nil
9
+ end
10
+ it "should find the user" do
11
+ expect(TEST_PASS).not_to be_nil
12
+ end
13
+ end
@@ -0,0 +1,34 @@
1
+ require_relative '../spec_helper.rb'
2
+
3
+ describe "create an invoice", javascript: true, type: :feature do
4
+ before :all do
5
+ WebMock.allow_net_connect!
6
+ get_claim_code = -> {
7
+ visit ROOT_ADDRESS
8
+ if has_link?('Login')
9
+ click_link('Login')
10
+ fill_in 'email', :with => TEST_USER
11
+ fill_in 'password', :with => TEST_PASS
12
+ click_button('loginButton')
13
+ else
14
+ visit "#{ROOT_ADDRESS}/home"
15
+ end
16
+ click_link "My Account"
17
+ click_link "API Tokens", match: :first
18
+ find(".token-access-new-button").find(".btn").click
19
+ sleep 0.25
20
+ find_button("Add Token", match: :first).click
21
+ find(".token-claimcode", match: :first).text
22
+ }
23
+ set_client = -> {
24
+ client = BitPay::Client.new(api_uri: ROOT_ADDRESS, pem: PEM, insecure: true)
25
+ client.pair_pos_client(get_claim_code.call)
26
+ client
27
+ }
28
+ @client = set_client.call
29
+ end
30
+
31
+ it 'should verify tokens' do
32
+ expect(@client.verify_token).to be true
33
+ end
34
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe BitPay::KeyUtils do
4
+ let(:key_utils) {BitPay::KeyUtils}
5
+
6
+
7
+ describe '.get_local_private_key' do
8
+ it "should get the key from the ENV['PRIV_KEY'] variable" do
9
+ stub_const('ENV', {'BITPAY_PEM' => PEM})
10
+ expect(key_utils.get_local_pem_file).to eq(PEM)
11
+ end
12
+
13
+ it "should throw an error if the ENV['PRIV_KEY'] variable is not set" do
14
+ expect {key_utils.get_local_pem_file}.to raise_error( BitPay::BitPayError )
15
+ end
16
+
17
+ end
18
+
19
+ describe '.generate_pem' do
20
+ it 'should generate a pem string' do
21
+ regex = /BEGIN\ EC\ PRIVATE\ KEY/
22
+ expect(regex.match(key_utils.generate_pem)).to be_truthy
23
+ end
24
+ end
25
+
26
+ describe '.get_public_key_from_pem' do
27
+ it 'should generate the right public key' do
28
+ expect(key_utils.get_public_key_from_pem(PEM)).to eq(PUB_KEY)
29
+ end
30
+
31
+ it 'should get pem from the env if none is passed' do
32
+ expect(key_utils.get_public_key_from_pem(PEM)).to eq(PUB_KEY)
33
+ end
34
+
35
+ end
36
+
37
+ describe '.generate_sin_from_pem' do
38
+ let(:pem){PEM}
39
+ let(:sin){CLIENT_ID}
40
+
41
+ it 'will return the right sin for the right pem' do
42
+ expect(key_utils.generate_sin_from_pem(pem)).to eq sin
43
+ end
44
+
45
+ it 'will attempt to use an env variable if no key is provided' do
46
+ stub_const('ENV', {'BITPAY_PEM' => PEM})
47
+ expect(key_utils.generate_sin_from_pem(nil)).to eq sin
48
+ end
49
+
50
+ end
51
+
52
+ context "errors when priv_key is not provided" do
53
+ it 'will not retrieve public key' do
54
+ expect{key_utils.get_public_key_from_pem(nil)}.to raise_error(BitPay::BitPayError)
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+
3
+ export RCROOTADDRESS=$1
4
+ echo $RCROOTADDRESS
5
+ export RCTESTUSER=$2
6
+ echo $RCTESTUSER
7
+ export RCTESTPASSWORD=$3
8
+ echo $RCTESTPASSWORD
9
+ export PRIV_KEY=$4
10
+ echo $PRIV_KEY
@@ -0,0 +1,34 @@
1
+ require 'webmock/rspec'
2
+ require 'pry'
3
+ require 'capybara/rspec'
4
+ require 'capybara/poltergeist'
5
+
6
+ require File.join File.dirname(__FILE__), '..', 'lib', 'bitpay', 'client.rb'
7
+ require File.join File.dirname(__FILE__), '..', 'lib', 'bitpay', 'key_utils.rb'
8
+ require File.join File.dirname(__FILE__), '..', 'lib', 'bitpay.rb'
9
+ require_relative '../config/constants.rb'
10
+ require_relative '../config/capybara.rb'
11
+
12
+ #
13
+ ## Test Variables
14
+ #
15
+ PEM = "-----BEGIN EC PRIVATE KEY-----\nMHQCAQEEICg7E4NN53YkaWuAwpoqjfAofjzKI7Jq1f532dX+0O6QoAcGBSuBBAAK\noUQDQgAEjZcNa6Kdz6GQwXcUD9iJ+t1tJZCx7hpqBuJV2/IrQBfue8jh8H7Q/4vX\nfAArmNMaGotTpjdnymWlMfszzXJhlw==\n-----END EC PRIVATE KEY-----\n"
16
+
17
+ PUB_KEY = '038d970d6ba29dcfa190c177140fd889fadd6d2590b1ee1a6a06e255dbf22b4017'
18
+ CLIENT_ID = "TeyN4LPrXiG5t2yuSamKqP3ynVk3F52iHrX"
19
+
20
+
21
+ RSpec.configure do |config|
22
+ config.before :each do |example|
23
+ WebMock.allow_net_connect! if example.metadata[:type] == :feature
24
+ end
25
+ end
26
+
27
+ def an_illegal_claim_code
28
+ legal_map = [*'A'..'Z'] + [*'a'..'z'] + [*0..9]
29
+ first_length = rand(6)
30
+ short_code = (0..first_length).map{legal_map.sample}.join
31
+ second_length = [*8..25].sample
32
+ long_code = [*8..25].sample.times.inject([]){|arr| arr << legal_map.sample}.join
33
+ [nil, short_code, long_code].sample
34
+ end
metadata ADDED
@@ -0,0 +1,269 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitpay-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bitpay, Inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: ecdsa
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 10.3.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 10.3.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.18.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.18.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-rescue
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.4.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.4.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: capybara
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.4.3
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.4.3
139
+ - !ruby/object:Gem::Dependency
140
+ name: cucumber
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.3.17
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.3.17
153
+ - !ruby/object:Gem::Dependency
154
+ name: poltergeist
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 1.5.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 1.5.1
167
+ - !ruby/object:Gem::Dependency
168
+ name: airborne
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.0.20
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.0.20
181
+ - !ruby/object:Gem::Dependency
182
+ name: rspec
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 3.1.0
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 3.1.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: mongo
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 1.11.1
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 1.11.1
209
+ description: Powerful, flexible, lightweight, thread-safe interface to the BitPay
210
+ developers API
211
+ email: info@bitpay.com
212
+ executables: []
213
+ extensions: []
214
+ extra_rdoc_files: []
215
+ files:
216
+ - ".gitignore"
217
+ - ".travis.yml"
218
+ - Gemfile
219
+ - LICENSE.md
220
+ - README.md
221
+ - Rakefile
222
+ - bitpay-sdk.gemspec
223
+ - config/capybara.rb
224
+ - config/constants.rb
225
+ - features/creating_invoices.feature
226
+ - features/pairing.feature
227
+ - features/retrieving_invoices.feature
228
+ - features/step_definitions/invoice_steps.rb
229
+ - features/step_definitions/keygen_steps.rb
230
+ - features/step_definitions/step_helpers.rb
231
+ - lib/bitpay.rb
232
+ - lib/bitpay/cacert.pem
233
+ - lib/bitpay/client.rb
234
+ - lib/bitpay/key_utils.rb
235
+ - lib/bitpay/version.rb
236
+ - lib/harness.rb
237
+ - spec/client_spec.rb
238
+ - spec/features/pair_spec.rb
239
+ - spec/features/pos_spec.rb
240
+ - spec/features/setup_spec.rb
241
+ - spec/features/verify_tokens_spec.rb
242
+ - spec/key_utils_spec.rb
243
+ - spec/set_constants.sh
244
+ - spec/spec_helper.rb
245
+ homepage: https://github.com/bitpay/ruby-client
246
+ licenses:
247
+ - MIT
248
+ metadata: {}
249
+ post_install_message:
250
+ rdoc_options: []
251
+ require_paths:
252
+ - lib
253
+ required_ruby_version: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - "~>"
256
+ - !ruby/object:Gem::Version
257
+ version: '2.1'
258
+ required_rubygems_version: !ruby/object:Gem::Requirement
259
+ requirements:
260
+ - - ">="
261
+ - !ruby/object:Gem::Version
262
+ version: 1.3.4
263
+ requirements: []
264
+ rubyforge_project: bitpay-sdk
265
+ rubygems_version: 2.2.2
266
+ signing_key:
267
+ specification_version: 4
268
+ summary: Official Ruby library for the BitPay API
269
+ test_files: []