-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1099 from texpert/fix-uploads-to-aws-s3-folder
Fix uploads to AWS S3 folder
- Loading branch information
Showing
13 changed files
with
120 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
spec/requests/admin/media_controller/download_private_file_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Download private file requests', type: :request do | ||
init_site | ||
|
||
let(:current_site) { Cama::Site.first.decorate } | ||
|
||
before do | ||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:cama_authenticate) | ||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:current_site).and_return(current_site) | ||
end | ||
|
||
context 'when the file path is valid and file exists' do | ||
before do | ||
allow_any_instance_of(CamaleonCmsLocalUploader).to receive(:fetch_file).and_return('some_file') | ||
|
||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:send_file) | ||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:default_render) | ||
end | ||
|
||
it 'allows the file to be downloaded' do | ||
expect_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:send_file).with('some_file', disposition: 'inline') | ||
|
||
get '/admin/media/download_private_file', params: { file: 'some_file' } | ||
end | ||
end | ||
|
||
context 'when file path is invalid' do | ||
it 'returns invalid file path error' do | ||
get '/admin/media/download_private_file', params: { file: './../../../../../etc/passwd' } | ||
|
||
expect(response.body).to include('Invalid file path') | ||
end | ||
end | ||
|
||
context 'when the file is not found' do | ||
it 'returns file not found error' do | ||
get '/admin/media/download_private_file', params: { file: 'passwd' } | ||
|
||
expect(response.body).to include('File not found') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'New folder request', type: :request do | ||
init_site | ||
|
||
let(:current_site) { Cama::Site.first.decorate } | ||
|
||
before do | ||
allow_any_instance_of(CamaleonCms::AdminController).to receive(:cama_authenticate) | ||
allow_any_instance_of(CamaleonCms::AdminController).to receive(:current_site).and_return(current_site) | ||
allow_any_instance_of(CamaleonCms::Admin::MediaController).to receive(:authorize!) | ||
end | ||
|
||
context 'when the folder path is valid' do | ||
it 'creates the new folder' do | ||
post '/admin/media/actions', params: { folder: '/test2', media_action: 'new_folder' } | ||
|
||
expect(Dir).to exist(File.join(current_site.upload_directory, '/test2')) | ||
end | ||
end | ||
|
||
context 'when the folder path is invalid' do | ||
it 'returns invalid file path error' do | ||
post '/admin/media/actions', params: { folder: '/../test3', media_action: 'new_folder' } | ||
|
||
expect(Dir).not_to exist(File.join(current_site.upload_directory, '/../test3')) | ||
|
||
expect(response.body).to include('Invalid folder path') | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters