testutil

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestAuthUser     = "clouditor"
	TestAuthPassword = "clouditor"

	TestAuthClientID     = "client"
	TestAuthClientSecret = "secret"

	TestCustomClaims  = "cloudserviceid"
	TestCloudService1 = "11111111-1111-1111-1111-111111111111"
	TestCloudService2 = "22222222-2222-2222-2222-222222222222"
)

Variables

View Source
var (
	// TestContextOnlyService1 is an incoming context with a JWT that only allows access to cloud service ID
	// 11111111-1111-1111-1111-111111111111
	TestContextOnlyService1 context.Context

	// TestBrokenContext contains an invalid JWT
	TestBrokenContext = metadata.NewIncomingContext(context.Background(), metadata.New(map[string]string{
		"authorization": "bearer what",
	}))

	// TestClaimsOnlyService1 contains claims that authorize the user for the cloud service
	// 11111111-1111-1111-1111-111111111111.
	TestClaimsOnlyService1 = jwt.MapClaims{
		"sub": "me",
		"cloudserviceid": []string{
			TestCloudService1,
		},
		"other": []int{1, 2},
	}
)

Functions

func AuthClientConfig

func AuthClientConfig(port uint16) *clientcredentials.Config

func AuthURL

func AuthURL(port uint16) string

func JWKSURL

func JWKSURL(port uint16) string

func NewInMemoryStorage added in v1.4.5

func NewInMemoryStorage(t *testing.T, funcs ...func(s persistence.Storage)) (s persistence.Storage)

NewInMemoryStorage uses the inmemory package to create a new in-memory storage that can be used for unit testing. The funcs varargs can be used to immediately execute storage operations on it.

func StartAuthenticationServer

func StartAuthenticationServer() (srv *oauth2.AuthorizationServer, port uint16, err error)

StartAuthenticationServer starts an authentication server on a random port with users and clients specified in the TestAuthUser and TestAuthClientID constants.

func TokenURL

func TokenURL(port uint16) string

Types

type ListRecvStreamerOf added in v1.4.5

type ListRecvStreamerOf[MsgType proto.Message] struct {
	Messages []MsgType
}

ListRecvStreamerOf implements a grpc.ClientStream that mocks the reception of a list of messages and then EOFs.

func (ListRecvStreamerOf[MsgType]) CloseSend added in v1.4.5

func (ListRecvStreamerOf[MsgType]) CloseSend() error

func (ListRecvStreamerOf[MsgType]) Context added in v1.4.5

func (ListRecvStreamerOf[MsgType]) Context() context.Context

func (ListRecvStreamerOf[MsgType]) Header added in v1.4.5

func (ListRecvStreamerOf[MsgType]) Header() (metadata.MD, error)

func (*ListRecvStreamerOf[MsgType]) Recv added in v1.4.5

func (l *ListRecvStreamerOf[MsgType]) Recv() (req MsgType, err error)

func (ListRecvStreamerOf[MsgType]) RecvMsg added in v1.4.5

func (ListRecvStreamerOf[MsgType]) RecvMsg(_ interface{}) error

func (ListRecvStreamerOf[MsgType]) SendMsg added in v1.4.5

func (ListRecvStreamerOf[MsgType]) SendMsg(_ interface{}) error

func (ListRecvStreamerOf[MsgType]) Trailer added in v1.4.5

func (ListRecvStreamerOf[MsgType]) Trailer() metadata.MD

type StorageWithError added in v1.4.5

type StorageWithError struct {
	CreateErr error
	SaveErr   error
	UpdateErr error
	GetErr    error
	ListErr   error
	CountErr  error
	DeleteErr error
}

StorageWithError can be used to introduce various errors in a storage operation during unit testing.

func (*StorageWithError) Count added in v1.4.5

func (s *StorageWithError) Count(_ any, _ ...any) (int64, error)

func (*StorageWithError) Create added in v1.4.5

func (s *StorageWithError) Create(_ any) error

func (*StorageWithError) Delete added in v1.4.5

func (s *StorageWithError) Delete(_ any, _ ...any) error

func (*StorageWithError) Get added in v1.4.5

func (s *StorageWithError) Get(_ any, _ ...any) error

func (*StorageWithError) List added in v1.4.5

func (s *StorageWithError) List(_ any, _ string, _ bool, _ int, _ int, _ ...any) error

func (*StorageWithError) Save added in v1.4.5

func (s *StorageWithError) Save(_ any, _ ...any) error

func (*StorageWithError) Update added in v1.4.5

func (*StorageWithError) Update(_ any, _ ...any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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