uploadcare-ruby 1.0.6 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Uploadcare::Connections::Auth::Secure do
4
+ describe '#apply' do
5
+ let(:env){ Faraday::Env.new(:get, nil, URI::HTTP.build(host: 'example.com'), nil, {}) }
6
+ subject{ env.request_headers }
7
+
8
+ before(:each) do
9
+ described_class.new(public_key: 'pub', private_key: 'priv').apply(env)
10
+ end
11
+
12
+ it "adds Authorization header to env's request_headers" do
13
+ expect(subject).to include('Authorization')
14
+ end
15
+
16
+ it "adds Date header to env's request_headers" do
17
+ expect(subject).to include('Date')
18
+ end
19
+
20
+ it "uses secure authorization" do
21
+ expect(subject['Authorization']).to match /Uploadcare pub:.+/
22
+ end
23
+ end
24
+
25
+ describe 'signature' do
26
+ let(:uri){ URI::HTTP.build(host: 'example.com', path: '/path', query: 'test=1') }
27
+ let(:headers){ {'Content-Type' => 'application/x-www-form-urlencoded'} }
28
+ let(:env){ Faraday::Env.new(:post, 'url=encoded&test=body', uri, nil, headers) }
29
+
30
+ subject{ env.request_headers }
31
+
32
+ before(:each) do
33
+ allow(Time).to receive(:now).and_return(Time.parse('2017.02.02 12:58:50 +0000'))
34
+ described_class.new(public_key: 'pub', private_key: 'priv').apply(env)
35
+ end
36
+
37
+ it "counts signature correctly" do
38
+ expected = '71b61ed67d16f48d2e46a4ee72ca12025aeb8d1f'
39
+ expect(subject['Authorization']).to eq "Uploadcare pub:#{expected}"
40
+ end
41
+ end
42
+
43
+
44
+ describe 'integration' do
45
+ let(:api){ Uploadcare::Api.new(auth_scheme: :secure) }
46
+ let(:file){ api.upload IMAGE_URL }
47
+
48
+ before(:each) do
49
+ # ensure that secure auth is being used
50
+ expect_any_instance_of(described_class).to receive(:apply).at_least(4).times.and_call_original
51
+ end
52
+
53
+ it 'auth works with real requests' do
54
+ # request with url params
55
+ expect{ api.get('/files/', limit: 1) }.not_to raise_error
56
+ # request with an url-encoded body
57
+ expect{
58
+ retry_if(Uploadcare::Error::RequestError::BadRequest) do
59
+ api.post('/files/', source: file.uuid)
60
+ end
61
+ }.not_to raise_error
62
+ # request with an empty body and a redirect
63
+ expect{ api.delete("/files/#{file.uuid}/storage/") }.not_to raise_error
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Uploadcare::Connections::Auth::Simple do
4
+ let(:env){ Faraday::Env.new(nil, nil, nil, nil, {}) }
5
+ subject{ described_class.new(public_key: 'pub', private_key: 'priv') }
6
+
7
+ describe 'apply' do
8
+ it "adds Authorization header to env's request_headers" do
9
+ subject.apply(env)
10
+ expect(env.request_headers).to include('Authorization')
11
+ end
12
+
13
+ it "sets Authorization header's value correctly" do
14
+ subject.apply(env)
15
+ expect(env.request_headers['Authorization']).to eq "Uploadcare.Simple pub:priv"
16
+ end
17
+ end
18
+
19
+ describe 'integration' do
20
+ let(:api){ Uploadcare::Api.new(auth_scheme: :simple) }
21
+
22
+ before(:each) do
23
+ # ensure that simple auth is being used
24
+ expect_any_instance_of(described_class).to receive(:apply).and_call_original
25
+ end
26
+
27
+ it 'auth works with real requests' do
28
+ expect{ api.get('/files/') }.not_to raise_error
29
+ end
30
+ end
31
+ end
@@ -7,7 +7,10 @@ require 'rspec'
7
7
  require 'uploadcare'
8
8
  require 'yaml'
9
9
 
10
- CONFIG = Uploadcare.default_settings
10
+ CONFIG = Uploadcare.default_settings.merge!(
11
+ public_key: ENV['UPLOADCARE_PUBLIC_KEY'] || 'demopublickey',
12
+ private_key: ENV['UPLOADCARE_SECRET_KEY'] || 'demoprivatekey',
13
+ )
11
14
  UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
12
15
 
13
16
  API = Uploadcare::Api.new(CONFIG)
@@ -22,3 +25,17 @@ config_file = File.join(File.dirname(__FILE__), 'config.yml')
22
25
  if File.exists?(config_file)
23
26
  CONFIG.update Hash[YAML.parse_file(config_file).to_ruby.map{|a, b| [a.to_sym, b]}]
24
27
  end
