testing_utils

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SharedSecretKey environment variable name for shared secret key for signing a token.
	SharedSecretKey = "SHARED_SECRET_KEY"

	AuthKey               = "authorization"
	BearerPrefixLowercase = "bearer "
)

Variables

This section is empty.

Functions

func AddJWTToTheIncomingContext

func AddJWTToTheIncomingContext(ctx context.Context, jwtToken string) context.Context

func AddJWTToTheOutgoingContext

func AddJWTToTheOutgoingContext(ctx context.Context, jwtToken string) context.Context

func CreateContextWithJWT

func CreateContextWithJWT(tb testing.TB) (context.Context, context.CancelFunc)

CreateContextWithJWT can be used only with test clients, which send the request to the server.

func CreateContextWithTimeoutWithJWT

func CreateContextWithTimeoutWithJWT(tb testing.TB, timeout time.Duration) (context.Context, context.CancelFunc)

CreateContextWithTimeoutWithJWT can be used only with test clients, which send the request to the server.

func CreateIncomingContextWithJWT

func CreateIncomingContextWithJWT(tb testing.TB) (context.Context, context.CancelFunc)

CreateIncomingContextWithJWT can be used to test the actual call, which performs the authorization.

func CreateIncomingContextWithTimeoutWithJWT

func CreateIncomingContextWithTimeoutWithJWT(tb testing.TB, timeout time.Duration) (context.Context, context.CancelFunc)

CreateIncomingContextWithTimeoutWithJWT can be used to test the actual call, which performs the authorization.

func CreateJWT

func CreateJWT(tb testing.TB) (string, string, error)

CreateJWT returns random signing key and JWT token (HS256 encoded) in a string with both roles, read and write. Only 1 token can persist in the system (otherwise, env variable holding secret key would be re-written).

func CreateJWTWithClaims

func CreateJWTWithClaims(tb testing.TB, claims *jwt.MapClaims) (string, string, error)

CreateJWTWithClaims returns random signing key and JWT token (HS256 encoded) in a string with defined claims.

func CreateJWTWithReadRole

func CreateJWTWithReadRole(tb testing.TB) (string, string, error)

CreateJWTWithReadRole returns random signing key and JWT token (HS256 encoded) in a string with only write role. Only 1 token can persist in the system (otherwise, env variable holding secret key would be re-written).

func CreateJWTWithWriteRole

func CreateJWTWithWriteRole(tb testing.TB) (string, string, error)

CreateJWTWithWriteRole returns random signing key and JWT token (HS256 encoded) in a string with only write role. Only 1 token can persist in the system (otherwise, env variable holding secret key would be re-written).

Types

This section is empty.

Jump to

Keyboard shortcuts

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