carrierwave_direct 0.0.16 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +14 -9
  3. data/Changelog.md +45 -1
  4. data/README.md +37 -23
  5. data/carrierwave_direct.gemspec +4 -3
  6. data/gemfiles/{3.2.gemfile → 5.1.gemfile} +3 -3
  7. data/gemfiles/{4.0.gemfile → 5.2.gemfile} +3 -3
  8. data/gemfiles/{4.1.gemfile → 6.0.gemfile} +3 -3
  9. data/gemfiles/6.1.gemfile +13 -0
  10. data/lib/carrierwave_direct/action_view_extensions/form_helper.rb +1 -1
  11. data/lib/carrierwave_direct/form_builder.rb +30 -12
  12. data/lib/carrierwave_direct/mount.rb +1 -11
  13. data/lib/carrierwave_direct/policies/aws4_hmac_sha256.rb +93 -0
  14. data/lib/carrierwave_direct/policies/aws_base64_sha1.rb +57 -0
  15. data/lib/carrierwave_direct/policies/base.rb +21 -0
  16. data/lib/carrierwave_direct/test/capybara_helpers.rb +3 -3
  17. data/lib/carrierwave_direct/test/helpers.rb +1 -1
  18. data/lib/carrierwave_direct/uploader.rb +55 -56
  19. data/lib/carrierwave_direct/validations/active_model.rb +2 -2
  20. data/lib/carrierwave_direct/version.rb +1 -1
  21. data/spec/form_builder_spec.rb +24 -15
  22. data/spec/mount_spec.rb +2 -2
  23. data/spec/orm/activerecord_spec.rb +11 -7
  24. data/spec/orm/indirect_activerecord_spec.rb +7 -1
  25. data/spec/policies/aws4_hmac_sha256_spec.rb +243 -0
  26. data/spec/policies/aws_base64_sha1_spec.rb +229 -0
  27. data/spec/spec_helper.rb +5 -0
  28. data/spec/support/carrier_wave_config.rb +1 -0
  29. data/spec/test/capybara_helpers_spec.rb +4 -4
  30. data/spec/test/helpers_spec.rb +3 -3
  31. data/spec/uploader_spec.rb +20 -26
  32. metadata +36 -18
  33. data/lib/carrierwave_direct/uploader/direct_url.rb +0 -15
  34. data/spec/uploader/direct_url_spec.rb +0 -26
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,11 @@
3
3
  require 'carrierwave_direct'
4
4
  require 'json'
5
5
  require 'timecop'
6
+ begin
7
+ require 'byebug'
8
+ rescue LoadError
9
+ puts "Byebug not installed"
10
+ end
6
11
 
7
12
  require File.dirname(__FILE__) << '/support/view_helpers' # Catch dependency order
8
13
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  CarrierWave.configure do |config|
4
+ config.fog_provider = 'fog/aws'
4
5
  config.fog_credentials = {
5
6
  :provider => 'AWS',
6
7
  :aws_access_key_id => 'AWS_ACCESS_KEY_ID',
@@ -15,8 +15,8 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
15
15
  allow(subject).to receive(:page).and_return(page)
16
16
  end
17
17
 
18
- def find_element_value(css, value, options = nil)
19
- if options
18
+ def find_element_value(css, value, **options)
19
+ if options.keys.any?
20
20
  allow(page).to receive(:find).with(css, options).and_return(selector)
21
21
  else
22
22
  allow(page).to receive(:find).with(css).and_return(selector)
@@ -36,10 +36,10 @@ describe CarrierWaveDirect::Test::CapybaraHelpers do
36
36
  describe "#upload_directly" do
37
37
  let(:uploader) { DirectUploader.new }
38
38
 
39
- def upload_directly(options = {})
39
+ def upload_directly(**options)
40
40
  options[:button_locator] ||= ""
41
41
  button_locator = options.delete(:button_locator)
42
- subject.upload_directly(uploader, button_locator, options)
42
+ subject.upload_directly(uploader, button_locator, **options)
43
43
  end
44
44
 
45
45
  def stub_common
@@ -19,7 +19,7 @@ describe CarrierWaveDirect::Test::Helpers do
19
19
 
20
20
  context "['exe', 'bmp']" do
21
21
  before do
22
- allow(direct_uploader).to receive(:extension_white_list).and_return(%w{exe bmp})
22
+ allow(direct_uploader).to receive(:extension_allowlist).and_return(%w{exe bmp})
23
23
  end
24
24
 
25
25
  it "should return '*/guid/filename.exe'" do
@@ -29,7 +29,7 @@ describe CarrierWaveDirect::Test::Helpers do
29
29
 
30
30
  context "[]" do
31
31
  before do
32
- allow(direct_uploader).to receive(:extension_white_list).and_return([])
32
+ allow(direct_uploader).to receive(:extension_allowlist).and_return([])
33
33
  end
34
34
 
35
35
  it_should_behave_like "returning the default extension"
@@ -37,7 +37,7 @@ describe CarrierWaveDirect::Test::Helpers do
37
37
 
38
38
  context "nil" do
39
39
  before do
40
- allow(direct_uploader).to receive(:extension_white_list).and_return(nil)
40
+ allow(direct_uploader).to receive(:extension_allowlist).and_return(nil)
41
41
  end
42
42
 
43
43
  it_should_behave_like "returning the default extension"
@@ -7,10 +7,8 @@ describe CarrierWaveDirect::Uploader do
7
7
  include ModelHelpers
8
8
 
9
9
  let(:subject) { DirectUploader.new }
10
- let(:mounted_model) { double(sample(:mounted_model_name), video_identifier: sample(:stored_filename)) }
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)
@@ -138,26 +145,26 @@ describe CarrierWaveDirect::Uploader do
138
145
  expect(subject.extension_regexp).to be_a(String)
