testing

package
v0.0.0-...-1a987c6 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testing provides shared constants and utilities for cloud-auth tests

Index

Constants

View Source
const (
	// Email domains
	TestOrgDomain = "testorg.com"
	NvidiaDomain  = "nvidia.com"
	ExampleDomain = "example.com"
	DevDomain     = "test.com"

	// Base URLs and endpoints
	LocalKeycloakURL = "http://localhost:8082"
	TestKeycloakURL  = "https://keycloak.test.com"
	TestCallbackURL  = "http://localhost:3000/callback"

	// Client identifiers
	TestClientID     = "test-client"
	TestClientSecret = "test-secret"
	AdminClientID    = "admin-cli"

	// Organization names
	TestOrgName     = "test-org"
	NICoDevOrgName  = "nico-tenant-dev"
	NICoProviderOrg = "nico-prime-provider"
	NvidiaOrgName   = "nvidia"

	// User identifiers
	TestUserEmail     = "john.doe@testorg.com"
	AdminUserEmail    = "admin@nvidia.com"
	TestUserSubject   = "test-subject"
	TestUserFirstName = "John"
	TestUserLastName  = "Doe"

	// Common JWT claims
	TestIssuer   = "test-issuer"
	TestAudience = "ngc"

	// Keycloak realm and IDP constants
	TestRealm       = "nico"
	TestIDPAlias    = "testorg-idp"
	TestIDPProvider = "oidc"
)

Test domain constants - consolidate similar patterns across test files

View Source
const (
	NICoProviderAdminRole  = authz.ProviderAdminRole
	NICoTenantAdminRole    = authz.TenantAdminRole
	NICoProviderViewerRole = authz.ProviderViewerRole
	NICoTenantViewerRole   = "TENANT_VIEWER"
)

Test role constants

View Source
const (
	TestRSAKeySize   = 2048
	TestECDSACurve   = "P-256"
	TestKeyID        = "test-key-id"
	TestSigningKeyID = "signing-key-1"
)

Key generation constants

Variables

View Source
var (
	TestIDPConfig = map[string]string{
		"clientId":          "test-client-id",
		"clientSecret":      "test-client-secret",
		"authorizationUrl":  "https://auth.testorg.com/oauth2/authorize",
		"tokenUrl":          "https://auth.testorg.com/oauth2/token",
		"userInfoUrl":       "https://auth.testorg.com/oauth2/userinfo",
		"jwksUrl":           "https://auth.testorg.com/.well-known/jwks.json",
		"issuer":            "https://auth.testorg.com",
		"validateSignature": "true",
		"useJwksUrl":        "true",
		"pkceEnabled":       "false",
		"emailDomain":       TestOrgDomain,
	}

	// Standard test IDP representation
	StandardTestIDP = &gocloak.IdentityProviderRepresentation{
		Alias:       gocloak.StringP(TestIDPAlias),
		DisplayName: gocloak.StringP("TestOrg OIDC"),
		ProviderID:  gocloak.StringP(TestIDPProvider),
		Enabled:     gocloak.BoolP(true),
		Config:      &TestIDPConfig,
	}
)

Mock IDP configurations for reuse across tests

View Source
var TestEmails = struct {
	Valid     []string
	EdgeCases []string
	Invalid   []string
}{
	Valid: []string{
		"user@" + TestOrgDomain,
		"admin@" + NvidiaDomain,
		"test.user@" + ExampleDomain,
		"first.last@" + DevDomain,
	},
	EdgeCases: []string{
		"user+tag@" + TestOrgDomain,
		"user.with.dots@" + TestOrgDomain,
		"user-with-dashes@" + TestOrgDomain,
		"UPPERCASE@" + TestOrgDomain,
	},
	Invalid: []string{
		"invalid-email",
		"@" + TestOrgDomain,
		"user@",
		"",
		"user space@" + TestOrgDomain,
	},
}

Common test emails for different scenarios

View Source
var TestRealmRoles = struct {
	SingleOrg     []string
	MultiOrg      []string
	MixedCase     []string
	InvalidFormat []string
}{
	SingleOrg: []string{
		TestOrgName + ":" + NICoProviderAdminRole,
		TestOrgName + ":" + NICoTenantAdminRole,
	},
	MultiOrg: []string{
		TestOrgName + ":" + NICoProviderAdminRole,
		NICoDevOrgName + ":" + NICoTenantAdminRole,
		NvidiaOrgName + ":" + NICoProviderViewerRole,
	},
	MixedCase: []string{
		"TestOrg:" + NICoProviderAdminRole,
		"TESTORG:" + NICoTenantAdminRole,
	},
	InvalidFormat: []string{
		"invalid-role-format",
		":" + NICoProviderAdminRole,
		TestOrgName + ":",
		"",
	},
}

Common realm access role combinations for testing

Functions

func EncodeBase64URLBigInt

func EncodeBase64URLBigInt(i *big.Int) string

EncodeBase64URLBigInt encodes a big integer as base64url

Types

type ConcurrencyHelper

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

