utils

package
v0.0.0-...-5d43b02 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: BSD-2-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package utils contains the internal test utils

Package utils contains the internal test utils

Index

Constants

This section is empty.

Variables

View Source
var Actions = map[string]Action{
	Account.String():  Account,
	Auth.String():     Auth,
	Password.String(): Password,
	Session.String():  Session,
}

Actions is a map with all the available Actions by their name.

Functions

func TestBinaryDataDecoder

func TestBinaryDataDecoder(ptr pam.BinaryPointer) ([]byte, error)

TestBinaryDataDecoder decodes a test binary data.

func TestBinaryDataEncoder

func TestBinaryDataEncoder(bytes []byte) []byte

TestBinaryDataEncoder encodes a test binary data.

func WithWorkDir

func WithWorkDir() withWorkDir

Types

type Action

type Action int

Action represents a PAM action to perform.

const (
	// Account is the account.
	Account Action = iota + 1
	// Auth is the auth.
	Auth
	// Password is the password.
	Password
	// Session is the session.
	Session
)

func (Action) String

func (a Action) String() string

type BaseModule

type BaseModule struct{}

BaseModule is the type for a base PAM module.

func (*BaseModule) AcctMgmt

func (h *BaseModule) AcctMgmt(pam.ModuleTransaction, pam.Flags, []string) error

AcctMgmt is the handler function for PAM AcctMgmt.

func (*BaseModule) Authenticate

func (h *BaseModule) Authenticate(pam.ModuleTransaction, pam.Flags, []string) error

Authenticate is the handler function for PAM Authenticate.

func (*BaseModule) ChangeAuthTok

func (h *BaseModule) ChangeAuthTok(pam.ModuleTransaction, pam.Flags, []string) error

ChangeAuthTok is the handler function for PAM ChangeAuthTok.

func (*BaseModule) CloseSession

func (h *BaseModule) CloseSession(pam.ModuleTransaction, pam.Flags, []string) error

CloseSession is the handler function for PAM CloseSession.

func (*BaseModule) OpenSession

func (h *BaseModule) OpenSession(pam.ModuleTransaction, pam.Flags, []string) error

OpenSession is the handler function for PAM OpenSession.

func (*BaseModule) SetCred

func (h *BaseModule) SetCred(pam.ModuleTransaction, pam.Flags, []string) error

SetCred is the handler function for PAM SetCred.

type BinaryTransaction

type BinaryTransaction struct {
	ExpectedNull bool
	ReturnedData []byte
	// contains filtered or unexported fields
}

BinaryTransaction represents a binary PAM transaction handler struct.

func NewBinaryTransactionWithData

func NewBinaryTransactionWithData(data []byte, retData []byte) BinaryTransaction

NewBinaryTransactionWithData creates a new [pam.BinaryTransaction] from bytes.

func NewBinaryTransactionWithRandomData

func NewBinaryTransactionWithRandomData(size uint8, retData []byte) BinaryTransaction

NewBinaryTransactionWithRandomData creates a new [pam.BinaryTransaction] with random data.

func (BinaryTransaction) Data

func (b BinaryTransaction) Data() []byte

Data returns the bytes of the transaction.

func (BinaryTransaction) RespondPAM

func (b BinaryTransaction) RespondPAM(s pam.Style, msg string) (string, error)

RespondPAM (not) handles the PAM string conversations.

func (BinaryTransaction) RespondPAMBinary

func (b BinaryTransaction) RespondPAMBinary(ptr pam.BinaryPointer) ([]byte, error)

RespondPAMBinary handles the PAM binary conversations.

type Control

type Control int

Control represents how a PAM module should controlled in PAM service file.

const (
	// Required implies that the module is required.
	Required Control = iota + 1
	// Requisite implies that the module is requisite.
	Requisite
	// Sufficient implies that the module is sufficient.
	Sufficient
	// Optional implies that the module is optional.
	Optional
)

func (Control) String

func (c Control) String() string

type Credentials

type Credentials struct {
	User              string
	Password          string
	EchoOn            string
	EchoOff           string
	TextInfo          string
	ErrorMsg          string
	ExpectedMessage   string
	CheckEmptyMessage bool
	ExpectedStyle     pam.Style
	CheckZeroStyle    bool
	Context           interface{}
}

Credentials is a test [pam.ConversationHandler] implementation.

func (Credentials) RespondPAM

func (c Credentials) RespondPAM(s pam.Style, msg string) (string, error)

RespondPAM handles PAM string conversations.

type FallBackModule

type FallBackModule int

FallBackModule is a type to represent the module that should be used as fallback.

const (
	// NoFallback add no fallback module.
	NoFallback FallBackModule = iota + 1
	// Permit uses a module that always permits.
	Permit
	// Deny uses a module that always denys.
	Deny
)

func (FallBackModule) String

func (a FallBackModule) String() string

type SerializableError

type SerializableError struct {
	Msg string
}

SerializableError is a representation of an error in a way can be serialized.

func (*SerializableError) Error

func (e *SerializableError) Error() string

type ServiceLine

type ServiceLine struct {
	Action  Action
	Control Control
	Module  string
	Args    []string
}

ServiceLine is the representation of a PAM module service file line.

type TestSetup

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

TestSetup is an utility type for having a playground for test PAM modules.

func NewTestSetup

func NewTestSetup(t *testing.T, args ...interface{}) *TestSetup

NewTestSetup creates a new TestSetup.

func (*TestSetup) CreateService

func (ts *TestSetup) CreateService(serviceName string, services []ServiceLine) string

CreateService creates a service file.

func (*TestSetup) CreateTemporaryDir

func (ts *TestSetup) CreateTemporaryDir(basename string) string

CreateTemporaryDir creates a temporary directory with provided basename.

func (*TestSetup) GenerateModule

func (ts *TestSetup) GenerateModule(testModulePath string, moduleName string) string

GenerateModule generates a PAM module for the provided path and name.

func (*TestSetup) GenerateModuleDefault

func (ts *TestSetup) GenerateModuleDefault(testModulePath string) string

GenerateModuleDefault generates a default module.

func (TestSetup) GetCurrentFile

func (ts TestSetup) GetCurrentFile() string

GetCurrentFile returns the current file path.

func (TestSetup) GetCurrentFileDir

func (ts TestSetup) GetCurrentFileDir() string

GetCurrentFileDir returns the current file directory.

func (TestSetup) WorkDir

func (ts TestSetup) WorkDir() string

WorkDir returns the test setup work directory.

Jump to

Keyboard shortcuts

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