debian-mirror-gitlab/spec/lib/safe_zip/extract_params_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.1 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2019-02-02 18:00:53 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe SafeZip::ExtractParams do
2019-02-02 18:00:53 +05:30
let(:target_path) { Dir.mktmpdir("safe-zip") }
2023-02-26 17:17:37 +05:30
let(:real_target_path) { File.realpath(target_path) }
let(:params) { described_class.new(directories: directories, files: files, to: target_path) }
2019-02-02 18:00:53 +05:30
let(:directories) { %w(public folder/with/subfolder) }
2023-02-26 17:17:37 +05:30
let(:files) { %w(public/index.html public/assets/image.png) }
2019-02-02 18:00:53 +05:30
after do
FileUtils.remove_entry_secure(target_path)
end
describe '#extract_path' do
subject { params.extract_path }
2023-02-26 17:17:37 +05:30
it { is_expected.to eq(real_target_path) }
2019-02-02 18:00:53 +05:30
end
describe '#matching_target_directory' do
using RSpec::Parameterized::TableSyntax
2023-02-26 17:17:37 +05:30
subject { params.matching_target_directory(real_target_path + path) }
2019-02-02 18:00:53 +05:30
where(:path, :result) do
'/public/index.html' | '/public/'
'/non/existing/path' | nil
'/public' | nil
'/folder/with/index.html' | nil
end
with_them do
2023-02-26 17:17:37 +05:30
it { is_expected.to eq(result ? real_target_path + result : nil) }
2019-02-02 18:00:53 +05:30
end
end
describe '#target_directories' do
subject { params.target_directories }
it 'starts with target_path' do
2023-02-26 17:17:37 +05:30
is_expected.to all(start_with(real_target_path + '/'))
2019-02-02 18:00:53 +05:30
end
it 'ends with / for all paths' do
is_expected.to all(end_with('/'))
end
end
describe '#directories_wildcard' do
subject { params.directories_wildcard }
it 'adds * for all paths' do
is_expected.to all(end_with('/*'))
end
end
2023-02-26 17:17:37 +05:30
describe '#matching_target_file' do
using RSpec::Parameterized::TableSyntax
subject { params.matching_target_file(real_target_path + path) }
where(:path, :result) do
'/public/index.html' | true
'/non/existing/path' | false
'/public/' | false
'/folder/with/index.html' | false
end
with_them do
it { is_expected.to eq(result) }
end
end
context 'when directories and files are empty' do
it 'is invalid' do
expect { described_class.new(to: target_path) }.to raise_error(ArgumentError, /directories or files are required/)
end
end
2019-02-02 18:00:53 +05:30
end