Documentation
¶
Overview ¶
Package testing provides shared constants and utilities for cloud-auth tests
Index ¶
- Constants
- Variables
- func EncodeBase64URLBigInt(i *big.Int) string
- type ConcurrencyHelper
- func (h *ConcurrencyHelper) AssertConcurrentResults(results []interface{}, expectedValue interface{}, description string)
- func (h *ConcurrencyHelper) AssertNoConcurrencyErrors(errors []error, description string)
- func (h *ConcurrencyHelper) RunConcurrent(fn func() error, numGoroutines int, description string) []error
- type ErrorTestHelper
- type JWTAssertionHelper
- type KeyGenerationHelper
- type MockServerHelper
- type TestKeyInfo
- type TimeHelper
Constants ¶
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" ForgeDevOrgName = "forge-tenant-dev" ForgeProviderOrg = "forge-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 = "forge" TestIDPAlias = "testorg-idp" TestIDPProvider = "oidc" )
Test domain constants - consolidate similar patterns across test files
const ( ForgeProviderAdminRole = "FORGE_PROVIDER_ADMIN" ForgeTenantAdminRole = "FORGE_TENANT_ADMIN" ForgeProviderViewerRole = "FORGE_PROVIDER_VIEWER" ForgeTenantViewerRole = "FORGE_TENANT_VIEWER" )
Test role constants
const ( TestRSAKeySize = 2048 TestECDSACurve = "P-256" TestKeyID = "test-key-id" TestSigningKeyID = "signing-key-1" )
Key generation constants
Variables ¶
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
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
var TestRealmRoles = struct { SingleOrg []string MultiOrg []string MixedCase []string InvalidFormat []string }{ SingleOrg: []string{ TestOrgName + ":" + ForgeProviderAdminRole, TestOrgName + ":" + ForgeTenantAdminRole, }, MultiOrg: []string{ TestOrgName + ":" + ForgeProviderAdminRole, ForgeDevOrgName + ":" + ForgeTenantAdminRole, NvidiaOrgName + ":" + ForgeProviderViewerRole, }, MixedCase: []string{ "TestOrg:" + ForgeProviderAdminRole, "TESTORG:" + ForgeTenantAdminRole, }, InvalidFormat: []string{ "invalid-role-format", ":" + ForgeProviderAdminRole, TestOrgName + ":", "", }, }
Common realm access role combinations for testing
Functions ¶
func EncodeBase64URLBigInt ¶
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 ¶
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)