szenario

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UserTypeAll name of the usertype that contains all szenarios
	UserTypeAll = "all"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	CheckRepeat  time.Duration
	CheckTimeout time.Duration
	LoginRetry   int
	// contains filtered or unexported fields
}

Base is the base type of all szenarios

func (Base) GetMaxLoginTry added in v0.12.2

func (s Base) GetMaxLoginTry() int

GetMaxLoginTry returns how many times a login with a new password should be attemped

func (Base) Name

func (s Base) Name() string

Name returns the name of the szenario

func (Base) RepeatDelay added in v0.12.0

func (s Base) RepeatDelay() time.Duration

RepeatDelay between executions

func (*Base) SetName

func (s *Base) SetName(name string)

SetName do not call! rename panics

func (*Base) SetUser

func (s *Base) SetUser(u User)

SetUser set the user the szenario runs with

func (Base) Timeout added in v0.12.0

func (s Base) Timeout() time.Duration

Timeout for an execution

func (*Base) User

func (s *Base) User() User

User returns the user the szenario runs with

type CheckFunc

type CheckFunc func(*string) error

CheckFunc is used to check the plaintext body content

type Config

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

Config holds all Szenario informations

var (
	// NoConfig means that the sznario config has not been loaded and set
	NoConfig *Config = New()
)

func New

func New() *Config

New creates a new config

func (Config) Add

func (c Config) Add(name string, s Szenario, ut []*UserType) Szenario

Add a szenario to the engine

func (Config) ByName

func (c Config) ByName(name string) Szenario

ByName return the szario by name, names are case insensitive and if no exact match is found a prefix match is done

func (Config) ByUser

func (c Config) ByUser(u User) ([]Szenario, error)

ByUser retruns a Szenario slice defined by the users type

func (Config) CreateUserType

func (c Config) CreateUserType(n string, desc string) (*UserType, error)

CreateUserType creates a user type

func (Config) GetUserType

func (c Config) GetUserType(name string) *UserType

GetUserType returns the usertype

func (Config) GetUserTypes

func (c Config) GetUserTypes() []string

GetUserTypes returns a list of all user types

func (Config) SzenarioCount

func (c Config) SzenarioCount() int

SzenarioCount returns the number of szenarios

type EitherOption added in v0.11.0

type EitherOption struct {
	ID     any
	Action chromedp.Action
}

type Engine

type Engine interface {
	// StepTimeout executes a Step with an timeout
	StepTimeout(name string, timeout time.Duration, actions ...chromedp.Action) error
	// Step executes the actions given and records how long it takes
	Step(name string, actions ...chromedp.Action)

	// SetInputField sets a HTML input field and validates that it has been set
	SetInputField(stepName string, sel interface{}, value string, opts ...func(*chromedp.Selector)) error
	// IsPresent checks if something is present
	IsPresent(sel interface{}, opts ...chromedp.QueryOption) bool
	// Either wait for a list of options and sends the name of the first met option to the channel
	Either(name string, option ...EitherOption) <-chan any
	// Body is used to check the content of the page
	Body(checks ...CheckFunc) chromedp.Action
	// IsHeadless indicates if the browser is headless (i.e. does not show on screen)
	IsHeadless() bool
	// Dump prints the body and its size to log
	Dump() CheckFunc
	// Contains looks for a string in the body
	Contains(s string) CheckFunc
	// NotContains looks for a string in the body and errs if found
	NotContains(s string) CheckFunc
	// Bigger checks if the size of the body (in bytes) in bigger than i
	Bigger(i int) CheckFunc
	// Strings gets the body as plaintext
	Strings(html *string) CheckFunc
	// SetStatus sets a status of the event
	SetStatus(key, val string)
	// AddErr adds a error to the event
	AddErr(err error)
	// Log returns the logger
	Log() *slog.Logger

	// WaitForEver blocks until the timeout is reached
	WaitForEver()
	// BreakWaitForUserInput waits until any key is clicked on the cmdlint
	BreakWaitForUserInput()
}

Engine is executing a szenario

type JobFunc

type JobFunc func(Engine) error

JobFunc is the signature of a function that runs as job

type Szenario

type Szenario interface {
	Name() string               // Name returns the name
	User() User                 // User returns the user the szenario runs with
	SetUser(u User)             // SetUser set the user the szenario runs with
	Execute(Engine) error       // Execute the szenario
	RepeatDelay() time.Duration // RepeatDelay between executions
	Timeout() time.Duration     // Timeout for an execution
	GetMaxLoginTry() int        // GetMaxLoginTry returns how many times a login with a new password should be attemped
}

Szenario is the definition of a monitoring szenario

type TimeoutError added in v0.10.3

type TimeoutError struct {
	Timeout time.Duration
}

TimeoutError indicated a timeout

func (TimeoutError) Error added in v0.10.3

func (te TimeoutError) Error() string

Error interface

type User

type User interface {
	// Name returns the name
	Name() string
	// Email returns the email address
	Email() string

	// DisplayName returns the display name
	DisplayName() string

	// Type returns what kind of user it is
	Type() string

	// Password decrypts the password
	Password() string

	// NextPassword increases the password index and returns the decrypted PW
	// retruns empty string "" if no more passwords are present
	NextPassword() string

	// LoginSuccessfull sets the last use of the password
	LoginSuccessfull()

	// NewPassword generates a new password
	// it does not store the password
	NewPassword() (string, error)

	// PasswordHistoryCount returns the number of PW in the history
	PasswordHistoryCount() int

	// PasswordCreated returns the time when the password was created
	PasswordCreated() time.Time

	// PasswordLastUse returns the time when the password was last accessed
	PasswordLastUse() time.Time

	// NumPasswdChg number of times the password was changed
	NumPasswdChg(time.Duration) int

	// ResetPasswordIndex start with the first password
	// and reset the number of failed logins to 0
	ResetPasswordIndex()

	// FailedLogins the number of failed logins
	FailedLogins() int

	// SetPassword encrypts the password
	SetPassword(pw string)

	// String implements stringer
	String() string

	// IsValid checks if all needed fields are set
	IsValid() error

	// Save the user to the store
	Save() error
}

User stores a user and its encrypted password

type UserType

type UserType struct {
	Name      string
	Desc      string
	Szenarios []Szenario
}

UserType defines types of users

func MustUserType

func MustUserType(ut *UserType, err error) *UserType

MustUserType panics if usertype creation returns an error

Jump to

Keyboard shortcuts

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