types

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package types provides common type definitions for the OWASP testing framework

Package types provides common type definitions for the OWASP testing framework

Package types provides common type definitions for the OWASP testing framework

Index

Constants

View Source
const (
	JSONFormat     string = "json"
	JSONLFormat    string = "jsonl"
	CSVFormat      string = "csv"
	ExcelFormat    string = "excel"
	HTMLFormat     string = "html"
	PDFFormat      string = "pdf"
	MarkdownFormat string = "markdown"
	TextFormat     string = "text"
)

Report formats as string constants

Variables

This section is empty.

Functions

func GetAllRegisteredTestCases

func GetAllRegisteredTestCases() map[VulnerabilityType][]*TestCase

GetAllRegisteredTestCases returns all registered test cases

func RegisterTestCase

func RegisterTestCase(vulnerabilityType VulnerabilityType, testCase *TestCase)

RegisterTestCase registers a test case with the global registry

func SetDefaultTestFactory

func SetDefaultTestFactory(factory TestFactory)

SetDefaultTestFactory sets the default test factory

Types

type DefaultTestCaseBuilder

type DefaultTestCaseBuilder struct {
	// contains filtered or unexported fields
}

DefaultTestCaseBuilder is the default implementation of the TestCaseBuilder interface

func (*DefaultTestCaseBuilder) Build

func (b *DefaultTestCaseBuilder) Build() (*TestCase, error)

Build builds the test case

func (*DefaultTestCaseBuilder) NewTestCase

func (b *DefaultTestCaseBuilder) NewTestCase() (interface{}, error)

NewTestCase initializes a new test case

func (*DefaultTestCaseBuilder) WithDescription

func (b *DefaultTestCaseBuilder) WithDescription(description string) TestCaseBuilder

WithDescription sets the description of the test case

func (*DefaultTestCaseBuilder) WithDetectionCriteria

func (b *DefaultTestCaseBuilder) WithDetectionCriteria(criteria interface{}) TestCaseBuilder

WithDetectionCriteria sets the detection criteria of the test case

func (*DefaultTestCaseBuilder) WithExpectedBehavior

func (b *DefaultTestCaseBuilder) WithExpectedBehavior(expectedBehavior string) TestCaseBuilder

WithExpectedBehavior sets the expected behavior of the test case

func (*DefaultTestCaseBuilder) WithID

WithID sets the ID of the test case

func (*DefaultTestCaseBuilder) WithMetadata

func (b *DefaultTestCaseBuilder) WithMetadata(metadata map[string]interface{}) TestCaseBuilder

WithMetadata sets the metadata of the test case

func (*DefaultTestCaseBuilder) WithName

func (b *DefaultTestCaseBuilder) WithName(name string) TestCaseBuilder

WithName sets the name of the test case

func (*DefaultTestCaseBuilder) WithOWASPMapping

func (b *DefaultTestCaseBuilder) WithOWASPMapping(mapping string) TestCaseBuilder

WithOWASPMapping sets the OWASP mapping of the test case

func (*DefaultTestCaseBuilder) WithPrompt

func (b *DefaultTestCaseBuilder) WithPrompt(prompt string) TestCaseBuilder

WithPrompt sets the prompt of the test case

func (*DefaultTestCaseBuilder) WithSeverity

func (b *DefaultTestCaseBuilder) WithSeverity(severity interface{}) TestCaseBuilder

WithSeverity sets the severity of the test case

func (*DefaultTestCaseBuilder) WithTags

func (b *DefaultTestCaseBuilder) WithTags(tags []string) TestCaseBuilder

WithTags sets the tags of the test case

func (*DefaultTestCaseBuilder) WithVulnerabilityType

func (b *DefaultTestCaseBuilder) WithVulnerabilityType(vulnerabilityType VulnerabilityType) TestCaseBuilder

WithVulnerabilityType sets the vulnerability type of the test case

type DefaultTestSuiteBuilder

type DefaultTestSuiteBuilder struct {
	// contains filtered or unexported fields
}

DefaultTestSuiteBuilder is the default implementation of the TestSuiteBuilder interface

func (*DefaultTestSuiteBuilder) Build

