analysistest

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package analysistest contains utility functions for testing the analysis tools.

Index

Constants

This section is empty.

Variables

View Source
var EscapeRegex = regexp.MustCompile(`//.*@Escape\(((?:\s*\w\s*,?)+)\)`)

EscapeRegex matches annotations of the form "@Escape(id1, id2, id3)"

View Source
var SinkRegex = regexp.MustCompile(`//.*@Sink\(((?:\s*\w\s*,?)+)\)`)

SinkRegex matches annotations of the form "@Sink(id1, id2, id3)"

View Source
var SourceRegex = regexp.MustCompile(`//.*@Source\(((?:\s*(\w|(\w\s+[a-zA-Z0-9$:\->]+\s*))\s*,?)+)\)`)

SourceRegex matches an annotation of the form @Source(id1, id2 meta2, ...) where the "argument" is either an identifier (e.g. id) or an identifier with associated "metadata" (e.g. id call:example1->call:helper->call:example1$1).

Functions

func GetExpectedTargetToSources

func GetExpectedTargetToSources(reldir string, dir string) (TargetToSources, TargetToSources)

GetExpectedTargetToSources analyzes the files in dir and looks for comments @Source(id) and @Sink(id) to construct expected flows from targets to sources in the form of two maps from: - from sink positions to all the source position that reach that sink. - from escape positions to the source of data that escapes.

func LoadTest

func LoadTest(t *testing.T, dir string, extraFiles []string) (*ssa.Program, *config.Config)

LoadTest loads the program in the directory dir, looking for a main.go and a config.yaml. If additional files are specified as extraFiles, the program will be loaded using those files too.

Types

type AnnotationID

type AnnotationID struct {
	// ID is the value of an annotation id.
	// e.g. @Source(id)
	//              ^^
	ID string
	// Meta is the identifier of the second portion of an annotation id.
	// This represents an annotation id metadata, usually for trace information.
	// e.g. @Source(id call:example1->call:helper)
	//                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
	// Meta can be empty.
	// e.g. @Source(id)
	Meta string
	// Pos is the position of the annotation.
	Pos LPos
}

AnnotationID represents an identifier in an annotation.

func (AnnotationID) String

func (id AnnotationID) String() string

type LPos

type LPos struct {
	// Filename is the file name of the position
	Filename string
	// Line is the line number in the file
	Line int
}

LPos is a line position

func RelPos

func RelPos(pos token.Position, reldir string) LPos

RelPos drops the column of the position and prepends reldir to the filename of the position

func RemoveColumn

func RemoveColumn(pos token.Position) LPos

RemoveColumn transforms a token.Position into a LPos by removing the column information

func (LPos) String

func (p LPos) String() string

type TargetToSources

type TargetToSources map[AnnotationID]map[AnnotationID]bool

TargetToSources is a mapping from a target annotation (e.g. ex in @Sink(ex, ex2)) to a source annotation (e.g. ex in @Source(ex, ex2)).

func (TargetToSources) HasMetadata

func (t TargetToSources) HasMetadata() bool

HasMetadata returns true if the TargetToSources mapping contains metadata

Jump to

Keyboard shortcuts

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