testing

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthorizedCode

type AuthorizedCode struct {
	Code         string
	ClientID     string
	RedirectURI  string
	State        string
	PKCEVerifier string
	UserID       string
	Scopes       []string
	IssuedAt     time.Time
	ExpiresAt    time.Time
}

AuthorizedCode represents an authorized code

type IssuedToken

type IssuedToken struct {
	AccessToken  string
	RefreshToken string
	TokenType    string
	ExpiresAt    time.Time
	UserID       string
	Scopes       []string
	IssuedAt     time.Time
}

IssuedToken represents an issued token

type MockOAuthServer

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

MockOAuthServer simulates an OAuth 2.0 provider for testing

func NewMockOAuthServer

func NewMockOAuthServer(config MockServerConfig) *MockOAuthServer

NewMockOAuthServer creates a new mock OAuth server

func (*MockOAuthServer) Close

func (m *MockOAuthServer) Close()

Close shuts down the mock server

func (*MockOAuthServer) CreateMockProvider

func (m *MockOAuthServer) CreateMockProvider() oauth.Provider

CreateMockProvider creates an OAuth provider configured for the mock server

func (*MockOAuthServer) GetAuthURL

func (m *MockOAuthServer) GetAuthURL() string

GetAuthURL returns the authorization endpoint URL

func (*MockOAuthServer) GetRevokeURL

func (m *MockOAuthServer) GetRevokeURL() string

GetRevokeURL returns the revoke endpoint URL

func (*MockOAuthServer) GetTokenURL

func (m *MockOAuthServer) GetTokenURL() string

GetTokenURL returns the token endpoint URL

func (*MockOAuthServer) GetURL

func (m *MockOAuthServer) GetURL() string

GetURL returns the mock server URL

func (*MockOAuthServer) GetUserInfoURL

func (m *MockOAuthServer) GetUserInfoURL() string

GetUserInfoURL returns the user info endpoint URL

func (*MockOAuthServer) IssueAuthorizationCode

func (m *MockOAuthServer) IssueAuthorizationCode(userID, state, redirectURI string, pkceVerifier string) string

IssueAuthorizationCode issues a new authorization code

func (*MockOAuthServer) SetErrorRate

func (m *MockOAuthServer) SetErrorRate(endpoint string, rate float64)

SetErrorRate sets the error rate for an endpoint (0.0 to 1.0)

func (*MockOAuthServer) SetFailureScenario

func (m *MockOAuthServer) SetFailureScenario(scenario string, enabled bool)

SetFailureScenario enables a specific failure scenario

func (*MockOAuthServer) SetLatency

func (m *MockOAuthServer) SetLatency(endpoint string, latency time.Duration)

SetLatency sets artificial latency for an endpoint

func (*MockOAuthServer) SetUserInfo

func (m *MockOAuthServer) SetUserInfo(userID string, info *oauth.UserInfo)

SetUserInfo sets user information for a specific user ID

type MockProvider

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

MockProvider implements oauth.Provider for testing

func (*MockProvider) Exchange

func (p *MockProvider) Exchange(ctx context.Context, code string, pkce *oauth.PKCEChallenge) (*oauth.Token, error)

func (*MockProvider) GetAuthURL

func (p *MockProvider) GetAuthURL(state string, pkce *oauth.PKCEChallenge) string

func (*MockProvider) GetUserInfo

func (p *MockProvider) GetUserInfo(ctx context.Context, accessToken string) (*oauth.UserInfo, error)

func (*MockProvider) Name

func (p *MockProvider) Name() string

func (*MockProvider) RefreshToken

func (p *MockProvider) RefreshToken(ctx context.Context, refreshToken string) (*oauth.Token, error)

func (*MockProvider) RevokeToken

func (p *MockProvider) RevokeToken(ctx context.Context, token string) error

func (*MockProvider) SupportsPKCE

func (p *MockProvider) SupportsPKCE() bool

func (*MockProvider) SupportsRefresh

func (p *MockProvider) SupportsRefresh() bool

func (*MockProvider) ValidateConfig

func (p *MockProvider) ValidateConfig() error

type MockServerConfig

type MockServerConfig struct {
	ProviderName    string
	ClientID        string
	ClientSecret    string
	SupportsPKCE    bool
	SupportsRefresh bool
	TokenExpiry     time.Duration
	RefreshExpiry   time.Duration
	RequireHTTPS    bool
}

MockServerConfig configures the mock OAuth server

Jump to

Keyboard shortcuts

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