func (b *DefaultTestSuiteBuilder) Build() (*TestSuite, error)

Build builds the test suite

func (*DefaultTestSuiteBuilder) NewTestSuite

func (b *DefaultTestSuiteBuilder) NewTestSuite() (interface{}, error)

NewTestSuite initializes a new test suite

func (*DefaultTestSuiteBuilder) WithDescription

func (b *DefaultTestSuiteBuilder) WithDescription(description string) TestSuiteBuilder

WithDescription sets the description of the test suite

func (*DefaultTestSuiteBuilder) WithID

WithID sets the ID of the test suite

func (*DefaultTestSuiteBuilder) WithMetadata

func (b *DefaultTestSuiteBuilder) WithMetadata(metadata map[string]interface{}) TestSuiteBuilder

WithMetadata sets the metadata of the test suite

func (*DefaultTestSuiteBuilder) WithName

WithName sets the name of the test suite

func (*DefaultTestSuiteBuilder) WithTestCases

func (b *DefaultTestSuiteBuilder) WithTestCases(testCases []*TestCase) TestSuiteBuilder

WithTestCases sets the test cases of the test suite

type Report

type Report struct {
	Title       string                 `json:"title"`
	TestSuites  []*TestSuite           `json:"test_suites"`
	Format      string                 `json:"format"`
	GeneratedAt time.Time              `json:"generated_at"`
	Metadata    map[string]interface{} `json:"metadata"`
}

Report represents a generated report

type ReportGenerator

type ReportGenerator interface {
	GenerateReport(ctx context.Context, testSuites []*TestSuite, options *ReportOptions) (*Report, error)
}

ReportGenerator is an interface for generating reports

type ReportOptions

type ReportOptions struct {
	Format     string                 `json:"format"`
	OutputPath string                 `json:"output_path"`
	Title      string                 `json:"title"`
	Metadata   map[string]interface{} `json:"metadata"`
}

ReportOptions represents options for generating a report

type TestCase

type TestCase struct {
	ID                string                        `json:"id"`
	Name              string                        `json:"name"`
	Description       string                        `json:"description"`
	VulnerabilityType VulnerabilityType             `json:"vulnerability_type"`
	Severity          detection.SeverityLevel       `json:"severity"`
	Prompt            string                        `json:"prompt"`
	ExpectedBehavior  string                        `json:"expected_behavior"`
	DetectionCriteria []detection.DetectionCriteria `json:"detection_criteria"`
	Tags              []string                      `json:"tags"`
	OWASPMapping      string                        `json:"owasp_mapping"`
	Metadata          map[string]interface{}        `json:"metadata"`
}

TestCase represents a test case for OWASP compliance testing

func GetRegisteredTestCases

func GetRegisteredTestCases(vulnerabilityType VulnerabilityType) []*TestCase

GetRegisteredTestCases returns all test cases registered for a specific vulnerability type

type TestCaseBuilder

type TestCaseBuilder interface {
	NewTestCase() (interface{}, error)
	WithID(id string) TestCaseBuilder
	WithName(name string) TestCaseBuilder
	WithDescription(description string) TestCaseBuilder
	WithVulnerabilityType(vulnerabilityType VulnerabilityType) TestCaseBuilder
	WithSeverity(severity interface{}) TestCaseBuilder
	WithPrompt(prompt string) TestCaseBuilder
	WithExpectedBehavior(expectedBehavior string) TestCaseBuilder
	WithDetectionCriteria(criteria interface{}) TestCaseBuilder
	WithTags(tags []string) TestCaseBuilder
	WithOWASPMapping(mapping string) TestCaseBuilder
	WithMetadata(metadata map[string]interface{}) TestCaseBuilder
	Build() (*TestCase, error)
}

TestCaseBuilder is an interface for building test cases

func NewTestCaseBuilder

func NewTestCaseBuilder() TestCaseBuilder

NewTestCaseBuilder creates a new test case builder

type TestCaseFactory

type TestCaseFactory interface {
	CreatePromptInjectionTestCases() []*TestCase
	CreateInsecureOutputHandlingTestCases() []*TestCase
	CreateTrainingDataPoisoningTestCases() []*TestCase
	CreateModelDoSTestCases() []*TestCase
	CreateSupplyChainVulnerabilitiesTestCases() []*TestCase
	CreateSensitiveInfoDisclosureTestCases() []*TestCase
	CreateInsecurePluginDesignTestCases() []*TestCase
	CreateExcessiveAgencyTestCases() []*TestCase
	CreateOverrelianceTestCases() []*TestCase
	CreateModelTheftTestCases() []*TestCase
	CreateTestCasesForVulnerability(vulnerabilityType VulnerabilityType) ([]*TestCase, error)
	CreateTestSuite(id string, name string, description string) *TestSuite
}

TestCaseFactory is an interface for creating test cases

type TestFactory

type TestFactory interface {
	CreateTestCase(vulnerabilityType VulnerabilityType, id string, name string, description string) (*TestCase, error)
	CreateTestSuite(id string, name string, description string) (*TestSuite, error)
	RegisterValidator(validator interface{}) error
	GetValidator(vulnerabilityType VulnerabilityType) (interface{}, error)
	RegisterComplianceService(service interface{}) error
	GetComplianceService() (interface{}, error)
}

TestFactory is an interface for creating test cases and test suites

func GetDefaultTestFactory

func GetDefaultTestFactory() TestFactory

GetDefaultTestFactory returns the default test factory

type TestResult

type TestResult struct {
	TestCase         *TestCase                   `json:"test_case"`
	Passed           bool                        `json:"passed"`
	Response         string                      `json:"response"`
	DetectionResults []detection.DetectionResult `json:"detection_results"`
	ExecutionTime    time.Duration               `json:"execution_time"`
	Timestamp        time.Time                   `json:"timestamp"`
	Notes            string                      `json:"notes"`
}

TestResult represents the result of a test case execution

type TestRunner

type TestRunner interface {
	RunTest(ctx context.Context, testCase *TestCase, provider core.Provider, model string) (*TestResult, error)
	RunTestSuite(ctx context.Context, testSuite *TestSuite, provider core.Provider, model string) error
}

TestRunner is an interface for running tests

type TestSuite

type TestSuite struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	TestCases   []*TestCase            `json:"test_cases"`
	Results     []*TestResult          `json:"results"`
	CreatedAt   time.Time              `json:"created_at"`
	CompletedAt time.Time              `json:"completed_at"`
	Metadata    map[string]interface{} `json:"metadata"`
	Tags        []string               `json:"tags"`
}

TestSuite represents a collection of test cases

type TestSuiteBuilder

type TestSuiteBuilder interface {
	NewTestSuite() (interface{}, error)
	WithID(id string) TestSuiteBuilder
	WithName(name string) TestSuiteBuilder
	WithDescription(description string) TestSuiteBuilder
	WithTestCases(testCases []*TestCase) TestSuiteBuilder
	WithMetadata(metadata map[string]interface{}) TestSuiteBuilder
	Build() (*TestSuite, error)
}

TestSuiteBuilder is an interface for building test suites

func NewTestSuiteBuilder

func NewTestSuiteBuilder() TestSuiteBuilder

NewTestSuiteBuilder creates a new test suite builder

type VulnerabilityType

type VulnerabilityType string

VulnerabilityType represents the type of vulnerability being tested

const (
	PromptInjection                VulnerabilityType = "prompt_injection"
	InsecureOutput                 VulnerabilityType = "insecure_output"
	InsecureOutputHandling         VulnerabilityType = "insecure_output_handling"
	TrainingDataPoisoning          VulnerabilityType = "training_data_poisoning"
	ModelDOS                       VulnerabilityType = "model_dos"
	SupplyChainVulnerabilities     VulnerabilityType = "supply_chain_vulnerabilities"
	SensitiveInformationDisclosure VulnerabilityType = "sensitive_information_disclosure"
	InsecurePluginDesign           VulnerabilityType = "insecure_plugin_design"
	ExcessiveAgency                VulnerabilityType = "excessive_agency"
	Overreliance                   VulnerabilityType = "overreliance"
	ModelTheft                     VulnerabilityType = "model_theft"
)

OWASP Top 10 for LLM vulnerability types

Jump to

Keyboard shortcuts

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