Commit 905a0f73 authored by Fernando Arias's avatar Fernando Arias Committed by David Fernandez

Fix corpus delete by updating corpus fetch

Filter out corpuses to only get :hidden ones

Changelog: fixed
EE: true
parent 7199516c
......@@ -11,7 +11,7 @@ module AppSec
end
def execute
AppSec::Fuzzing::Coverage::Corpus.by_project_id(project)
AppSec::Fuzzing::Coverage::Corpus.by_project_id_and_status_hidden(project)
end
end
end
......
......@@ -18,8 +18,8 @@ module AppSec
validates :package_id, uniqueness: true
scope :by_project_id, -> (project_id) do
joins(:package).where(package: { project_id: project_id })
scope :by_project_id_and_status_hidden, -> (project_id) do
joins(:package).where(package: { project_id: project_id, status: :hidden })
end
def audit_details
......
......@@ -5,4 +5,4 @@ rollout_issue_url:
milestone: '13.9'
type: development
group: group::fuzz testing
default_enabled: false
default_enabled: false
\ No newline at end of file
......@@ -4,6 +4,6 @@ FactoryBot.define do
factory :corpus, class: 'AppSec::Fuzzing::Coverage::Corpus' do
user
project
package { association(:generic_package, :with_zip_file, project: project) }
package { association(:generic_package, :with_zip_file, project: project, status: :hidden) }
end
end
......@@ -3,9 +3,7 @@
require 'spec_helper'
RSpec.describe AppSec::Fuzzing::Coverage::Corpus, type: :model do
let(:corpus) { create(:corpus) }
subject { corpus }
subject(:corpus) { create(:corpus) }
describe 'associations' do
it { is_expected.to belong_to(:package).class_name('Packages::Package') }
......@@ -75,15 +73,27 @@ RSpec.describe AppSec::Fuzzing::Coverage::Corpus, type: :model do
end
describe 'scopes' do
describe 'by_project_id' do
it 'includes the correct records' do
another_corpus_profile = create(:corpus)
describe '.by_project_id_and_status_hidden' do
subject(:find_corpuses) { described_class.by_project_id_and_status_hidden(corpus.package.project_id) }
context 'with another_corpus having different project_id' do
it 'includes the correct records' do
another_corpus = create(:corpus)
result = described_class.by_project_id(subject.package.project_id)
aggregate_failures do
expect(find_corpuses).to include(corpus)
expect(find_corpuses).not_to include(another_corpus)
end
end
end
context "with another_corpus having same project with different status apart from hidden" do
before do
corpus.package.update!(status: :pending_destruction)
end
aggregate_failures do
expect(result).to include(subject)
expect(result).not_to include(another_corpus_profile)
it 'includes the correct records' do
expect(find_corpuses).not_to include(corpus)
end
end
end
......
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