Add additional test case for new CodeOcean::File#read method
This commit is contained in:
@ -58,7 +58,7 @@ module CodeOcean
|
|||||||
|
|
||||||
def read
|
def read
|
||||||
if native_file?
|
if native_file?
|
||||||
valid = Pathname(native_file.current_path).fnmatch? ::File.join(native_file.root, '**')
|
valid = Pathname(native_file.current_path).realpath.fnmatch? ::File.join(native_file.root, '**')
|
||||||
return nil unless valid
|
return nil unless valid
|
||||||
|
|
||||||
native_file.read
|
native_file.read
|
||||||
|
@ -69,7 +69,26 @@ describe CodeOcean::File do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context 'when the path has been modified' do
|
context 'when the path has been modified' do
|
||||||
before { file.update(native_file: '../../../../secrets.yml') }
|
before do
|
||||||
|
file.update_column(:native_file, '../../../../secrets.yml') # rubocop:disable Rails/SkipsModelValidations
|
||||||
|
file.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not read the native file' do
|
||||||
|
expect(file.read).not_to be_present
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when a symlink is used' do
|
||||||
|
let(:fake_upload_location) { File.join(CarrierWave::Uploader::Base.new.root, 'uploads', 'files', 'secrets.yml') }
|
||||||
|
|
||||||
|
before do
|
||||||
|
File.symlink Rails.root.join('config/secrets.yml'), fake_upload_location
|
||||||
|
file.update_column(:native_file, '../secrets.yml') # rubocop:disable Rails/SkipsModelValidations
|
||||||
|
file.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
after { File.delete(fake_upload_location) }
|
||||||
|
|
||||||
it 'does not read the native file' do
|
it 'does not read the native file' do
|
||||||
expect(file.read).not_to be_present
|
expect(file.read).not_to be_present
|
||||||
|
Reference in New Issue
Block a user