Documentation ¶
Index ¶
- Constants
- Variables
- func CreateDummyApplicabilityRule(cve string, applicableStatus jasutils.ApplicabilityStatus) *sarif.ReportingDescriptor
- func CreateDummyApplicableResults(cve string, location formats.Location) *sarif.Result
- func CreateDummyJasResult(id string, level severityutils.SarifSeverityLevel, location formats.Location, ...) *sarif.Result
- func CreateDummyJasRule(id string, cwe ...string) *sarif.ReportingDescriptor
- func CreateDummySastViolationResult(id string, level severityutils.SarifSeverityLevel, watch, issueId string, ...) *sarif.Result
- func CreateDummySecretResult(id string, status jasutils.TokenValidationStatus, metadata string, ...) *sarif.Result
- func CreateDummySecretViolationResult(id string, status jasutils.TokenValidationStatus, ...) *sarif.Result
- func CreateRestsMockServer(testHandler restsTestHandler) *httptest.Server
- func CreateXrayRestsMockServer(testHandler restsTestHandler) (*httptest.Server, *config.ServerDetails)
- func CreateXscRestsMockServer(t *testing.T, testHandler restsTestHandler) (*httptest.Server, *config.ServerDetails, ...)
- func GetValidationCountErrMsg(what, where string, exactMatch bool, expectedCount, actualCount int) string
- func NewMockJasRuns(runs ...*sarif.Run) []results.ScanResult[[]*sarif.Run]
- func NewMockScaResults(responses ...services.ScanResponse) (converted []results.ScanResult[services.ScanResponse])
- func ValidateApplicabilityStatusCount(t *testing.T, outputType string, violation, exactMatch bool, ...)
- func ValidateCommandJsonOutput(t *testing.T, params ValidationParams)
- func ValidateCommandSarifOutput(t *testing.T, params ValidationParams)
- func ValidateCommandSimpleJsonOutput(t *testing.T, params ValidationParams)
- func ValidateCommandSummaryOutput(t *testing.T, params ValidationParams)
- func ValidateContent(t *testing.T, exactMatch bool, validations ...Validation) bool
- func ValidateCount(t *testing.T, outputType string, params ValidationParams, ...)
- func ValidatePointersAndNotNil[T any](t *testing.T, exactMatch bool, pair PointerValidation[T]) bool
- func ValidateSarifIssuesCount(t *testing.T, params ValidationParams, report *sarif.Report)
- func ValidateSarifReport(t *testing.T, exactMatch bool, expected, actual *sarif.Report)
- func ValidateScaViolationCount(t *testing.T, outputType string, exactMatch bool, params *ScaViolationCount, ...)
- func ValidateScanResponseIssuesCount(t *testing.T, params ValidationParams, content ...services.ScanResponse)
- func ValidateScanResponses(t *testing.T, exactMatch bool, expected, actual []services.ScanResponse)
- func ValidateScanTypeCount(t *testing.T, outputType string, violation, exactMatch bool, params *ScanCount, ...)
- func ValidateSimpleJsonIssuesCount(t *testing.T, params ValidationParams, results formats.SimpleJsonResults)
- func ValidateSimpleJsonResults(t *testing.T, exactMatch bool, expected, actual formats.SimpleJsonResults)
- func ValidateSummaryIssuesCount(t *testing.T, params ValidationParams, results formats.ResultsSummary)
- func ValidateTotalCount(t *testing.T, outputType string, exactMatch bool, params *TotalCount, ...)
- func ValidateViolationCount(t *testing.T, outputType string, exactMatch bool, params *ViolationCount, ...)
- func ValidateVulnerabilitiesCount(t *testing.T, outputType string, exactMatch bool, params *VulnerabilityCount, ...)
- func VerifyJsonResults(t *testing.T, content string, params ValidationParams)
- func VerifySimpleJsonResults(t *testing.T, content string, params ValidationParams)
- func XrayServer(t *testing.T, params MockServerParams) (*httptest.Server, *config.ServerDetails)
- func XscServer(t *testing.T, params MockServerParams) (*httptest.Server, *config.ServerDetails)
- type ApplicabilityStatusCount
- type CountValidation
- type ListValidation
- type MockServerParams
- type NumberValidation
- type PointerValidation
- type ScaViolationCount
- type ScanCount
- type StringValidation
- type TotalCount
- type Validation
- type ValidationParams
- type ViolationCount
- type VulnerabilityCount
Constants ¶
const ( TestMsi = "27e175b8-e525-11ee-842b-7aa2c69b8f1f" TestScaScanId = "3d90ec4b-cf33-4846-6831-4bf9576f2235" TestPlatformUrl = "https://test-platform-url.jfrog.io/" TestMoreInfoUrl = "https://test-more-info-url.jfrog.io/" TestConfigProfileName = "default-profile" )
const ( SastToolName = "🐸 JFrog SAST" IacToolName = "JFrog Terraform scanner" // #nosec G101 -- Not credentials. SecretsToolName = "JFrog Secrets scanner" ContextualAnalysisToolName = "JFrog Applicability Scanner" )
const (
ErrCountFormat = "Expected%s %d %s in %s, but got %d %s."
)
Variables ¶
var (
TestMockGitInfo = xscservices.XscGitInfoContext{
GitRepoHttpsCloneUrl: "https://github.com/jfrog/dummy-repo.git",
GitProvider: "github",
GitRepoName: "dummy-repo",
GitProject: "jfrog",
BranchName: "dev",
LastCommitHash: "4be861f9a585d8ae5dde0b9550669972ee05c9d7",
}
)
Functions ¶
func CreateDummyApplicabilityRule ¶ added in v1.14.0
func CreateDummyApplicabilityRule(cve string, applicableStatus jasutils.ApplicabilityStatus) *sarif.ReportingDescriptor
func CreateDummyApplicableResults ¶ added in v1.14.0
func CreateDummyJasResult ¶ added in v1.14.0
func CreateDummyJasResult(id string, level severityutils.SarifSeverityLevel, location formats.Location, codeFlows ...[]formats.Location) *sarif.Result
func CreateDummyJasRule ¶ added in v1.14.0
func CreateDummyJasRule(id string, cwe ...string) *sarif.ReportingDescriptor
func CreateDummySastViolationResult ¶ added in v1.14.0
func CreateDummySecretResult ¶ added in v1.14.0
func CreateDummySecretViolationResult ¶ added in v1.14.0
func CreateRestsMockServer ¶
Create mock server to test REST APIs. testHandler - The HTTP handler of the test
func CreateXrayRestsMockServer ¶
func CreateXrayRestsMockServer(testHandler restsTestHandler) (*httptest.Server, *config.ServerDetails)
func CreateXscRestsMockServer ¶
func CreateXscRestsMockServer(t *testing.T, testHandler restsTestHandler) (*httptest.Server, *config.ServerDetails, artifactory.ArtifactoryServicesManager)
func NewMockJasRuns ¶ added in v1.14.0
func NewMockScaResults ¶ added in v1.14.0
func NewMockScaResults(responses ...services.ScanResponse) (converted []results.ScanResult[services.ScanResponse])
func ValidateApplicabilityStatusCount ¶ added in v1.14.0
func ValidateCommandJsonOutput ¶
func ValidateCommandJsonOutput(t *testing.T, params ValidationParams)
Validation on SCA content only (No JAS in this content) Actual (and optional Expected) content should be a slice of services.ScanResponse in the validation params
func ValidateCommandSarifOutput ¶
func ValidateCommandSarifOutput(t *testing.T, params ValidationParams)
Validate sarif report according to the expected values and issue counts in the validation params. Value/Actual content should be a *sarif.Report in the validation params If ExactResultsMatch is true, the validation will check exact values and not only the 'equal or grater' counts / existence of expected attributes. For Integration tests with JFrog API, ExactResultsMatch should be set to false.
func ValidateCommandSimpleJsonOutput ¶
func ValidateCommandSimpleJsonOutput(t *testing.T, params ValidationParams)
Validate simple-json report results according to the expected values and issue counts in the validation params. Actual/Expected content should be a formats.SimpleJsonResults in the validation params. If Expected is provided, the validation will check if the Actual content matches the expected results. If ExactResultsMatch is true, the validation will check exact values and not only the 'equal or grater' counts / existence of expected attributes. (For Integration tests with JFrog API, ExactResultsMatch should be set to false)
func ValidateCommandSummaryOutput ¶
func ValidateCommandSummaryOutput(t *testing.T, params ValidationParams)
Validate summary results according to the expected values and issue counts in the validation params. Content/Expected should be a formats.ResultsSummary in the validation params. If Expected is provided, the validation will check if the Actual content matches the expected results. If ExactResultsMatch is true, the validation will check exact values and not only the 'equal or grater' counts / existence of expected attributes. (For Integration tests with JFrog API, ExactResultsMatch should be set to false)
func ValidateContent ¶
func ValidateContent(t *testing.T, exactMatch bool, validations ...Validation) bool
ValidateContent validates the content of the given Validations. If exactMatch is true, the content must match exactly. If at least one validation fails, the function returns false and stops validating the rest of the pairs.
func ValidateCount ¶ added in v1.14.0
func ValidateCount(t *testing.T, outputType string, params ValidationParams, actual validationCountActualValues)
func ValidateSarifIssuesCount ¶
func ValidateSarifIssuesCount(t *testing.T, params ValidationParams, report *sarif.Report)
Validate sarif report according to the expected counts in the validation params. Actual content should be a *sarif.Report in the validation params. If Expected is provided, the validation will check if the Actual content matches the expected results. If ExactResultsMatch is true, the validation will check exact values and not only the 'equal or grater' counts / existence of expected attributes. (For Integration tests with JFrog API, ExactResultsMatch should be set to false)
func ValidateSarifReport ¶
func ValidateScaViolationCount ¶ added in v1.14.0
func ValidateScanResponseIssuesCount ¶
func ValidateScanResponseIssuesCount(t *testing.T, params ValidationParams, content ...services.ScanResponse)
func ValidateScanResponses ¶
func ValidateScanResponses(t *testing.T, exactMatch bool, expected, actual []services.ScanResponse)
func ValidateScanTypeCount ¶ added in v1.14.0
func ValidateSimpleJsonIssuesCount ¶
func ValidateSimpleJsonIssuesCount(t *testing.T, params ValidationParams, results formats.SimpleJsonResults)
Validate simple-json report results according to the expected counts in the validation params. Actual content should be a formats.SimpleJsonResults in the validation params. If Expected is provided, the validation will check if the Actual content matches the expected results. If ExactResultsMatch is true, the validation will check exact values and not only the 'equal or grater' counts / existence of expected attributes. (For Integration tests with JFrog API, ExactResultsMatch should be set to false)
func ValidateSimpleJsonResults ¶
func ValidateSimpleJsonResults(t *testing.T, exactMatch bool, expected, actual formats.SimpleJsonResults)
func ValidateSummaryIssuesCount ¶
func ValidateSummaryIssuesCount(t *testing.T, params ValidationParams, results formats.ResultsSummary)
func ValidateTotalCount ¶ added in v1.14.0
func ValidateViolationCount ¶ added in v1.14.0
func ValidateViolationCount(t *testing.T, outputType string, exactMatch bool, params *ViolationCount, actual validationCountActualValues)
func ValidateVulnerabilitiesCount ¶ added in v1.14.0
func ValidateVulnerabilitiesCount(t *testing.T, outputType string, exactMatch bool, params *VulnerabilityCount, actual validationCountActualValues)
func VerifyJsonResults ¶
func VerifyJsonResults(t *testing.T, content string, params ValidationParams)
Validate SCA content only (No JAS in this content) according to the expected values and issue counts in the validation params. Content/Expected should be a []services.ScanResponse in the validation params. If Expected is provided, the validation will check if the Actual content matches the expected results. If ExactResultsMatch is true, the validation will check exact values and not only the 'equal or grater' counts / existence of expected attributes. (For Integration tests with JFrog API, ExactResultsMatch should be set to false)
func VerifySimpleJsonResults ¶
func VerifySimpleJsonResults(t *testing.T, content string, params ValidationParams)
Validate simple-json report results according to the expected values and issue counts in the validation params. Content/Expected should be a formats.SimpleJsonResults in the validation params. If Expected is provided, the validation will check if the Actual content matches the expected results. If ExactResultsMatch is true, the validation will check exact values and not only the 'equal or grater' counts / existence of expected attributes. (For Integration tests with JFrog API, ExactResultsMatch should be set to false)
func XrayServer ¶
func XrayServer(t *testing.T, params MockServerParams) (*httptest.Server, *config.ServerDetails)
Mock Xray server (with Xsc inner service if supported based on version - not backward compatible to XSC API)
func XscServer ¶
func XscServer(t *testing.T, params MockServerParams) (*httptest.Server, *config.ServerDetails)
Mock Only Xsc server API (backward compatible)
Types ¶
type ApplicabilityStatusCount ¶ added in v1.14.0
type ApplicabilityStatusCount struct { // Expected number of 'Applicable' contextual-analysis statuses for the issues (sca) Applicable int // Expected number of 'Undetermined' contextual-analysis statuses for the issues (sca) Undetermined int // Expected number of 'NotCovered' contextual-analysis statuses for the issues (sca) NotCovered int // Expected number of 'NotApplicable' contextual-analysis statuses for the issues (sca) NotApplicable int // Expected number of 'MissingContext' contextual-analysis statuses for the issues (sca) MissingContext int // Expected number of 'Inactive' contextual-analysis statuses for the issues (secrets) Inactive int }
type CountValidation ¶
CountValidation validates the content of the given numbers. Not ExactMatch: The actual content must be greater or equal to the expected content.
type ListValidation ¶
ListValidation validates the content of the given lists. Not ExactMatch: The expected content must be subset of the actual content.
type MockServerParams ¶ added in v1.13.2
type MockServerParams struct { // General params to mock Xray and Xsc (backward compatible and inner service based on the following params) XrayVersion string XscVersion string XscNotExists bool // Xsc/Event Api ReturnMsi string // Xsc/Watch/Resource Api ReturnMockPlatformWatches xrayutils.ResourcesWatchesBody }
type NumberValidation ¶
NumberValidation validates the content of the given numbers. Not ExactMatch: The actual content must not be zero if the expected content is not zero.
type PointerValidation ¶
PointerValidation validates the content of the given pointers. Not ExactMatch: The actual content must not be nil if the expected content is not nil.
type ScaViolationCount ¶ added in v1.14.0
type StringValidation ¶
Validate a string content. Not ExactMatch: The actual content must not be empty if the expected content is not empty.
type TotalCount ¶ added in v1.14.0
type Validation ¶
type Validation interface { Validate(t *testing.T, exactMatch bool) bool ErrMsgs(t *testing.T) []string }
Validation allows to validate/assert a content with expected values. Using the Validation interfaces implementations allows you to assert content for exact value or not exact match (changes base on the implementation).
type ValidationParams ¶
type ValidationParams struct { // The actual content to verify. Actual interface{} // If provided, the test will check if the content matches the expected results. Expected interface{} // If provided, the test will check exact values and not only the minimum values / existence. ExactResultsMatch bool // Validate total number of licenses, vulnerabilities and violations Total *TotalCount // Validate number of vulnerabilities in different contexts Vulnerabilities *VulnerabilityCount // Validate number of violations in different contexts Violations *ViolationCount }
ValidationParams holds validation/assertion parameters for tests.
type ViolationCount ¶ added in v1.14.0
type ViolationCount struct { // Expected number of violations by scan type (SCA/JAS) ValidateScan *ScanCount // Expected number of contextual statuses for violations (sca/secrets) ValidateApplicabilityStatus *ApplicabilityStatusCount // Expected number of violations by violation type (license, operational, security: SCA+JAS) ValidateType *ScaViolationCount }
type VulnerabilityCount ¶ added in v1.14.0
type VulnerabilityCount struct { // If exists, validate the total amount of issues in different scan types (SCA/SAST/SECRETS/IAC) ValidateScan *ScanCount // If exists, validate the total amount of contextual statuses for the issues (sca/secrets) ValidateApplicabilityStatus *ApplicabilityStatusCount }