validations

package
v1.13.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestMsi       = "27e175b8-e525-11ee-842b-7aa2c69b8f1f"
	TestScaScanId = "3d90ec4b-cf33-4846-6831-4bf9576f2235"

	// TestMoreInfoUrl       = "https://www.jfrog.com"
	TestPlatformUrl = "https://test-platform-url.jfrog.io/"
	TestMoreInfoUrl = "https://test-more-info-url.jfrog.io/"

	TestConfigProfileName = "default-profile"
)
View Source
const (
	SastToolName = "🐸 JFrog SAST"
	IacToolName  = "JFrog Terraform scanner"
	// #nosec G101 -- Not credentials.
	SecretsToolName = "JFrog Secrets scanner"
)
View Source
const (
	ErrCountFormat = "Expected%s %d %s in %s, but got %d %s."
)

Variables

This section is empty.

Functions

func CreateRestsMockServer

func CreateRestsMockServer(testHandler restsTestHandler) *httptest.Server

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 GetValidationCountErrMsg

func GetValidationCountErrMsg(what, where string, exactMatch bool, expectedCount, actualCount int) string

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 ValidatePointersAndNotNil

func ValidatePointersAndNotNil[T any](t *testing.T, exactMatch bool, pair PointerValidation[T]) bool

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 ValidateSarifReport(t *testing.T, exactMatch bool, expected, actual *sarif.Report)

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 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 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)

func XscServer

func XscServer(t *testing.T, params MockServerParams) (*httptest.Server, *config.ServerDetails)

Types

type CountValidation

type CountValidation[T any] struct {
	Expected int
	Actual   int
	Msg      string
}

CountValidation validates the content of the given numbers. Not ExactMatch: The actual content must be greater or equal to the expected content.

func (CountValidation[T]) ErrMsgs

func (cv CountValidation[T]) ErrMsgs(_ *testing.T) []string

func (CountValidation[T]) Validate

func (cv CountValidation[T]) Validate(t *testing.T, exactMatch bool) bool

type ListValidation

type ListValidation[T any] struct {
	Expected []T
	Actual   []T
	Msg      string
}

ListValidation validates the content of the given lists. Not ExactMatch: The expected content must be subset of the actual content.

func (ListValidation[T]) ErrMsgs

func (lvp ListValidation[T]) ErrMsgs(t *testing.T) []string

func (ListValidation[T]) Validate

func (lvp ListValidation[T]) Validate(t *testing.T, exactMatch bool) bool

type MockServerParams added in v1.13.2

type MockServerParams struct {
	XrayVersion  string
	XscVersion   string
	XscNotExists bool
	ReturnMsi    string
}

type NumberValidation

type NumberValidation[T any] struct {
	Expected T
	Actual   T
	Msg      string
}

NumberValidation validates the content of the given numbers. Not ExactMatch: The actual content must not be zero if the expected content is not zero.

func (NumberValidation[T]) ErrMsgs

func (nvp NumberValidation[T]) ErrMsgs(_ *testing.T) []string

func (NumberValidation[T]) Validate

func (nvp NumberValidation[T]) Validate(t *testing.T, exactMatch bool) bool

type PointerValidation

type PointerValidation[T any] struct {
	Expected *T
	Actual   *T
	Msg      string
}

PointerValidation validates the content of the given pointers. Not ExactMatch: The actual content must not be nil if the expected content is not nil.

func (PointerValidation[T]) ErrMsgs

func (pvp PointerValidation[T]) ErrMsgs(t *testing.T) []string

func (PointerValidation[T]) Validate

func (pvp PointerValidation[T]) Validate(t *testing.T, exactMatch bool) bool

type StringValidation

type StringValidation struct {
	Expected string
	Actual   string
	Msg      string
}

Validate a string content. Not ExactMatch: The actual content must not be empty if the expected content is not empty.

func (StringValidation) ErrMsgs

func (sv StringValidation) ErrMsgs(_ *testing.T) []string

func (StringValidation) Validate

func (sv StringValidation) Validate(t *testing.T, exactMatch bool) bool

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
	// Expected issues for each type to check if the content has the correct amount of issues.
	Vulnerabilities       int
	Licenses              int
	SecurityViolations    int
	LicenseViolations     int
	OperationalViolations int
	Applicable            int
	Undetermined          int
	NotCovered            int
	NotApplicable         int
	MissingContext        int
	Inactive              int
	Sast                  int
	Iac                   int
	Secrets               int
}

ValidationParams holds validation/assertion parameters for tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL