Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type StubMiddleware ¶
StubMiddleware is a no-op auth middleware for tests. If Scopes is nil/empty, scope.AllScopes() is used (the default for general-purpose tests). Tests that want to assert 403-for-missing-scope pass a restricted Scopes slice via TestServerOptions.
func (*StubMiddleware) Authorization ¶
func (s *StubMiddleware) Authorization() func(ctx fiber.Ctx) error
type StubPlatformMiddleware ¶
StubPlatformMiddleware attaches a platform principal: the identity system:kaiten, no organization, and the id of the platform credential being presented.
It is a separate type rather than a flag on StubMiddleware so that no test can accidentally produce the state the whole design forbids -- a platform principal that also carries an organization. There is no field here to set one with.
func (*StubPlatformMiddleware) Authorization ¶
func (s *StubPlatformMiddleware) Authorization() func(ctx fiber.Ctx) error
type StubUserProvider ¶
func (*StubUserProvider) GetUser ¶
func (s *StubUserProvider) GetUser(_ context.Context) (*currentuser.User, error)
type TestDatabase ¶
type TestDatabase struct {
DefaultData *TestData
DbPool *pgxpool.Pool
// ConnectionString is the container's DSN, exposed for tests that exercise a
// binary rather than a package: cmd/admin-tools reads
// KAITEN_DATABASE_CONNECTION_STRING from the environment and opens its own
// pool, so its tests need the string, not the pool.
ConnectionString string
// contains filtered or unexported fields
}
func NewTestDatabase ¶
func NewTestDatabase() (*TestDatabase, error)
func (*TestDatabase) Reset ¶
func (tdb *TestDatabase) Reset() error
func (*TestDatabase) TearDown ¶
func (tdb *TestDatabase) TearDown()
type TestServer ¶
type TestServer struct {
App *fiber.App
PlatformApp *fiber.App
Dependencies server.Dependencies
// contains filtered or unexported fields
}
TestServer holds both of the server's Fiber apps, because there are two listeners and a test has to say which one it is calling.
App is the Core (public) one and stays the default for every suite. PlatformApp is the internal one, and it is the ONLY app /api/platform/** answers on: a test that sends a platform request to App is asserting a 404, deliberately.
func NewTestServer ¶
func NewTestServer(tdb *TestDatabase, opts ...TestServerOptions) *TestServer
func (*TestServer) Close ¶
func (ts *TestServer) Close() error
Close stops the server the way the process does on shutdown: its listeners, then its background workers. Those include one pgnotify listener per module that listens, each on a Postgres connection of its own, and nothing else ever stops them -- a server a test forgets lives until the test binary exits. A suite that builds a server per subtest closes each one as the subtest ends, or their listeners pile up on the test database until it refuses new clients.
type TestServerOptions ¶
type TestServerOptions struct {
OrganizationID *uuid.UUID // Optional: override the default organization ID for stub auth
UseJWTAuth bool
// Scopes, when non-empty, restricts the principal to the given scope
// list (default is scope.AllScopes()). Use to test scope-gating
// (e.g. 403 when the caller lacks write:metadata_fields).
Scopes []string
ConfigOverride func(*config.Config)
UsageReporter services.UsageReporter
// PlatformFlags is an explicit per-suite rollout reader; nil stays closed.
PlatformFlags services.PlatformFlags
// ConnectorEntitlements stands in for the licensing deployment. Nil means
// services.AlwaysEntitled -- the self-hosted shape, where every registered
// connector is available -- which is what every suite that does not care about
// licences gets.
ConnectorEntitlements services.ConnectorEntitlements
// EntitlementConfig stands in for the licensing deployment's CONFIG
// entitlements, such as an organization's usage history retention. Nil means
// services.NoLicensingAuthority: the self-hosted shape, where those settings
// come from the configuration.
EntitlementConfig services.EntitlementConfig
// BillingProviders stands in for the payment providers a deployment
// registers. Nil means the providers the binary ships: NOOP and Stripe.
BillingProviders provider.Registry
// Stripe points the shipped Stripe adapter somewhere (a stripefake).
Stripe billingstripe.Options
// TurnstileVerifyURL points the Turnstile verification at a fake.
TurnstileVerifyURL string
// PlatformCredential makes BOTH of the server's listeners authenticate every
// request as a platform credential (StubPlatformMiddleware) instead of an
// organization one.
//
// Both, because the two things a suite does with this option are opposite
// sides of one boundary: send platform requests to PlatformApp and have them
// work, and send them to App and have them refused. The second needs a
// platform principal to reach the Core pipeline, which no production
// credential can now produce -- the stub is how the floor under that pipeline
// stays testable.
//
// It also wires the REAL currentuser.ContextUserProvider rather than
// StubUserProvider, and that is the point: StubUserProvider would hand every
// Core handler an organization the credential does not have, quietly
// reinstating exactly the confusion these tests exist to disprove.
PlatformCredential bool
// PlatformTokenID is the credential id the platform principal carries -- the
// same value a signed platform JWT would supply. Set it to the id of a row
// created by CreatePlatformToken when the test needs the credential to
// resolve (GET /platform/me); leave it zero when the test only needs a
// rejection.
PlatformTokenID uuid.UUID
}
TestServerOptions allows customizing the test server configuration