diff --git a/Integration-Test.ps1 b/Integration-Test.ps1 index 8e1d2fe..a93cf33 100644 --- a/Integration-Test.ps1 +++ b/Integration-Test.ps1 @@ -35,12 +35,27 @@ $Lines_To_Find = @( "using dependency library github.com/golang/snappy version 0.0.1. upgrade to at least version 0.0.2" ) +Write-Host "Setting up sample-projects" +# Copy all sample projects to temp directory and rename project manifests to correct format. +# This is done to avoid security scanning them for deprecated/vulnerable library dependancies +# These sample projects are not intended to be used in production, but are used for testing +$sample_projects_dir = Get-Random +Copy-Item -Path "./sample-projects" -Destination "./temp/$sample_projects_dir" -Recurse +Rename-Item -Path "./temp/$sample_projects_dir/dotnet-samples/sample_csproj_PLACEHOLDER" -NewName "sample.csproj" +Rename-Item -Path "./temp/$sample_projects_dir/go-samples/compatible/go_mod_PLACEHOLDER" -NewName "go.mod" +Rename-Item -Path "./temp/$sample_projects_dir/go-samples/incompatible/go_mod_PLACEHOLDER" -NewName "go.mod" +Rename-Item -Path "./temp/$sample_projects_dir/java-samples/pom_xml_PLACEHOLDER" -NewName "pom.xml" +Rename-Item -Path "./temp/$sample_projects_dir/node-samples/package_json_PLACEHOLDER" -NewName "package.json" +Rename-Item -Path "./temp/$sample_projects_dir/python-samples/compatible/requirements_txt_PLACEHOLDER" -NewName "requirements.txt" +Rename-Item -Path "./temp/$sample_projects_dir/python-samples/incompatible/requirements_txt_PLACEHOLDER" -NewName "requirements.txt" +Rename-Item -Path "./temp/$sample_projects_dir/ruby-samples/Gemfile_PLACEHOLDER" -NewName "Gemfile" + Write-Host "Running samples to console" -$ResultConsole = Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects" +$ResultConsole = Invoke-Expression ".\dist\$Filename\$Filename.exe .\temp\$sample_projects_dir" Test-Report "Console" $ResultConsole $Lines_To_Find Write-Host "Running samples to HTML report" -Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects --output test.html" +Invoke-Expression ".\dist\$Filename\$Filename.exe .\temp\$sample_projects_dir --output test.html" $ResultHtml = Get-Content -Path test.html Test-Report "HTML" $ResultHtml $Lines_To_Find Remove-Item -Path test.html @@ -86,7 +101,7 @@ $Dependencies = @( "httpclient" "jruby-openssl" ) -Invoke-Expression ".\dist\$Filename\$Filename.exe .\sample-projects --output test.xlsx --output-format dependencies" +Invoke-Expression ".\dist\$Filename\$Filename.exe .\temp\$sample_projects_dir --output test.xlsx --output-format dependencies" # xlsx files are compressed files, so we need to unzip them and then compare them Expand-Archive test.xlsx -DestinationPath temp $ResultXlsx = Get-Content ".\temp\xl\sharedStrings.xml" @@ -120,4 +135,6 @@ else Write-Host "**PASSED** directory not found test" } +Remove-Item -Recurse -Force $sample_project_directory + exit 0 \ No newline at end of file diff --git a/container-test.sh b/container-test.sh index 633b63c..8287f18 100755 --- a/container-test.sh +++ b/container-test.sh @@ -5,13 +5,16 @@ source ./test-helpers.sh # This script tests container image build and runs a couple of # tests against the generated image. +echo "Setting up sample-projects" +sample_project_directory=$(get_sample_projects_relative_path) + docker build -t porting-advisor . if [ $? -ne 0 ]; then echo "**ERROR**: building container image" && exit 1 fi echo "Running container on samples to console" -docker run --rm -v $(pwd)/sample-projects:/source porting-advisor /source > console_test.txt +docker run --rm -v $(pwd)/$sample_project_directory:/source porting-advisor /source > console_test.txt test_report 'console' 'console_test.txt' "${lines_to_find[@]}" if [ $? -ne 0 ]; then echo "**ERROR**: running container to console" && exit 1 @@ -19,7 +22,7 @@ fi rm console_test.txt echo "Running container on samples to HTML report" -docker run --rm -v $(pwd):/source porting-advisor /source/sample-projects --output /source/test.html +docker run --rm -v $(pwd):/source porting-advisor /source/$sample_project_directory --output /source/test.html test_report 'html' 'test.html' "${lines_to_find[@]}" if [ $? -ne 0 ]; then echo "**ERROR**: running container to html report" && exit 1 diff --git a/integration-test.sh b/integration-test.sh index a7e9be5..4615b10 100755 --- a/integration-test.sh +++ b/integration-test.sh @@ -5,14 +5,17 @@ source ./test-helpers.sh FILE_NAME=`./getBinaryName.sh` chmod +x ./dist/$FILE_NAME +echo "Setting up sample-projects" +sample_project_directory=$(get_sample_projects_relative_path) + echo "Running samples to console" -./dist/$FILE_NAME ./sample-projects/ > console_test.txt +./dist/$FILE_NAME $sample_project_directory > console_test.txt test_report 'console' 'console_test.txt' "${lines_to_find[@]}" rm console_test.txt echo "Running samples to HTML report" -./dist/$FILE_NAME ./sample-projects/ --output test.html +./dist/$FILE_NAME $sample_project_directory --output test.html test_report 'html' 'test.html' "${lines_to_find[@]}" rm test.html @@ -57,7 +60,7 @@ declare -a dependencies=("componentversionhttpclient" "jruby-openssl" ) -./dist/$FILE_NAME ./sample-projects/ --output test.xlsx --output-format dependencies +./dist/$FILE_NAME $sample_project_directory --output test.xlsx --output-format dependencies # xlsx files are compressed files, so we need to unzip them and then compare them mkdir ./temp unzip -q ./test.xlsx -d ./temp @@ -86,3 +89,5 @@ else echo "**FAILED**: directory not found test" && exit 1 fi rm directory_not_found_test.txt + +rm -r $sample_project_directory diff --git a/sample-projects/dotnet-samples/sample.csproj b/sample-projects/dotnet-samples/sample_csproj_PLACEHOLDER similarity index 100% rename from sample-projects/dotnet-samples/sample.csproj rename to sample-projects/dotnet-samples/sample_csproj_PLACEHOLDER diff --git a/sample-projects/go-samples/compatible/go.mod b/sample-projects/go-samples/compatible/go_mod_PLACEHOLDER similarity index 100% rename from sample-projects/go-samples/compatible/go.mod rename to sample-projects/go-samples/compatible/go_mod_PLACEHOLDER diff --git a/sample-projects/go-samples/incompatible/go.mod b/sample-projects/go-samples/incompatible/go_mod_PLACEHOLDER similarity index 100% rename from sample-projects/go-samples/incompatible/go.mod rename to sample-projects/go-samples/incompatible/go_mod_PLACEHOLDER diff --git a/sample-projects/java-samples/pom.xml b/sample-projects/java-samples/pom_xml_PLACEHOLDER similarity index 100% rename from sample-projects/java-samples/pom.xml rename to sample-projects/java-samples/pom_xml_PLACEHOLDER diff --git a/sample-projects/node-samples/package.json b/sample-projects/node-samples/package_json_PLACEHOLDER similarity index 100% rename from sample-projects/node-samples/package.json rename to sample-projects/node-samples/package_json_PLACEHOLDER diff --git a/sample-projects/python-samples/compatible/requirements.txt b/sample-projects/python-samples/compatible/requirements_txt_PLACEHOLDER similarity index 100% rename from sample-projects/python-samples/compatible/requirements.txt rename to sample-projects/python-samples/compatible/requirements_txt_PLACEHOLDER diff --git a/sample-projects/python-samples/incompatible/requirements.txt b/sample-projects/python-samples/incompatible/requirements_txt_PLACEHOLDER similarity index 100% rename from sample-projects/python-samples/incompatible/requirements.txt rename to sample-projects/python-samples/incompatible/requirements_txt_PLACEHOLDER diff --git a/sample-projects/ruby-samples/Gemfile b/sample-projects/ruby-samples/Gemfile_PLACEHOLDER similarity index 100% rename from sample-projects/ruby-samples/Gemfile rename to sample-projects/ruby-samples/Gemfile_PLACEHOLDER diff --git a/sample-projects/ruby-samples/sample.rb b/sample-projects/ruby-samples/sample.rb new file mode 100644 index 0000000..b85a042 --- /dev/null +++ b/sample-projects/ruby-samples/sample.rb @@ -0,0 +1 @@ +puts "Hello World" diff --git a/test-helpers.sh b/test-helpers.sh index ca386c6..5b1bdae 100755 --- a/test-helpers.sh +++ b/test-helpers.sh @@ -1,5 +1,23 @@ #!/bin/bash +function get_sample_projects_relative_path() { + # Copy all sample projects to temp directory and rename project manifests to correct format. + # This is done to avoid security scanning them for deprecated/vulnerable library dependancies + # These sample projects are not intended to be used in production, but are used for testing + sample_projects_dir=$RANDOM + mkdir -p ./temp/$sample_projects_dir && cp -r ./sample-projects/* ./temp/$sample_projects_dir + mv ./temp/$sample_projects_dir/dotnet-samples/sample_csproj_PLACEHOLDER ./temp/$sample_projects_dir/dotnet-samples/sample.csproj + mv ./temp/$sample_projects_dir/go-samples/compatible/go_mod_PLACEHOLDER ./temp/$sample_projects_dir/go-samples/compatible/go.mod + mv ./temp/$sample_projects_dir/go-samples/incompatible/go_mod_PLACEHOLDER ./temp/$sample_projects_dir/go-samples/incompatible/go.mod + mv ./temp/$sample_projects_dir/java-samples/pom_xml_PLACEHOLDER ./temp/$sample_projects_dir/java-samples/pom.xml + mv ./temp/$sample_projects_dir/node-samples/package_json_PLACEHOLDER ./temp/$sample_projects_dir/node-samples/package.json + mv ./temp/$sample_projects_dir/python-samples/compatible/requirements_txt_PLACEHOLDER ./temp/$sample_projects_dir/python-samples/compatible/requirements.txt + mv ./temp/$sample_projects_dir/python-samples/incompatible/requirements_txt_PLACEHOLDER ./temp/$sample_projects_dir/python-samples/incompatible/requirements.txt + mv ./temp/$sample_projects_dir/ruby-samples/Gemfile_PLACEHOLDER ./temp/$sample_projects_dir/ruby-samples/Gemfile + + echo ./temp/$sample_projects_dir +} + function test_line() { reportType=$1 result_filename=$2 diff --git a/unittest/test_manifester.py b/unittest/test_manifester.py index 3471fec..b4ebb86 100644 --- a/unittest/test_manifester.py +++ b/unittest/test_manifester.py @@ -148,11 +148,4 @@ def test_get_dependencies_for_ruby_returns_array_of_dependencies(self): self.assertEqual('6.1.6.1', dependencies[0].version) self.assertEqual('Gemfile', dependencies[0].filename) self.assertEqual('ruby', dependencies[0].tool) - - def test_scan_folder_returns_array_of_all_dependencies(self): - manifester = Manifester() - sample_path = path.abspath(path.join(path.dirname(__file__), '..', 'sample-projects')) - dependencies = manifester.scan_folder(sample_path) - self.assertGreater(len(dependencies), 0) - self.assertIsInstance(dependencies, list) - self.assertIsInstance(dependencies[0], Dependency) \ No newline at end of file + \ No newline at end of file