e2e

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTokenFromSetCookie

func ExtractTokenFromSetCookie(resp *http.Response, cookieName string) string

ExtractTokenFromSetCookie extracts a session token from Set-Cookie header.

func SimulateUserAuthorization

func SimulateUserAuthorization(serverURL, userCode string) error

SimulateUserAuthorization simulates a user authorizing a device code. This makes the necessary HTTP requests that a browser would make.

Types

type FakeOAuthProvider

type FakeOAuthProvider struct {
	Server      *httptest.Server
	Config      *oauth2.Config
	AutoApprove bool // automatically approve authorization requests
	// contains filtered or unexported fields
}

FakeOAuthProvider simulates an OAuth2 provider for testing. It provides minimal OAuth2 endpoints for authorization code flow.

func NewFakeOAuthProvider

func NewFakeOAuthProvider(autoApprove bool) *FakeOAuthProvider

NewFakeOAuthProvider creates a new fake OAuth2 provider for testing. If autoApprove is true, authorization requests are immediately approved without user interaction, which is useful for automated testing.

func (*FakeOAuthProvider) Close

func (p *FakeOAuthProvider) Close()

Close shuts down the fake OAuth server.

func (*FakeOAuthProvider) OAuthConfig

func (p *FakeOAuthProvider) OAuthConfig() *oauth2.Config

OAuthConfig returns the oauth2.Config pointing to this fake provider.

func (*FakeOAuthProvider) Reset

func (p *FakeOAuthProvider) Reset()

Reset clears all stored authorization codes and access tokens. This is useful for isolating tests.

type FakeUser

type FakeUser struct {
	ID    string
	Email string
}

FakeUser represents a fake user for testing.

func (*FakeUser) String

func (f *FakeUser) String() string

String implements Identifier interface.

type MeResponse

type MeResponse struct {
	UserID           string    `json:"user_id"`
	SessionID        string    `json:"session_id"`
	IdleDeadline     time.Time `json:"idle_deadline"`
	AbsoluteDeadline time.Time `json:"absolute_deadline"`
}

MeResponse represents the response from /api/me endpoint.

type NativeAppClient added in v0.9.2

type NativeAppClient struct {
	BaseURL    string
	Token      string // stored session token
	HTTPClient *http.Client
}

NativeAppClient simulates a native application (desktop, mobile, CLI) authenticating with the server. It supports device code flow and browser OAuth flow.

func NewNativeAppClient added in v0.9.2

func NewNativeAppClient(baseURL string) *NativeAppClient

NewNativeAppClient creates a new native app client that talks to the given base URL.

func (*NativeAppClient) AuthenticateViaDeviceCode added in v0.9.2

func (c *NativeAppClient) AuthenticateViaDeviceCode(ctx context.Context, authorizeFunc func(userCode string) error) error

AuthenticateViaDeviceCode performs the device code OAuth flow. The authorizeFunc is called with the user code and should simulate the user authorizing the device via browser.

func (*NativeAppClient) BrowserAuthFlow added in v0.9.2

func (c *NativeAppClient) BrowserAuthFlow(ctx context.Context) error

BrowserAuthFlow simulates a browser OAuth flow and returns the session cookie. This is used for testing cookie-based authentication.

func (*NativeAppClient) GetMe added in v0.9.2

func (c *NativeAppClient) GetMe(ctx context.Context) (*MeResponse, error)

GetMe calls /api/me to verify authentication and get session info.

func (*NativeAppClient) Request added in v0.9.2

func (c *NativeAppClient) Request(ctx context.Context, method, path string, body io.Reader) (*http.Response, error)

Request makes an authenticated HTTP request using the stored token.

func (*NativeAppClient) RequestWithCookie added in v0.9.2

func (c *NativeAppClient) RequestWithCookie(ctx context.Context, method, path, cookieName string) (*http.Response, error)

RequestWithCookie makes an HTTP request with the token sent as a cookie instead of header. This simulates browser-based authentication.

type TestServer

type TestServer struct {
	Server      *httptest.Server
	Gosesh      *gosesh.Gosesh
	Store       *gosesh.MemoryStore
	DeviceStore *gosesh.MemoryDeviceCodeStore
	OAuthServer *FakeOAuthProvider
	OAuthConfig *oauth2.Config
}

TestServer wraps an HTTP test server with gosesh for e2e testing. It provides a complete working server with OAuth2, sessions, and authentication.

func NewTestServer

func NewTestServer(opts ...TestServerOption) *TestServer

NewTestServer creates a new test server with gosesh configured for e2e testing. The server includes:

  • FakeOAuthProvider for OAuth2 (auto-approves by default)
  • MemoryStore for sessions
  • MemoryDeviceCodeStore for device codes
  • CompositeCredentialSource supporting both cookies and headers
  • All authentication routes configured

func (*TestServer) Close

func (ts *TestServer) Close()

Close shuts down the test server and fake OAuth provider.

func (*TestServer) Reset

func (ts *TestServer) Reset()

Reset clears all session and device code state. Call this between tests to isolate state.

type TestServerOption

type TestServerOption func(*TestServer)

TestServerOption configures a TestServer.

Jump to

Keyboard shortcuts

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