139
146
  end
140
147
 
141
- context "where #extension_white_list returns nil" do
148
+ context "where #extension_allowlist returns nil" do
142
149
  before do
143
- allow(subject).to receive(:extension_white_list).and_return(nil)
150
+ allow(subject).to receive(:extension_allowlist).and_return(nil)
144
151
  end
145
152
 
146
153
  it_should_behave_like "a globally allowed file extension"
147
154
  end
148
155
 
149
- context "where #extension_white_list returns []" do
156
+ context "where #extension_allowlist returns []" do
150
157
  before do
151
- allow(subject).to receive(:extension_white_list).and_return([])
158
+ allow(subject).to receive(:extension_allowlist).and_return([])
152
159
  end
153
160
 
154
161
  it_should_behave_like "a globally allowed file extension"
155
162
  end
156
163
 
157
- context "where #extension_white_list returns ['exe', 'bmp']" do
164
+ context "where #extension_allowlist returns ['exe', 'bmp']" do
158
165
 
159
166
  before do
160
- allow(subject).to receive(:extension_white_list).and_return(%w{exe bmp})
167
+ allow(subject).to receive(:extension_allowlist).and_return(%w{exe bmp})
161
168
  end
162
169
 
163
170
  it "should return '(exe|bmp)'" do
@@ -275,6 +282,7 @@ describe CarrierWaveDirect::Uploader do
275
282
  end
276
283
 
277
284
  # http://aws.amazon.com/articles/1434?_encoding=UTF8
285
+ #http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html
278
286
  describe "#policy" do
279
287
 
280
288
 
@@ -473,31 +481,17 @@ describe CarrierWaveDirect::Uploader do
473
481
  end
474
482
  end
475
483
 
476
- describe "#signature" do
477
- it "should not contain any new lines" do
478
- expect(subject.signature).to_not include("\n")
479
- end
480
-
481
- it "should return a base64 encoded 'sha1' hash of the secret key and policy document" do
482
- expect(Base64.decode64(subject.signature)).to eq OpenSSL::HMAC.digest(
483
- OpenSSL::Digest.new('sha1'),
484
- subject.aws_secret_access_key, subject.policy
485
- )
486
- end
487
- end
488
-
489
-
490
484
  # note that 'video' is hardcoded into the MountedClass support file
491
485
  # so changing the sample will cause the tests to fail
492
486
  context "a class has a '#{sample(:mounted_as)}' mounted" do
493
487
  describe "#{sample(:mounted_as).to_s.capitalize}Uploader" do
494
488
  describe "##{sample(:mounted_as)}" do
495
489
  it "should be defined" do
496
- expect(direct_subject).to be_respond_to(sample(:mounted_as))
490
+ expect(subject).to be_respond_to(sample(:mounted_as))
497
491
  end
498
492
 
499
493
  it "should return itself" do
500
- expect(direct_subject.send(sample(:mounted_as))).to eq direct_subject
494
+ expect(subject.send(sample(:mounted_as))).to eq subject
501
495
  end
502
496
  end
503
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: 0.0.16
4
+ version: 3.0.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-07-02 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 2.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fog-aws
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 3.2.12
75
+ version: 5.1.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 3.2.12
82
+ version: 5.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: Process your uploads in the background by uploading directly to S3
112
126
  email:
