Skip to content

Commit

Permalink
get selected modules should be driven from the detailed report module…
Browse files Browse the repository at this point in the history
… selection
  • Loading branch information
antfie committed Mar 7, 2024
1 parent d7a0e8b commit 1f818f3
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 54 deletions.
3 changes: 1 addition & 2 deletions checks/dependencies_selected_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ func TestDependenciesSelected(t *testing.T) {
Modules: []report.Module{
{Name: "Test",
Instances: []report.ModuleInstance{
{IsDependency: true},
{IsSelected: true},
{IsDependency: true, IsSelected: true, Source: report.DetailedReportModuleSelected},
}},
},
}
Expand Down
3 changes: 3 additions & 0 deletions checks/general_recommendations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func TestGeneralRecommendations(t *testing.T) {
Instances: []report.ModuleInstance{{
IsSelected: false,
HasFatalErrors: false,
Source: report.DetailedReportModuleSelected,
}},
},
{Name: "gradle-wrapper.jar",
Expand All @@ -105,6 +106,7 @@ func TestGeneralRecommendations(t *testing.T) {
Instances: []report.ModuleInstance{{
IsSelected: true,
HasFatalErrors: false,
Source: report.DetailedReportModuleSelected,
}},
},
{Name: "test.jar",
Expand All @@ -113,6 +115,7 @@ func TestGeneralRecommendations(t *testing.T) {
Instances: []report.ModuleInstance{{
IsSelected: false,
HasFatalErrors: false,
Source: report.DetailedReportModuleSelected,
}},
},
},
Expand Down
3 changes: 3 additions & 0 deletions checks/gradle_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestGradleWrapper(t *testing.T) {
Instances: []report.ModuleInstance{{
IsSelected: false,
HasFatalErrors: false,
Source: report.DetailedReportModuleSelected,
}},
},
{Name: "gradle-wrapper.jar",
Expand All @@ -50,6 +51,7 @@ func TestGradleWrapper(t *testing.T) {
Instances: []report.ModuleInstance{{
IsSelected: true,
HasFatalErrors: false,
Source: report.DetailedReportModuleSelected,
}},
},
{Name: "test.jar",
Expand All @@ -58,6 +60,7 @@ func TestGradleWrapper(t *testing.T) {
Instances: []report.ModuleInstance{{
IsSelected: false,
HasFatalErrors: false,
Source: report.DetailedReportModuleSelected,
}},
},
},
Expand Down
12 changes: 6 additions & 6 deletions checks/missing_precompiled_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func TestMissingPrecompiledFiles(t *testing.T) {
t.Parallel()
testReport := report.Report{
Modules: []report.Module{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true},
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected},
{Issues: []string{"No precompiled files were found for this .NET web application"}}},
},
},
Expand All @@ -113,11 +113,11 @@ func TestMissingPrecompiledFiles(t *testing.T) {
t.Parallel()
testReport := report.Report{
Modules: []report.Module{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true},
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected},
{Issues: []string{"No precompiled files were found for this .NET web application"}}},
},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected},
{Issues: []string{"No precompiled files were found for this .NET web application"}}},
},
},
Expand Down
24 changes: 12 additions & 12 deletions checks/missing_supporting_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func TestMissingSupportingFiles(t *testing.T) {
t.Parallel()
testReport := report.Report{
Modules: []report.Module{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}, {Issues: []string{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}, {Issues: []string{
"Missing Supporting Files - 1 File",
}}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: false}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: false, Source: report.DetailedReportModuleSelected}}},
},
Issues: []report.Issue{},
}
Expand All @@ -51,11 +51,11 @@ func TestMissingSupportingFiles(t *testing.T) {
t.Parallel()
testReport := report.Report{
Modules: []report.Module{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}, {Issues: []string{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}, {Issues: []string{
"Missing Supporting Files - 3 Files",
}}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: false}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: false, Source: report.DetailedReportModuleSelected}}},
},
Issues: []report.Issue{},
}
Expand All @@ -73,14 +73,14 @@ func TestMissingSupportingFiles(t *testing.T) {
t.Parallel()
testReport := report.Report{
Modules: []report.Module{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}, {Issues: []string{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}, {Issues: []string{
"Missing Supporting Files - 1 File",
"Missing Supporting Files - 1 File",
"Missing Supporting Files - 1 File",
"Missing Supporting Files - 1 File",
}}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: false}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: false, Source: report.DetailedReportModuleSelected}}},
},
Issues: []report.Issue{},
}
Expand All @@ -98,13 +98,13 @@ func TestMissingSupportingFiles(t *testing.T) {
t.Parallel()
testReport := report.Report{
Modules: []report.Module{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}, {Issues: []string{
{Name: "file1.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}, {Issues: []string{
"Missing Supporting Files - 1 File",
}}}},
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: true}, {Issues: []string{
{Name: "file2.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: true, Source: report.DetailedReportModuleSelected}, {Issues: []string{
"Missing Supporting Files - 1 File",
}}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false}, {IsSelected: false}}},
{Name: "file3.dll", Instances: []report.ModuleInstance{{IsDependency: false, Source: report.DetailedReportModuleSelected}, {IsSelected: false, Source: report.DetailedReportModuleSelected}}},
},
Issues: []report.Issue{},
}
Expand Down
32 changes: 28 additions & 4 deletions checks/module_count_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ func generateModule(name string) report.Module {
IsIgnored: false,
IsThirdParty: false,
Instances: []report.ModuleInstance{
{IsDependency: false},
{IsSelected: true},
{Id: 1},
}}
}

