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
- func DefaultBindings() []authz.Binding
- type Hub
- func (h *Hub) AddExecutor(t testing.TB, ex executor.Executor, name string)
- func (h *Hub) Call(t testing.TB, browser *http.Client, method, path string, body any) (int, []byte)
- func (h *Hub) ControlPlane(t testing.TB) *statedb.DB
- func (h *Hub) Login(t testing.TB, email string, groups ...string) string
- func (h *Hub) RestrictExecutor(t testing.TB, id string, groups ...string)
- func (h *Hub) SignIn(t testing.TB, email string, groups ...string) *http.Client
- func (h *Hub) TerminalSession(t testing.TB, browser *http.Client) string
- type IdP
- type Options
- type StubExecutor
- func (e *StubExecutor) Capabilities() executor.Capabilities
- func (e *StubExecutor) HealthCheck(context.Context) error
- func (e *StubExecutor) ID() string
- func (e *StubExecutor) Kind() string
- func (e *StubExecutor) Signal(context.Context, string, executor.Signal) error
- func (e *StubExecutor) Start(context.Context, executor.Spec) (executor.Handle, error)
- func (e *StubExecutor) Status(context.Context, string) (executor.Status, error)
- func (e *StubExecutor) Stream(context.Context, string) (<-chan executor.LogLine, error)
Constants ¶
const ( GroupViewers = "readers" GroupOperators = "engineers" GroupMaintainers = "maintainers" GroupAdmins = "owners" )
The groups the default policy maps to roles, one per rung of the ladder.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
ControlPlane opens the hub's control-plane database, closed with the test.
func (*Hub) RestrictExecutor ¶
RestrictExecutor puts an access list on an executor: only the named groups may use it.
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 (*IdP) SetIdentity ¶
SetIdentity sets who the next sign-in is.
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