ConcurrencyHelper provides utilities for concurrency testing

func NewConcurrencyHelper

func NewConcurrencyHelper(t *testing.T) *ConcurrencyHelper

NewConcurrencyHelper creates a new concurrency test helper

func (*ConcurrencyHelper) AssertConcurrentResults

func (h *ConcurrencyHelper) AssertConcurrentResults(results []interface{}, expectedValue interface{}, description string)

AssertConcurrentResults validates results from concurrent operations

func (*ConcurrencyHelper) AssertNoConcurrencyErrors

func (h *ConcurrencyHelper) AssertNoConcurrencyErrors(errors []error, description string)

AssertNoConcurrencyErrors validates that no errors occurred during concurrent execution

func (*ConcurrencyHelper) RunConcurrent

func (h *ConcurrencyHelper) RunConcurrent(fn func() error, numGoroutines int, description string) []error

RunConcurrent executes a function concurrently and collects results

type ErrorTestHelper

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

ErrorTestHelper provides utilities for error scenario testing

func NewErrorTestHelper

func NewErrorTestHelper(t *testing.T) *ErrorTestHelper

NewErrorTestHelper creates a new error test helper

func (*ErrorTestHelper) AssertErrorContains

func (h *ErrorTestHelper) AssertErrorContains(err error, expectedMsg string, description string)

AssertErrorContains validates that error contains expected message

func (*ErrorTestHelper) AssertErrorType

func (h *ErrorTestHelper) AssertErrorType(err error, expectedType interface{}, description string)

AssertErrorType validates error type using interface{}

type JWTAssertionHelper

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

JWTAssertionHelper provides consistent JWT validation patterns

func NewJWTHelper

func NewJWTHelper(t *testing.T) *JWTAssertionHelper

NewJWTHelper creates a new JWT assertion helper

func (*JWTAssertionHelper) AssertJWTAlgorithm

func (h *JWTAssertionHelper) AssertJWTAlgorithm(tokenString, expectedAlg, description string)

AssertJWTAlgorithm validates JWT algorithm

func (*JWTAssertionHelper) AssertJWTHasKid

func (h *JWTAssertionHelper) AssertJWTHasKid(tokenString, expectedKid, description string)

AssertJWTHasKid validates that JWT header contains kid

func (*JWTAssertionHelper) AssertValidJWT

func (h *JWTAssertionHelper) AssertValidJWT(tokenString string, description string) *jwt.Token

AssertValidJWT validates that a JWT token is properly formed and valid

type KeyGenerationHelper

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

KeyGenerationHelper provides consistent key generation for tests

func NewKeyHelper

func NewKeyHelper(t *testing.T) *KeyGenerationHelper

NewKeyHelper creates a new key generation helper

func (*KeyGenerationHelper) GenerateECDSAKey

func (h *KeyGenerationHelper) GenerateECDSAKey() *ecdsa.PrivateKey

GenerateECDSAKey generates an ECDSA key pair for testing

func (*KeyGenerationHelper) GenerateECDSAKeyP384

func (h *KeyGenerationHelper) GenerateECDSAKeyP384() *ecdsa.PrivateKey

GenerateECDSAKeyP384 generates an ECDSA P-384 key pair

func (*KeyGenerationHelper) GenerateRSAKey

func (h *KeyGenerationHelper) GenerateRSAKey() *rsa.PrivateKey

GenerateRSAKey generates an RSA key pair for testing

type MockServerHelper

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

MockServerHelper provides consistent mock server patterns

func NewMockServerHelper

func NewMockServerHelper(t *testing.T) *MockServerHelper

NewMockServerHelper creates a new mock server helper

func (*MockServerHelper) CreateJWKSServer

func (h *MockServerHelper) CreateJWKSServer(keys []TestKeyInfo) *httptest.Server

CreateJWKSServer creates a mock JWKS server with given keys

type TestKeyInfo

type TestKeyInfo struct {
	Key       interface{}
	KeyID     string
	Algorithm string
	Use       string
}

TestKeyInfo represents key information for testing

type TimeHelper

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

TimeHelper provides utilities for time-based testing

func NewTimeHelper

func NewTimeHelper(t *testing.T) *TimeHelper

NewTimeHelper creates a new time helper

func (*TimeHelper) AssertTimeWithinRange

func (h *TimeHelper) AssertTimeWithinRange(actual, expected time.Time, tolerance time.Duration, description string)

AssertTimeWithinRange validates that a time is within expected range

func (*TimeHelper) CreateExpiredTime

func (h *TimeHelper) CreateExpiredTime() time.Time

CreateExpiredTime returns a time in the past

func (*TimeHelper) CreateFutureTime

func (h *TimeHelper) CreateFutureTime() time.Time

CreateFutureTime returns a time in the future

func (*TimeHelper) CreateNearExpiredTime

func (h *TimeHelper) CreateNearExpiredTime() time.Time

CreateNearExpiredTime returns a time that's almost expired (within 5 minutes)

Jump to

Keyboard shortcuts

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