ssohubtest

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package ssohubtest runs a hub with single sign-on in a test's own process, for tests of the terminal commands that talk to one (Task 20417).

pkg/ui's own tests drive its handlers against uiFakeIdP, a fake identity provider in its _test.go files, which nothing outside the package can reach. The `cloop remote` commands need the same thing from cmd: a real hub — its middleware, its role policy, its session store, its routes — with an identity provider the test controls, and a terminal session minted the way `cloop login` mints one, so a command run in the test is refused or allowed exactly as the dashboard would be for the same person.

Test-only (tests/arch/testonly_test.go): it imports "testing".

Index

Constants

View Source
const (
	GroupViewers     = "readers"
	GroupOperators   = "engineers"
	GroupMaintainers = "maintainers"
	GroupAdmins      = "owners"
)

The groups the default policy maps to roles, one per rung of the ladder.

View Source
const ClientID = "cloop-terminal-tests"

ClientID is the OAuth client the hub is registered as at the fake provider.

Variables

This section is empty.

Functions

func DefaultBindings

func DefaultBindings() []authz.Binding

DefaultBindings maps each group above to its role.

Types

type Hub

type Hub struct {
	Server *ui.Server
	// URL is the hub's base URL.
	URL string
	// Dir is the hub's own directory: its control plane.
	Dir string
	// Home is the HOME the hub runs with: its project registry, and the
	// projects root a project created by name goes under.
	Home string
	IdP  *IdP
	// contains filtered or unexported fields
}

Hub is a running hub with single sign-on.

func Start

func Start(t testing.TB, opts Options) *Hub

Start runs a hub with single sign-on, terminal sign-in and a role policy, with HOME pointed at a directory of the test's own.

func (*Hub) AddExecutor

func (h *Hub) AddExecutor(t testing.TB, ex executor.Executor, name string)

AddExecutor registers ex in this process's executor registry and records it in the control plane, so a project can be bound to it. Unregistered when the test ends.

func (*Hub) Call

func (h *Hub) Call(t testing.TB, browser *http.Client, method, path string, body any) (int, []byte)

Call makes a request to the hub as browser, returning the status and the raw answer: what the dashboard's own call gets, for a test to compare a terminal's rendering against.

func (*Hub) ControlPlane

func (h *Hub) ControlPlane(t testing.TB) *statedb.DB

ControlPlane opens the hub's control-plane database, closed with the test.

func (*Hub) Login

func (h *Hub) Login(t testing.TB, email string, groups ...string) string

Login signs in as email with groups and returns a terminal session for them.

func (*Hub) RestrictExecutor

func (h *Hub) RestrictExecutor(t testing.TB, id string, groups ...string)

RestrictExecutor puts an access list on an executor: only the named groups may use it.

func (*Hub) SignIn

func (h *Hub) SignIn(t testing.TB, email string, groups ...string) *http.Client

SignIn completes a browser sign-in as email with groups and returns the browser: a client with the session cookie.

func (*Hub) TerminalSession

func (h *Hub) TerminalSession(t testing.TB, browser *http.Client) string

TerminalSession is `cloop login` approved in browser: it returns the session credential a terminal would keep in its hubs.json.

type IdP

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

IdP is a minimal OpenID provider. Its authorization endpoint answers at once with a code for whoever it is currently set to be, and its token endpoint signs an ID token for the identity that code was issued to, with a refresh grant of its own.

func NewIdP

func NewIdP(t testing.TB) *IdP

NewIdP starts a provider, stopped with the test.

func (*IdP) SetIdentity

func (idp *IdP) SetIdentity(email string, groups ...string)

SetIdentity sets who the next sign-in is.

func (*IdP) URL

func (idp *IdP) URL() string

URL is the provider's issuer URL.

type Options

type Options struct {
	// Bindings are the role mappings; nil means DefaultBindings.
	Bindings []authz.Binding
	// AdminEmails become global admins, as ui.oidc.admin_emails does.
	AdminEmails []string
	// SelfExe is the binary the hub runs for `cloop init`, `cloop feature`
	// and the rest of the work it dispatches (Server.SelfExe).
	SelfExe string
	// Goal is the hub's own project's goal.
	Goal string
}

Options shape the hub.

type StubExecutor

type StubExecutor struct {
	IDValue string
}

StubExecutor isolates like a container and runs nothing: enough to be listed, admitted or refused, and bound to.

func (*StubExecutor) Capabilities

func (e *StubExecutor) Capabilities() executor.Capabilities

func (*StubExecutor) HealthCheck

func (e *StubExecutor) HealthCheck(context.Context) error

func (*StubExecutor) ID

func (e *StubExecutor) ID() string

func (*StubExecutor) Kind

func (e *StubExecutor) Kind() string

func (*StubExecutor) Signal

func (*StubExecutor) Start

func (*StubExecutor) Status

func (*StubExecutor) Stream

func (e *StubExecutor) Stream(context.Context, string) (<-chan executor.LogLine, error)

Jump to

Keyboard shortcuts

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