28
+
29
+ if CONFIG[:public_key] == 'demopublickey'
30
+ RSpec.configure do |c|
31
+ c.before(:example, :payed_feature){ skip "Unavailable for demo account" }
32
+ end
33
+ end
34
+
35
+ def retry_if(error, retries=5, &block)
36
+ block.call
37
+ rescue error
38
+ raise if retries <= 0
39
+ sleep 0.2
40
+ retry_if(error, retries-1, &block)
41
+ end
metadata CHANGED
@@ -1,113 +1,113 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uploadcare-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - "@rastyagaev (Vadim Rastyagaev)"
8
- - "@dimituri (Dimitry Solovyov)"
9
- - "@romanonthego (Roman Dubinin)"
7
+ - '@rastyagaev (Vadim Rastyagaev)'
8
+ - '@dimituri (Dimitry Solovyov)'
9
+ - '@romanonthego (Roman Dubinin)'
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-01-30 00:00:00.000000000 Z
13
+ date: 2017-03-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: faraday
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0.8'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0.8'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: faraday_middleware
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ~>
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0.9'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - "~>"
40
+ - - ~>
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0.9'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: multipart-post
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">="
47
+ - - '>='
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">="
54
+ - - '>='
55
55
  - !ruby/object:Gem::Version
56
56
  version: '0'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: mime-types
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">="
61
+ - - '>='
62
62
  - !ruby/object:Gem::Version
63
63
  version: '0'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - ">="
68
+ - - '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - "~>"
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: '3'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - "~>"
82
+ - - ~>
83
83
  - !ruby/object:Gem::Version
84
84
  version: '3'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: rake
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ">="
89
+ - - '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">="
96
+ - - '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: pry
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ">="
103
+ - - '>='
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - ">="
110
+ - - '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
113
  description: " Ruby wrapper for Uploadcare service API. \n
@@ -119,9 +119,9 @@ executables: []
119
119
  extensions: []
120
120
  extra_rdoc_files: []
121
121
  files:
122
- - ".DS_Store"
123
- - ".gitignore"
124
- - ".travis.yml"
122
+ - .DS_Store
123
+ - .gitignore
124
+ - .travis.yml
125
125
  - CHANGELOG.md
126
126
  - Gemfile
127
127
  - LICENSE
@@ -142,8 +142,12 @@ files:
142
142
  - lib/uploadcare/resources/group.rb
143
143
  - lib/uploadcare/resources/group_list.rb
144
144
  - lib/uploadcare/resources/project.rb
145
+ - lib/uploadcare/rest/auth/auth.rb
146
+ - lib/uploadcare/rest/auth/secure.rb
147
+ - lib/uploadcare/rest/auth/simple.rb
145
148
  - lib/uploadcare/rest/connections/api_connection.rb
146
149
  - lib/uploadcare/rest/connections/upload_connection.rb
150
+ - lib/uploadcare/rest/middlewares/auth_middleware.rb
147
151
  - lib/uploadcare/rest/middlewares/parse_json_middleware.rb
148
152
  - lib/uploadcare/rest/middlewares/raise_error_middleware.rb
149
153
  - lib/uploadcare/utils/parser.rb
@@ -156,6 +160,8 @@ files:
156
160
  - spec/resources/operations_spec.rb
157
161
  - spec/resources/project_spec.rb
158
162
  - spec/rest/api_connection_spec.rb
163
+ - spec/rest/auth/secure_spec.rb
164
+ - spec/rest/auth/simple_spec.rb
159
165
  - spec/rest/errors_spec.rb
160
166
  - spec/rest/upload_connection_spec.rb
161
167
  - spec/spec_helper.rb
@@ -178,17 +184,17 @@ require_paths:
178
184
  - lib
179
185
  required_ruby_version: !ruby/object:Gem::Requirement
180
186
  requirements:
181
- - - ">="
187
+ - - '>='
182
188
  - !ruby/object:Gem::Version
183
189
  version: '0'
184
190
  required_rubygems_version: !ruby/object:Gem::Requirement
185
191
  requirements:
186
- - - ">="
192
+ - - '>='
187
193
  - !ruby/object:Gem::Version
188
194
  version: '0'
189
195
  requirements: []
190
196
  rubyforge_project:
191
- rubygems_version: 2.5.1
197
+ rubygems_version: 2.0.14.1
192
198
  signing_key:
193
199
  specification_version: 4
194
200
  summary: Ruby gem for Uploadcare
@@ -201,6 +207,8 @@ test_files:
201
207
  - spec/resources/operations_spec.rb
202
208
  - spec/resources/project_spec.rb
203
209
  - spec/rest/api_connection_spec.rb
210
+ - spec/rest/auth/secure_spec.rb
211
+ - spec/rest/auth/simple_spec.rb
204
212
  - spec/rest/errors_spec.rb
205
213
  - spec/rest/upload_connection_spec.rb
206
214
  - spec/spec_helper.rb