carrierwave_direct 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -2
- data/Changelog.md +12 -1
- data/README.md +1 -1
- data/carrierwave_direct.gemspec +1 -1
- data/gemfiles/5.2.gemfile +13 -0
- data/lib/carrierwave_direct/form_builder.rb +30 -14
- data/lib/carrierwave_direct/mount.rb +1 -11
- data/lib/carrierwave_direct/policies/aws4_hmac_sha256.rb +93 -0
- data/lib/carrierwave_direct/policies/aws_base64_sha1.rb +57 -0
- data/lib/carrierwave_direct/policies/base.rb +21 -0
- data/lib/carrierwave_direct/uploader.rb +41 -76
- data/lib/carrierwave_direct/version.rb +1 -1
- data/spec/form_builder_spec.rb +11 -8
- data/spec/mount_spec.rb +2 -2
- data/spec/policies/aws4_hmac_sha256_spec.rb +243 -0
- data/spec/policies/aws_base64_sha1_spec.rb +229 -0
- data/spec/spec_helper.rb +5 -1
- data/spec/uploader_spec.rb +13 -31
- metadata +15 -10
- data/lib/carrierwave_direct/uploader/direct_url.rb +0 -16
- data/spec/uploader/direct_url_spec.rb +0 -26
data/spec/spec_helper.rb
CHANGED
@@ -3,7 +3,11 @@
|
|
3
3
|
require 'carrierwave_direct'
|
4
4
|
require 'json'
|
5
5
|
require 'timecop'
|
6
|
-
|
6
|
+
begin
|
7
|
+
require 'byebug'
|
8
|
+
rescue LoadError
|
9
|
+
puts "Byebug not installed"
|
10
|
+
end
|
7
11
|
|
8
12
|
require File.dirname(__FILE__) << '/support/view_helpers' # Catch dependency order
|
9
13
|
|
data/spec/uploader_spec.rb
CHANGED
@@ -7,10 +7,8 @@ describe CarrierWaveDirect::Uploader do
|
|
7
7
|
include ModelHelpers
|
8
8
|
|
9
9
|
let(:subject) { DirectUploader.new }
|
10
|
-
let(:mounted_model) {
|
10
|
+
let(:mounted_model) { MountedClass.new }
|
11
11
|
let(:mounted_subject) { DirectUploader.new(mounted_model, sample(:mounted_as)) }
|
12
|
-
let(:direct_subject) { DirectUploader.new }
|
13
|
-
|
14
12
|
|
15
13
|
DirectUploader.fog_credentials.keys.each do |key|
|
16
14
|
describe "##{key}" do
|
@@ -74,8 +72,9 @@ describe CarrierWaveDirect::Uploader do
|
|
74
72
|
context "but the uploaders url is '#{sample(:s3_file_url)}'" do
|
75
73
|
before do
|
76
74
|
allow(mounted_subject).to receive(:store_dir).and_return(sample(:store_dir))
|
77
|
-
allow(mounted_subject).to receive(:url).and_return(sample(:s3_file_url))
|
78
75
|
allow(mounted_subject).to receive(:present?).and_return(true)
|
76
|
+
allow(mounted_model).to receive(:video_identifier).and_return(sample(:stored_filename))
|
77
|
+
mounted_model.remote_video_url = sample(:s3_file_url)
|
79
78
|
end
|
80
79
|
|
81
80
|
it "should return '#{sample(:s3_key)}'" do
|
@@ -104,6 +103,14 @@ describe CarrierWaveDirect::Uploader do
|
|
104
103
|
end
|
105
104
|
end
|
106
105
|
|
106
|
+
describe "#direct_fog_url" do
|
107
|
+
it "should return the result from CarrierWave::Storage::Fog::File#public_url" do
|
108
|
+
expect(subject.direct_fog_url).to eq CarrierWave::Storage::Fog::File.new(
|
109
|
+
subject, nil, nil
|
110
|
+
).public_url
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
107
114
|
describe "#key_regexp" do
|
108
115
|
it "should return a regexp" do
|
109
116
|
expect(subject.key_regexp).to be_a(Regexp)
|
@@ -474,42 +481,17 @@ describe CarrierWaveDirect::Uploader do
|
|
474
481
|
end
|
475
482
|
end
|
476
483
|
|
477
|
-
describe "#signature" do
|
478
|
-
it "should not contain any new lines" do
|
479
|
-
expect(subject.signature).to_not include("\n")
|
480
|
-
end
|
481
|
-
|
482
|
-
it "should return a HMAC hexdigest encoded 'sha256' hash of the secret key and policy document" do
|
483
|
-
expect(subject.signature).to eq OpenSSL::HMAC.hexdigest(
|
484
|
-
OpenSSL::Digest.new('sha256'),
|
485
|
-
subject.send(:signing_key), subject.policy
|
486
|
-
)
|
487
|
-
end
|
488
|
-
end
|
489
|
-
#http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html
|
490
|
-
describe "#signature_key" do
|
491
|
-
it "should include correct signature_key elements" do
|
492
|
-
kDate = OpenSSL::HMAC.digest('sha256', "AWS4" + subject.aws_secret_access_key, Time.now.utc.strftime("%Y%m%d"))
|
493
|
-
kRegion = OpenSSL::HMAC.digest('sha256', kDate, subject.region)
|
494
|
-
kService = OpenSSL::HMAC.digest('sha256', kRegion, 's3')
|
495
|
-
kSigning = OpenSSL::HMAC.digest('sha256', kService, "aws4_request")
|
496
|
-
|
497
|
-
expect(subject.send(:signing_key)).to eq (kSigning)
|
498
|
-
end
|
499
|
-
end
|
500
|
-
|
501
|
-
|
502
484
|
# note that 'video' is hardcoded into the MountedClass support file
|
503
485
|
# so changing the sample will cause the tests to fail
|
504
486
|
context "a class has a '#{sample(:mounted_as)}' mounted" do
|
505
487
|
describe "#{sample(:mounted_as).to_s.capitalize}Uploader" do
|
506
488
|
describe "##{sample(:mounted_as)}" do
|
507
489
|
it "should be defined" do
|
508
|
-
expect(
|
490
|
+
expect(subject).to be_respond_to(sample(:mounted_as))
|
509
491
|
end
|
510
492
|
|
511
493
|
it "should return itself" do
|
512
|
-
expect(
|
494
|
+
expect(subject.send(sample(:mounted_as))).to eq subject
|
513
495
|
end
|
514
496
|
end
|
515
497
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave_direct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Wilkie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '3.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '3.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: timecop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- carrierwave_direct.gemspec
|
140
140
|
- gemfiles/4.2.gemfile
|
141
141
|
- gemfiles/5.1.gemfile
|
142
|
+
- gemfiles/5.2.gemfile
|
142
143
|
- lib/carrierwave_direct.rb
|
143
144
|
- lib/carrierwave_direct/action_view_extensions/form_helper.rb
|
144
145
|
- lib/carrierwave_direct/form_builder.rb
|
@@ -146,12 +147,14 @@ files:
|
|
146
147
|
- lib/carrierwave_direct/locale/nl.yml
|
147
148
|
- lib/carrierwave_direct/mount.rb
|
148
149
|
- lib/carrierwave_direct/orm/activerecord.rb
|
150
|
+
- lib/carrierwave_direct/policies/aws4_hmac_sha256.rb
|
151
|
+
- lib/carrierwave_direct/policies/aws_base64_sha1.rb
|
152
|
+
- lib/carrierwave_direct/policies/base.rb
|
149
153
|
- lib/carrierwave_direct/test/capybara_helpers.rb
|
150
154
|
- lib/carrierwave_direct/test/helpers.rb
|
151
155
|
- lib/carrierwave_direct/uploader.rb
|
152
156
|
- lib/carrierwave_direct/uploader/configuration.rb
|
153
157
|
- lib/carrierwave_direct/uploader/content_type.rb
|
154
|
-
- lib/carrierwave_direct/uploader/direct_url.rb
|
155
158
|
- lib/carrierwave_direct/validations/active_model.rb
|
156
159
|
- lib/carrierwave_direct/version.rb
|
157
160
|
- spec/action_view_extensions/form_helper_spec.rb
|
@@ -160,6 +163,8 @@ files:
|
|
160
163
|
- spec/mount_spec.rb
|
161
164
|
- spec/orm/activerecord_spec.rb
|
162
165
|
- spec/orm/indirect_activerecord_spec.rb
|
166
|
+
- spec/policies/aws4_hmac_sha256_spec.rb
|
167
|
+
- spec/policies/aws_base64_sha1_spec.rb
|
163
168
|
- spec/spec_helper.rb
|
164
169
|
- spec/support/carrier_wave_config.rb
|
165
170
|
- spec/support/direct_uploader.rb
|
@@ -173,7 +178,6 @@ files:
|
|
173
178
|
- spec/test/helpers_spec.rb
|
174
179
|
- spec/uploader/configuration_spec.rb
|
175
180
|
- spec/uploader/content_type_spec.rb
|
176
|
-
- spec/uploader/direct_url_spec.rb
|
177
181
|
- spec/uploader_spec.rb
|
178
182
|
homepage: https://github.com/dwilkie/carrierwave_direct
|
179
183
|
licenses: []
|
@@ -194,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
194
198
|
version: '0'
|
195
199
|
requirements: []
|
196
200
|
rubyforge_project: carrierwave_direct
|
197
|
-
rubygems_version: 2.
|
201
|
+
rubygems_version: 2.7.6
|
198
202
|
signing_key:
|
199
203
|
specification_version: 4
|
200
204
|
summary: Upload direct to S3 using CarrierWave
|
@@ -205,6 +209,8 @@ test_files:
|
|
205
209
|
- spec/mount_spec.rb
|
206
210
|
- spec/orm/activerecord_spec.rb
|
207
211
|
- spec/orm/indirect_activerecord_spec.rb
|
212
|
+
- spec/policies/aws4_hmac_sha256_spec.rb
|
213
|
+
- spec/policies/aws_base64_sha1_spec.rb
|
208
214
|
- spec/spec_helper.rb
|
209
215
|
- spec/support/carrier_wave_config.rb
|
210
216
|
- spec/support/direct_uploader.rb
|
@@ -218,5 +224,4 @@ test_files:
|
|
218
224
|
- spec/test/helpers_spec.rb
|
219
225
|
- spec/uploader/configuration_spec.rb
|
220
226
|
- spec/uploader/content_type_spec.rb
|
221
|
-
- spec/uploader/direct_url_spec.rb
|
222
227
|
- spec/uploader_spec.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module CarrierWaveDirect
|
2
|
-
module Uploader
|
3
|
-
module DirectUrl
|
4
|
-
|
5
|
-
def direct_fog_url(options = {})
|
6
|
-
if options[:with_path]
|
7
|
-
warn "calling `#direct_for_url` with :with_path is deprecated, please use `#url` instead."
|
8
|
-
url
|
9
|
-
else
|
10
|
-
CarrierWave::Storage::Fog::File.new(self, CarrierWave::Storage::Fog.new(self), nil).public_url
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'data/sample_data'
|
5
|
-
|
6
|
-
describe CarrierWaveDirect::Uploader::DirectUrl do
|
7
|
-
|
8
|
-
let(:subject) { DirectUploader.new }
|
9
|
-
|
10
|
-
let(:mounted_subject) { DirectUploader.new(mounted_model, sample(:mounted_as)) }
|
11
|
-
|
12
|
-
describe "#direct_fog_url" do
|
13
|
-
it "should return the result from CarrierWave::Storage::Fog::File#public_url" do
|
14
|
-
expect(subject.direct_fog_url).to eq CarrierWave::Storage::Fog::File.new(
|
15
|
-
subject, nil, nil
|
16
|
-
).public_url
|
17
|
-
end
|
18
|
-
|
19
|
-
context ":with_path => true" do
|
20
|
-
it "should return the full url set by carrierwave" do
|
21
|
-
allow(subject).to receive(:url).and_return("url")
|
22
|
-
expect(subject.direct_fog_url(:with_path => true)).to eq "url"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|