Commit 0bb3bcc5 authored by atiwari71's avatar atiwari71

Update Coverage-Fuzzing yml and use last package file in corpus

Add COVFUZZ_PROJECT_PATH to Coverage-Fuzzing.gitlab-ci.yml.
Update corpus to use last package file instead of first package file.

Changelog: changed
EE: true
parent c55c7142
...@@ -35,22 +35,22 @@ module AppSec ...@@ -35,22 +35,22 @@ module AppSec
end end
def package_with_package_file def package_with_package_file
unless first_package_file unless latest_package_file
errors.add(:package_id, 'should have an associated package file') errors.add(:package_id, 'should have an associated package file')
end end
end end
def validate_file_format def validate_file_format
return unless first_package_file return unless latest_package_file
unless ACCEPTED_FORMATS.include? File.extname(first_package_file.file_name) unless ACCEPTED_FORMATS.include? File.extname(latest_package_file.file_name)
errors.add(:package_id, 'format is not supported') errors.add(:package_id, 'format is not supported')
end end
end end
# Currently we are only supporting one package_file per package for a corpus model. # Currently we are only supporting one package_file per package for a corpus model.
def first_package_file def latest_package_file
@package_file ||= package.package_files.first @package_file ||= package.package_files.last
end end
end end
end end
......
...@@ -29,21 +29,45 @@ RSpec.describe AppSec::Fuzzing::Coverage::Corpus, type: :model do ...@@ -29,21 +29,45 @@ RSpec.describe AppSec::Fuzzing::Coverage::Corpus, type: :model do
subject(:corpus) { build(:corpus, package: package, project: package.project) } subject(:corpus) { build(:corpus, package: package, project: package.project) }
it 'raises the error on adding the package file with different format' do context 'without a package file associated to the package' do
it 'raises the error' do
expect { corpus.save! }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Package should have an associated package file') expect { corpus.save! }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Package should have an associated package file')
end end
end end
context 'with a package file associated to the package' do
before do
create(:package_file, :generic_zip, package: package)
end
it 'saves the record successfully' do
expect(corpus.save).to be true
end
end
end
describe 'validate_file_format' do describe 'validate_file_format' do
let(:package_file) { create(:package_file) } let(:xml_package_file) { create(:package_file, :xml) }
let(:package) { package_file.package } let(:package) { xml_package_file.package }
subject(:corpus) { build(:corpus, package: package, project: package.project) } subject(:corpus) { build(:corpus, package: package, project: package.project) }
context 'with an invalid last package file' do
it 'raises the error on adding the package file with different format' do it 'raises the error on adding the package file with different format' do
expect { corpus.save! }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Package format is not supported') expect { corpus.save! }.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Package format is not supported')
end end
end end
context 'with a valid last package file' do
before do
create(:package_file, :generic_zip, package: package)
end
it 'saves the record successfully' do
expect(corpus.save).to be true
end
end
end
end end
describe 'validates' do describe 'validates' do
......
...@@ -33,6 +33,7 @@ coverage_fuzzing_unlicensed: ...@@ -33,6 +33,7 @@ coverage_fuzzing_unlicensed:
before_script: before_script:
- export COVFUZZ_JOB_TOKEN=$CI_JOB_TOKEN - export COVFUZZ_JOB_TOKEN=$CI_JOB_TOKEN
- export COVFUZZ_PRIVATE_TOKEN=$CI_PRIVATE_TOKEN - export COVFUZZ_PRIVATE_TOKEN=$CI_PRIVATE_TOKEN
- export COVFUZZ_PROJECT_PATH=$CI_PROJECT_PATH
- export COVFUZZ_PROJECT_ID=$CI_PROJECT_ID - export COVFUZZ_PROJECT_ID=$CI_PROJECT_ID
- if [ -x "$(command -v apt-get)" ] ; then apt-get update && apt-get install -y wget; fi - if [ -x "$(command -v apt-get)" ] ; then apt-get update && apt-get install -y wget; fi
- wget -O gitlab-cov-fuzz "${COVFUZZ_URL_PREFIX}"/"${COVFUZZ_VERSION}"/binaries/gitlab-cov-fuzz_Linux_x86_64 - wget -O gitlab-cov-fuzz "${COVFUZZ_URL_PREFIX}"/"${COVFUZZ_VERSION}"/binaries/gitlab-cov-fuzz_Linux_x86_64
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment