# encoding: utf-8 require 'spec_helper' require 'spec_helper_features' describe 'Lookup proxy for url' do context '/v1/githook' do let(:valid_pac_file1) do <<-EOS.strip_heredoc.chomp function FindProxyForURL(url, host) { return "DIRECT"; } EOS end let(:valid_pac_file2) do <<-EOS.strip_heredoc.chomp function FindProxyForURL(url, host) { return "PROXY 127.0.0.1:3128"; } EOS end let(:valid_pac_file3) do <<-EOS.strip_heredoc.chomp function FindProxyForURL(url, host) { return "PROXY 10.0.0.1:3128"; } EOS end let(:git_repo_path) { File.join(working_directory, 'git_repo.git') } let(:git_repo) { GitRepository.create(git_repo_path) } 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 def api_key SecureRandom.hex end end.new LocalPac.config = config Capybara.app = LocalPac::App::GitHookController end context 'checks proxy.pac' do it 'succeeds on valid proxy pac' do oid1 = git_repo.add_content('file1.pac', valid_pac_file1) oid2 = git_repo.add_content('file2.pac', valid_pac_file2) repo = Rugged::Repository.new(git_repo_path) commit1 = repo.lookup(oid1) commit2 = repo.lookup(oid2) params = { old_commit_id: commit1.oid, new_commit_id: commit2.oid, reference: 'refs/heads/master', api_key: LocalPac.config.api_key } response = page.driver.post('/pre-receive', params ) result = JSON.parse(response.body)['result'] expect(result).to eq('success') end it 'fails on invalid proxy.pac' do oid1 = git_repo.add_content('file1.pac', valid_pac_file1) oid2 = git_repo.add_content('dir/file2.pac', 'asdf()') oid3 = git_repo.add_content('dir/file3.pac', valid_pac_file3) repo = Rugged::Repository.new(git_repo_path) commit1 = repo.lookup(oid1) commit2 = repo.lookup(oid2) commit3 = repo.lookup(oid3) params = { old_commit_id: commit1.oid, new_commit_id: commit3.oid, reference: 'refs/heads/master', api_key: LocalPac.config.api_key } response = page.driver.post('/pre-receive', params ) result = JSON.parse(response.body)['error_summary'] expect(result).to eq('Invalid PAC-file...') expect(response.status).to eq(403) end end it 'returns a error message for an invalid url' do visit('/blub-gith-hook') expect(page).to have_content('Unknown git hook...') expect(page).to have_content('/blub-gith-hook') end end end