diff options
| -rw-r--r-- | spec/integration/dotnet/nuget_spec.rb | 2 | ||||
| -rw-r--r-- | spec/integration/go/modules_spec.rb | 2 | ||||
| -rw-r--r-- | spec/integration/java/gradle_spec.rb | 6 | ||||
| -rw-r--r-- | spec/integration/java/maven_spec.rb | 6 | ||||
| -rw-r--r-- | spec/integration/js/bower_spec.rb | 7 | ||||
| -rw-r--r-- | spec/integration/js/npm_spec.rb | 3 | ||||
| -rw-r--r-- | spec/integration/js/yarn_spec.rb | 3 | ||||
| -rw-r--r-- | spec/integration/php/composer_spec.rb | 2 | ||||
| -rw-r--r-- | spec/integration/python/pip_spec.rb | 3 | ||||
| -rw-r--r-- | spec/integration/python/pipenv_spec.rb | 3 | ||||
| -rw-r--r-- | spec/integration/ruby/bundler_spec.rb | 2 | ||||
| -rw-r--r-- | spec/integration/rust/cargo_spec.rb | 2 | ||||
| -rw-r--r-- | spec/support/integration_test_helper.rb | 6 | ||||
| -rw-r--r-- | spec/support/proxy_helper.rb | 23 |
14 files changed, 25 insertions, 45 deletions
diff --git a/spec/integration/dotnet/nuget_spec.rb b/spec/integration/dotnet/nuget_spec.rb index 0439125..fb8cb91 100644 --- a/spec/integration/dotnet/nuget_spec.rb +++ b/spec/integration/dotnet/nuget_spec.rb @@ -202,8 +202,6 @@ RSpec.describe "nuget" do context "when fetching dependencies from a custom registry" do before do - add_host('nuget.test', '127.0.0.1') - start_proxy_server runner.mount(dir: fixture_file('dotnet/nuget-custom-tls')) end diff --git a/spec/integration/go/modules_spec.rb b/spec/integration/go/modules_spec.rb index 2048bdb..788e264 100644 --- a/spec/integration/go/modules_spec.rb +++ b/spec/integration/go/modules_spec.rb @@ -107,8 +107,6 @@ RSpec.describe "modules" do context "when scanning a project sourced from a TLS endpoint with a X.509 certificate signed by a private authority" do before do - add_host('goproxy.test', '127.0.0.1') - start_proxy_server runner.mount(dir: fixture_file('go/1.14-ignore-tls')) end diff --git a/spec/integration/java/gradle_spec.rb b/spec/integration/java/gradle_spec.rb index e6bda3c..48a602f 100644 --- a/spec/integration/java/gradle_spec.rb +++ b/spec/integration/java/gradle_spec.rb @@ -55,15 +55,11 @@ plugins { subject do runner.scan(env: { 'ADDITIONAL_CA_CERT_BUNDLE' => x509_certificate('wildcard.test').read, - 'PRIVATE_MAVEN_HOST' => private_maven_host + 'PRIVATE_MAVEN_HOST' => 'maven.test' }) end - let(:private_maven_host) { 'maven.test' } - before do - add_host('maven.test', '127.0.0.1') - start_proxy_server runner.mount(dir: fixture_file('java/gradle/offline-environment')) end diff --git a/spec/integration/java/maven_spec.rb b/spec/integration/java/maven_spec.rb index 217035d..4061b65 100644 --- a/spec/integration/java/maven_spec.rb +++ b/spec/integration/java/maven_spec.rb @@ -92,19 +92,15 @@ RSpec.describe "maven" do context "when connecting to a custom package registry with a self signed certificate" do let(:report) { runner.scan(env: { 'ADDITIONAL_CA_CERT_BUNDLE' => x509_certificate('wildcard.test').read }) } - let(:private_maven_host) { 'maven.test' } before do - add_host('maven.test', '127.0.0.1') - start_proxy_server - runner.add_file('pom.xml') do fixture_file_content('java/maven/pom-single.xml.erb', { group_id: 'com.fasterxml.jackson.core', artifact_id: 'jackson-core', version: '2.10.0', repository_id: 'custom', - repository_url: "https://#{private_maven_host}/maven2" + repository_url: "https://maven.test/maven2" }) end end diff --git a/spec/integration/js/bower_spec.rb b/spec/integration/js/bower_spec.rb index 1bb366e..95617d6 100644 --- a/spec/integration/js/bower_spec.rb +++ b/spec/integration/js/bower_spec.rb @@ -29,13 +29,8 @@ RSpec.describe "bower" do context "when scanning a bower project with a dependency from a custom npm registry" do subject { runner.scan(env: { 'ADDITIONAL_CA_CERT_BUNDLE' => x509_certificate('wildcard.test').read }) } - let(:private_npm_host) { 'npm.test' } - before do - add_host(private_npm_host, '127.0.0.1') - start_proxy_server - - runner.add_file(".npmrc", "registry = https://#{private_npm_host}") + runner.add_file(".npmrc", "registry = https://npm.test") runner.add_file(".bowerrc") do JSON.pretty_generate({ resolvers: ['bower-npm-resolver'] }) end diff --git a/spec/integration/js/npm_spec.rb b/spec/integration/js/npm_spec.rb index 1481748..bd74fd7 100644 --- a/spec/integration/js/npm_spec.rb +++ b/spec/integration/js/npm_spec.rb @@ -475,9 +475,6 @@ RSpec.describe "npm" do let(:private_npm_host) { 'npm.test' } before do - add_host('npm.test', '127.0.0.1') - start_proxy_server - runner.add_file(".npmrc", "registry = https://#{private_npm_host}") runner.add_file("package.json") do JSON.pretty_generate({ diff --git a/spec/integration/js/yarn_spec.rb b/spec/integration/js/yarn_spec.rb index 5b1f9c5..8fcda9c 100644 --- a/spec/integration/js/yarn_spec.rb +++ b/spec/integration/js/yarn_spec.rb @@ -158,9 +158,6 @@ RSpec.describe "yarn" do let(:private_npm_host) { 'npm.test' } before do - add_host('npm.test', '127.0.0.1') - start_proxy_server - runner.add_file(".yarnrc.yml", "npmRegistryServer: \"https://#{private_npm_host}\"") runner.add_file("package.json") do diff --git a/spec/integration/php/composer_spec.rb b/spec/integration/php/composer_spec.rb index 9f71541..383bc94 100644 --- a/spec/integration/php/composer_spec.rb +++ b/spec/integration/php/composer_spec.rb @@ -101,8 +101,6 @@ RSpec.describe "composer" do context "when fetching dependencies from a custom registry" do before do - add_host('composer.test', '127.0.0.1') - start_proxy_server runner.mount(dir: fixture_file('php/composer/custom-tls')) end diff --git a/spec/integration/python/pip_spec.rb b/spec/integration/python/pip_spec.rb index 8b7d43b..b2e55b2 100644 --- a/spec/integration/python/pip_spec.rb +++ b/spec/integration/python/pip_spec.rb @@ -166,9 +166,6 @@ RSpec.describe "pip" do let(:index_url) { "https://pypi.test/simple" } before do - add_host('pypi.test', '127.0.0.1') - start_proxy_server - runner.add_file('setup.py') do <<~RAW from setuptools import setup, find_packages diff --git a/spec/integration/python/pipenv_spec.rb b/spec/integration/python/pipenv_spec.rb index fad3edf..74e1c6e 100644 --- a/spec/integration/python/pipenv_spec.rb +++ b/spec/integration/python/pipenv_spec.rb @@ -219,9 +219,6 @@ RSpec.describe "pipenv" do end before do - add_host('pypi.test', '127.0.0.1') - start_proxy_server - runner.add_file('Pipfile', fixture_file_content('python/airgap-Pipfile.erb', index_url: index_url)) runner.add_file('Pipfile.lock', fixture_file_content('python/airgap-Pipfile.lock.erb', index_url: index_url)) end diff --git a/spec/integration/ruby/bundler_spec.rb b/spec/integration/ruby/bundler_spec.rb index b70c67e..5020d3f 100644 --- a/spec/integration/ruby/bundler_spec.rb +++ b/spec/integration/ruby/bundler_spec.rb @@ -95,8 +95,6 @@ RSpec.describe "bundler" do context "when fetching dependencies from a custom registry" do before do - add_host('rubygems.test', '127.0.0.1') - start_proxy_server runner.mount(dir: fixture_file('ruby/bundler-custom-tls')) end diff --git a/spec/integration/rust/cargo_spec.rb b/spec/integration/rust/cargo_spec.rb index a0f2550..cdb4834 100644 --- a/spec/integration/rust/cargo_spec.rb +++ b/spec/integration/rust/cargo_spec.rb @@ -29,8 +29,6 @@ RSpec.describe "cargo" do context "when fetching dependencies from a custom registry" do before do - add_host('cargo.test', '127.0.0.1') - start_proxy_server runner.mount(dir: fixture_file('rust/cargo/custom-tls')) end diff --git a/spec/support/integration_test_helper.rb b/spec/support/integration_test_helper.rb index ec92fb8..7033799 100644 --- a/spec/support/integration_test_helper.rb +++ b/spec/support/integration_test_helper.rb @@ -4,10 +4,4 @@ module IntegrationTestHelper def runner(*args) @runner ||= ProjectHelper.new(*args) end - - def add_host(name, ip) - return if system("grep #{name} /etc/hosts") - - system("echo '#{ip} #{name}' >> /etc/hosts") - end end diff --git a/spec/support/proxy_helper.rb b/spec/support/proxy_helper.rb index 63b3910..8238167 100644 --- a/spec/support/proxy_helper.rb +++ b/spec/support/proxy_helper.rb @@ -1,15 +1,26 @@ # frozen_string_literal: true module ProxyHelper + DOMAINS = [ + 'composer.test', + 'goproxy.test', + 'maven.test', + 'npm.test', + 'nuget.test', + 'pypi.test', + 'rubygems.test' + ].freeze + def x509_certificate(host) License::Management.root.join("tmp/#{host}.crt") end def generate_self_signed_certificate_for(host) Dir.chdir License::Management.root.join('tmp') do + subject_alternative_names = DOMAINS.map { |x| "DNS:#{x}" }.join(',') system([ "rm -f #{host}.*", - "/usr/bin/openssl req -x509 -newkey rsa:4096 -keyout #{host}.key -out #{host}.crt -days 999 -nodes -subj '/C=/ST=/L=/O=/OU=/CN=*.test' -addext 'subjectAltName=DNS:nuget.test,DNS:rubygems.test,DNS:goproxy.test,DNS:maven.test,DNS:pypi.test,DNS:npm.test,DNS:composer.test'", + "/usr/bin/openssl req -x509 -newkey rsa:4096 -keyout #{host}.key -out #{host}.crt -days 999 -nodes -subj '/C=/ST=/L=/O=/OU=/CN=*.test' -addext 'subjectAltName=#{subject_alternative_names}'", "cat #{host}.* > #{host}.pem" ].join("&&")) end @@ -18,11 +29,18 @@ module ProxyHelper def start_proxy_server @proxy_server_pid ||= begin + DOMAINS.each { |domain| add_host(domain, '127.0.0.1') } generate_self_signed_certificate_for('wildcard.test') spawn("/usr/sbin/haproxy -f #{fixture_file('haproxy.cfg')}") end end + def add_host(name, ip) + return if system("grep #{name} /etc/hosts") + + system("echo '#{ip} #{name}' >> /etc/hosts") + end + def stop_proxy_server return if !defined?(@proxy_server_pid) || @proxy_server_pid.nil? @@ -34,6 +52,9 @@ end RSpec.configure do |config| config.include(ProxyHelper, type: :integration) + config.before(:example, type: :integration) do + start_proxy_server + end config.after(:example, type: :integration) do stop_proxy_server |