Expand All @@ -41,7 +40,7 @@ func TestModuleCount(t *testing.T) {

var lotsOfModules []report.Module

for i := 0; i < utils.MaximumModuleSelectedCountThreshold+1; i++ {
for i := 0; i < utils.MaximumModuleCountThreshold+1; i++ {
moduleName := fmt.Sprintf("module%d", i)
lotsOfModules = append(lotsOfModules, generateModule(moduleName))
}
Expand All @@ -56,7 +55,32 @@ func TestModuleCount(t *testing.T) {
t.FailNow()
}

assert.Contains(t, mockReport.Issues[0].Description, fmt.Sprintf("%d modules were selected", utils.MaximumModuleSelectedCountThreshold+1))
assert.Contains(t, mockReport.Issues[0].Description, fmt.Sprintf("%d modules were identified from the upload", utils.MaximumModuleCountThreshold+1))
})

t.Run("Large Number of Selected modules", func(t *testing.T) {
t.Parallel()

var lotsOfModules []report.Module

for i := 0; i < utils.MaximumModuleSelectedCountThreshold+1; i++ {
moduleName := fmt.Sprintf("module%d", i)
module := generateModule(moduleName)
module.Instances[0].IsSelected = true
module.Instances[0].Source = report.DetailedReportModuleSelected
lotsOfModules = append(lotsOfModules, module)
}

mockReport := report.Report{
Modules: lotsOfModules,
}

moduleCount(&mockReport)

if !assert.Equal(t, 1, len(mockReport.Issues)) {
t.FailNow()
}

assert.Contains(t, mockReport.Issues[0].Description, fmt.Sprintf("%d modules were selected", utils.MaximumModuleSelectedCountThreshold+1))
})
}
10 changes: 5 additions & 5 deletions checks/overscanning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ func TestOverScanning(t *testing.T) {
Modules: []report.Module{
{
Name: "common-lib.dll", Instances: []report.ModuleInstance{
{IsSelected: true},
{IsSelected: true, Source: report.DetailedReportModuleSelected},
},
DependencyOf: []string{"app.dll"},
},
{
Name: "app.dll", Instances: []report.ModuleInstance{
{IsSelected: true},
{IsSelected: true, Source: report.DetailedReportModuleSelected},
},
},
},
Expand All @@ -47,19 +47,19 @@ func TestOverScanning(t *testing.T) {
Modules: []report.Module{
{
Name: "common-lib.dll", Instances: []report.ModuleInstance{
{IsSelected: true},
{IsSelected: true, Source: report.DetailedReportModuleSelected},
},
DependencyOf: []string{"app.dll"},
},
{
Name: "common-models.dll", Instances: []report.ModuleInstance{
{IsSelected: true},
{IsSelected: true, Source: report.DetailedReportModuleSelected},
},
DependencyOf: []string{"app.dll"},
},
{
Name: "app.dll", Instances: []report.ModuleInstance{
{IsSelected: true},
{IsSelected: true, Source: report.DetailedReportModuleSelected},
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions checks/previous_scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func TestPreviousScan(t *testing.T) {
BuildId: 1,
},
Modules: []report.Module{
{Name: "file3.jar", Instances: []report.ModuleInstance{{IsDependency: false, IsSelected: true}}},
{Name: "file4.jar", Instances: []report.ModuleInstance{{IsDependency: false, IsSelected: false}}},
{Name: "file3.jar", Instances: []report.ModuleInstance{{IsDependency: false, IsSelected: true, Source: report.DetailedReportModuleSelected}}},
{Name: "file4.jar", Instances: []report.ModuleInstance{{IsDependency: false, IsSelected: false, Source: report.DetailedReportModuleSelected}}},
},
UploadedFiles: []report.UploadedFile{
{Id: 333333, Name: "file3.jar", MD5: "hash2", IsIgnored: false, IsThirdParty: false},
Expand Down Expand Up @@ -132,8 +132,8 @@ func TestPreviousScan(t *testing.T) {
BuildId: 1,
},
Modules: []report.Module{
{Name: "file3.jar", Instances: []report.ModuleInstance{{IsDependency: false, IsSelected: true}}},
{Name: "file4.jar", Instances: []report.ModuleInstance{{IsDependency: false, IsSelected: false}}},
{Name: "file3.jar", Instances: []report.ModuleInstance{{IsDependency: false, IsSelected: true, Source: report.DetailedReportModuleSelected}}},
{Name: "file4.jar", Instances: []report.ModuleInstance{{IsDependency: false, IsSelected: false, Source: report.DetailedReportModuleSelected}}},
},
UploadedFiles: []report.UploadedFile{
{Id: 333333, Name: "file3.jar", MD5: "hash2", IsIgnored: false, IsThirdParty: false},
Expand Down
10 changes: 8 additions & 2 deletions checks/testing_artefacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,18 @@ func TestTestingArtefacts(t *testing.T) {
{Name: "moq.dll",
Instances: []report.ModuleInstance{
{IsDependency: false},
{IsSelected: true},
{
IsSelected: true,
Source: report.DetailedReportModuleSelected,
},
}},
{Name: "standalone.unittests.dll",
Instances: []report.ModuleInstance{
{IsDependency: false},
{IsSelected: true},
{
IsSelected: true,
Source: report.DetailedReportModuleSelected,
},
}},
},
UploadedFiles: []report.UploadedFile{
Expand Down
2 changes: 1 addition & 1 deletion data/detailed_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func populateDetailedReportModules(r *report.Report, staticAnalysis detailedRepo
Architecture: html.UnescapeString(module.Architecture),
IsSelected: true,
WasScanned: true,
Source: "detailed_report_module_selected",
Source: report.DetailedReportModuleSelected,
})
}
}
Expand Down
12 changes: 9 additions & 3 deletions report/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ func (r *Report) GetSelectedModules() []Module {
var selectedModules []Module

for _, module := range r.Modules {
found := false

for _, instance := range module.Instances {
if !module.IsInListByName(selectedModules) && instance.IsSelected {
selectedModules = append(selectedModules, module)
if instance.Source == DetailedReportModuleSelected {
found = true
}
}

if found {
selectedModules = append(selectedModules, module)
}
}

return selectedModules
Expand All @@ -23,7 +29,7 @@ func (r *Report) GetPrescanModules() []Module {

for _, module := range r.Modules {
for _, instance := range module.Instances {
if !module.IsInListByName(prescanModules) && instance.Source == "prescan_module_list" {
if !module.IsInListByName(prescanModules) && instance.Source == PrescanModuleList {
prescanModules = append(prescanModules, module)
}
}
Expand Down
37 changes: 22 additions & 15 deletions report/report_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,29 @@ type Module struct {
DependencyOf []string `json:"dependency_of,omitempty"`
}

type ModuleInstanceSource string

const (
DetailedReportModuleSelected ModuleInstanceSource = "detailed_report_module_selected"
PrescanModuleList ModuleInstanceSource = "prescan_module_list"
)

type ModuleInstance struct {
Id int `json:"id,omitempty"`
Compiler string `json:"compiler,omitempty"`
OperatingSystem string `json:"operating_system,omitempty"`
Architecture string `json:"architecture,omitempty"`
IsDependency bool `json:"is_dependency"`
IsSelected bool `json:"is_selected"`
WasScanned bool `json:"was_scanned"`
HasFatalErrors bool `json:"has_fatal_errors"`
Status string `json:"status,omitempty"`
Platform string `json:"platform,omitempty"`
Size string `json:"size,omitempty"`
MD5 string `json:"md5,omitempty"`
Issues []string `json:"issues,omitempty"`
SizeBytes int `json:"size_bytes,omitempty"`
Source string `json:"source,omitempty"`
Id int `json:"id,omitempty"`
Compiler string `json:"compiler,omitempty"`
OperatingSystem string `json:"operating_system,omitempty"`
Architecture string `json:"architecture,omitempty"`
IsDependency bool `json:"is_dependency"`
IsSelected bool `json:"is_selected"`
WasScanned bool `json:"was_scanned"`
HasFatalErrors bool `json:"has_fatal_errors"`
Status string `json:"status,omitempty"`
Platform string `json:"platform,omitempty"`
Size string `json:"size,omitempty"`
MD5 string `json:"md5,omitempty"`
Issues []string `json:"issues,omitempty"`
SizeBytes int `json:"size_bytes,omitempty"`
Source ModuleInstanceSource `json:"source,omitempty"`
}

func (m *Module) IsSelected() bool {
Expand Down

0 comments on commit 1f818f3

Please sign in to comment.