113
127
  - dwilkie@gmail.com
@@ -123,9 +137,10 @@ files:
123
137
  - README.md
124
138
  - Rakefile
125
139
  - carrierwave_direct.gemspec
126
- - gemfiles/3.2.gemfile
127
- - gemfiles/4.0.gemfile
128
- - gemfiles/4.1.gemfile
140
+ - gemfiles/5.1.gemfile
141
+ - gemfiles/5.2.gemfile
142
+ - gemfiles/6.0.gemfile
143
+ - gemfiles/6.1.gemfile
129
144
  - lib/carrierwave_direct.rb
130
145
  - lib/carrierwave_direct/action_view_extensions/form_helper.rb
131
146
  - lib/carrierwave_direct/form_builder.rb
@@ -133,12 +148,14 @@ files:
133
148
  - lib/carrierwave_direct/locale/nl.yml
134
149
  - lib/carrierwave_direct/mount.rb
135
150
  - lib/carrierwave_direct/orm/activerecord.rb
151
+ - lib/carrierwave_direct/policies/aws4_hmac_sha256.rb
152
+ - lib/carrierwave_direct/policies/aws_base64_sha1.rb
153
+ - lib/carrierwave_direct/policies/base.rb
136
154
  - lib/carrierwave_direct/test/capybara_helpers.rb
137
155
  - lib/carrierwave_direct/test/helpers.rb
138
156
  - lib/carrierwave_direct/uploader.rb
139
157
  - lib/carrierwave_direct/uploader/configuration.rb
140
158
  - lib/carrierwave_direct/uploader/content_type.rb
141
- - lib/carrierwave_direct/uploader/direct_url.rb
142
159
  - lib/carrierwave_direct/validations/active_model.rb
143
160
  - lib/carrierwave_direct/version.rb
144
161
  - spec/action_view_extensions/form_helper_spec.rb
@@ -147,6 +164,8 @@ files:
147
164
  - spec/mount_spec.rb
148
165
  - spec/orm/activerecord_spec.rb
149
166
  - spec/orm/indirect_activerecord_spec.rb
167
+ - spec/policies/aws4_hmac_sha256_spec.rb
168
+ - spec/policies/aws_base64_sha1_spec.rb
150
169
  - spec/spec_helper.rb
151
170
  - spec/support/carrier_wave_config.rb
152
171
  - spec/support/direct_uploader.rb
@@ -160,7 +179,6 @@ files:
160
179
  - spec/test/helpers_spec.rb
161
180
  - spec/uploader/configuration_spec.rb
162
181
  - spec/uploader/content_type_spec.rb
163
- - spec/uploader/direct_url_spec.rb
164
182
  - spec/uploader_spec.rb
165
183
  homepage: https://github.com/dwilkie/carrierwave_direct
166
184
  licenses: []
@@ -180,8 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
198
  - !ruby/object:Gem::Version
181
199
  version: '0'
182
200
  requirements: []
183
- rubyforge_project: carrierwave_direct
184
- rubygems_version: 2.5.2.3
201
+ rubygems_version: 3.0.3
185
202
  signing_key:
186
203
  specification_version: 4
187
204
  summary: Upload direct to S3 using CarrierWave
@@ -192,6 +209,8 @@ test_files:
192
209
  - spec/mount_spec.rb
193
210
  - spec/orm/activerecord_spec.rb
194
211
  - spec/orm/indirect_activerecord_spec.rb
212
+ - spec/policies/aws4_hmac_sha256_spec.rb
213
+ - spec/policies/aws_base64_sha1_spec.rb
195
214
  - spec/spec_helper.rb
196
215
  - spec/support/carrier_wave_config.rb
197
216
  - spec/support/direct_uploader.rb
@@ -205,5 +224,4 @@ test_files:
205
224
  - spec/test/helpers_spec.rb
206
225
  - spec/uploader/configuration_spec.rb
207
226
  - spec/uploader/content_type_spec.rb
208
- - spec/uploader/direct_url_spec.rb
209
227
  - spec/uploader_spec.rb
@@ -1,15 +0,0 @@
1
- module CarrierWaveDirect
2
- module Uploader
3
- module DirectUrl
4
-
5
- def direct_fog_url(options = {})
6
- if options[:with_path]
7
- url
8
- else
9
- CarrierWave::Storage::Fog::File.new(self, CarrierWave::Storage::Fog.new(self), nil).public_url
10
- end
11
- end
12
-
13
- end
14
- end
15
- 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