require 'spec_helper' require 'spec_helper_features' describe 'Fetch proxy pac', :type => :feature do context '/v1/pac' do let(:valid_pac_file) do <<-EOS.strip_heredoc.chomp function FindProxyForURL(url, host) { return "DIRECT"; } EOS end let(:compressed_valid_pac_file) { "function FindProxyForURL(){return\"DIRECT\"}" } let(:git_repo) { File.join(working_directory, 'git_repo.git') } before :each do repo = GitRepository.create(git_repo) repo.add_content('file.pac', valid_pac_file) end before :each do config = Class.new do include FeduxOrg::Stdlib::Filesystem def root_directory ::File.expand_path('../../../', __FILE__) end def local_storage ::File.join(working_directory, 'git_repo.git') end end.new LocalPac.config = config Capybara.app = LocalPac::App::FileServeController end it 'finds an existing proxy pac' do visit('/file.pac') expect(page).to have_content('function FindProxyForURL(){return"DIRECT"}') end it 'exits with 404 if file does not exist' do visit('/does_not_exist.pac') expect(page.status_code).to eq(404) end it 'compresses data for transit if requested' do def app config = Class.new do include FeduxOrg::Stdlib::Filesystem def root_directory ::File.expand_path('../../../', __FILE__) end def local_storage ::File.join(working_directory, 'git_repo.git') end end.new LocalPac.config = config LocalPac::App::FileServeController end ['deflate','gzip', 'deflate,gzip','gzip,deflate'].each do|compression_method| response = get('/file.pac', {}, { 'HTTP_ACCEPT_ENCODING' => compression_method }) expect(response.headers['Content-Encoding']).to be end end it 'does not compresses data for transit if not requested' do def app config = Class.new do include FeduxOrg::Stdlib::Filesystem def root_directory ::File.expand_path('../../../', __FILE__) end def local_storage ::File.join(working_directory, 'git_repo.git') end end.new LocalPac.config = config LocalPac::App::FileServeController end ['deflate','gzip', 'deflate,gzip','gzip,deflate'].each do|compression_method| response = get('/does_not_exist.pac') expect(response.headers['Content-Encoding']).not_to be end end end end