-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/antfie/scan_health
- Loading branch information
Showing
6 changed files
with
485 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package checks | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/antfie/scan_health/v2/report" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMinifiedJavaScript(t *testing.T) { | ||
|
||
t.Run("No Issues", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "Test", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
}}, | ||
}, | ||
UploadedFiles: []report.UploadedFile{ | ||
{Id: 111111, Name: "file1.js", MD5: "hash1", IsIgnored: false, IsThirdParty: false}, | ||
{Id: 222222, Name: "file2.js", MD5: "hash2", IsIgnored: false, IsThirdParty: false}, | ||
}, | ||
} | ||
|
||
minifiedJavaScript(&mockReport) | ||
|
||
assert.Equal(t, len(mockReport.Issues), 0) | ||
}) | ||
|
||
t.Run("No JS Minified Issues", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "Test", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
{Issues: []string{"No PDB files found"}}, | ||
}}, | ||
}, | ||
} | ||
|
||
minifiedJavaScript(&mockReport) | ||
|
||
assert.Equal(t, len(mockReport.Issues), 0) | ||
}) | ||
|
||
t.Run("Testing for JS Minified Warning", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "JS files within Test", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
{Issues: []string{"because we think it is minified"}}, | ||
}}, | ||
{Name: "JS files within Test2", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
{Issues: []string{"because we think it is minified"}}, | ||
}}, | ||
}, | ||
} | ||
|
||
minifiedJavaScript(&mockReport) | ||
|
||
if !assert.Equal(t, len(mockReport.Issues), 1) { | ||
t.FailNow() | ||
} | ||
|
||
assert.Contains(t, mockReport.Issues[0].Description, "2 minified") | ||
assert.Equal(t, mockReport.Issues[0].Severity, report.IssueSeverityMedium) | ||
assert.Equal(t, len(mockReport.Recommendations), 2) | ||
}) | ||
|
||
t.Run("Testing for /dist/ JS Files", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "JS files within Test", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
{Issues: []string{"Random issue in /dist/blah.js"}}, | ||
}}, | ||
}, | ||
} | ||
|
||
minifiedJavaScript(&mockReport) | ||
|
||
assert.Equal(t, len(mockReport.Issues), 1) | ||
assert.Equal(t, mockReport.Issues[0].Severity, report.IssueSeverityMedium) | ||
assert.Equal(t, len(mockReport.Recommendations), 2) | ||
}) | ||
|
||
t.Run("Testing for minification by name", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
UploadedFiles: []report.UploadedFile{ | ||
{Id: 111111, Name: "file1.min.js", MD5: "hash1", IsIgnored: false, IsThirdParty: false}, | ||
{Id: 222222, Name: "file2.js", MD5: "hash2", IsIgnored: false, IsThirdParty: false}, | ||
{Id: 222222, Name: "file3.min.js", MD5: "hash3", IsIgnored: false, IsThirdParty: false}, | ||
}, | ||
} | ||
|
||
minifiedJavaScript(&mockReport) | ||
if !assert.Equal(t, len(mockReport.Issues), 1) { | ||
t.FailNow() | ||
} | ||
|
||
assert.Contains(t, mockReport.Issues[0].Description, "2 minified") | ||
assert.Equal(t, mockReport.Issues[0].Severity, report.IssueSeverityMedium) | ||
|
||
assert.Equal(t, len(mockReport.Recommendations), 2) | ||
}) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package checks | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/antfie/scan_health/v2/report" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMissingDebugSymbols(t *testing.T) { | ||
|
||
t.Run("No Executables/DLLs", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "file3.jar", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
}}, | ||
}, | ||
UploadedFiles: []report.UploadedFile{ | ||
{Id: 333333, Name: "file3.jar", MD5: "hash2", IsIgnored: false, IsThirdParty: false}, | ||
}, | ||
} | ||
|
||
missingDebugSymbols(&mockReport) | ||
|
||
assert.Equal(t, len(mockReport.Issues), 0) | ||
}) | ||
|
||
t.Run("Executables/DLLs but no issues", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "file3.dll", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
}}, | ||
{Name: "file4.exe", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
}}, | ||
}, | ||
UploadedFiles: []report.UploadedFile{ | ||
{Id: 111111, Name: "file3.dll", MD5: "hash1", IsIgnored: false, IsThirdParty: false}, | ||
{Id: 222222, Name: "file4.exe", MD5: "hash2", IsIgnored: false, IsThirdParty: false}, | ||
}, | ||
} | ||
|
||
missingDebugSymbols(&mockReport) | ||
|
||
assert.Equal(t, len(mockReport.Issues), 0) | ||
}) | ||
|
||
t.Run("Java with missing debug", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "file3.jar", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
{Issues: []string{"No supporting files or PDB files"}}, | ||
}}, | ||
{Name: "file4.war", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
{Issues: []string{"No supporting files or PDB files"}}, | ||
}}, | ||
}, | ||
UploadedFiles: []report.UploadedFile{ | ||
{Id: 111111, Name: "file3.exe", MD5: "hash1", IsIgnored: false, IsThirdParty: false}, | ||
{Id: 222222, Name: "file4.dll", MD5: "hash2", IsIgnored: false, IsThirdParty: false}, | ||
{Id: 111111, Name: "file3.jar", MD5: "hash1", IsIgnored: false, IsThirdParty: false}, | ||
{Id: 222222, Name: "file4.war", MD5: "hash2", IsIgnored: false, IsThirdParty: false}, | ||
}, | ||
Issues: []report.Issue{}, | ||
} | ||
|
||
missingDebugSymbols(&mockReport) | ||
|
||
assert.Equal(t, len(mockReport.Issues), 0) | ||
assert.Equal(t, len(mockReport.Recommendations), 0) | ||
}) | ||
|
||
t.Run("Executables + DLLs with missing debug", func(t *testing.T) { | ||
t.Parallel() | ||
mockReport := report.Report{ | ||
Modules: []report.Module{ | ||
{Name: "file3.exe", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
{Issues: []string{"No supporting files or PDB files"}}, | ||
}}, | ||
{Name: "file4.dll", | ||
Instances: []report.ModuleInstance{ | ||
{IsDependency: false}, | ||
{Issues: []string{"No supporting files or PDB files"}}, | ||
}}, | ||
}, | ||
UploadedFiles: []report.UploadedFile{ | ||
{Id: 111111, Name: "file3.exe", MD5: "hash1", IsIgnored: false, IsThirdParty: false}, | ||
{Id: 222222, Name: "file4.dll", MD5: "hash2", IsIgnored: false, IsThirdParty: false}, | ||
}, | ||
} | ||
|
||
missingDebugSymbols(&mockReport) | ||
|
||
if !assert.Equal(t, len(mockReport.Issues), 1) { | ||
assert.Contains(t, mockReport.Issues[0].Description, "2 modules") | ||
} | ||
|
||
assert.Equal(t, len(mockReport.Recommendations), 1) | ||
}) | ||
} |
Oops, something went wrong.