- TestEndpointGuards: a foreign browser Origin is 403 before the bearer is read, a body over the endpoint cap is 413, a long GET stream ends once its grant stops verifying (T-19.7-18, T-19.7-19) - TestDispatch: an argument key the input struct does not declare is refused before dispatch (T-19.7-17) - the gate requires TestEndpointGuards (untagged and tagged) and runs the demo's deploy check (T-19.7-37)
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package pier
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
"git.golem15.com/golem15/summercms/modules/bouncer"
|
|
"git.golem15.com/golem15/summercms/modules/cabana"
|
|
)
|
|
|
|
// Test seams (package pier, compiled into the test binary only).
|
|
|
|
// SetBackendTokens replaces the admin personal token resolver, which needs
|
|
// a database in production (cabana.ResolveBackendToken).
|
|
func (p *Pier) SetBackendTokens(fn func(ctx context.Context, app *backpack.App, raw string) (*bouncer.Principal, *cabana.BackendAPIToken, []string, error)) {
|
|
p.identities.backendTokens = fn
|
|
}
|
|
|
|
// Resolve resolves a bearer into an Identity as the endpoint does.
|
|
func (p *Pier) Resolve(ctx context.Context, raw string) (Identity, error) {
|
|
return p.identities.resolve(ctx, raw)
|
|
}
|
|
|
|
// Ceiling reports whether the read/write ceiling applies to the identity.
|
|
func (id Identity) Ceiling() bool { return id.ceiling }
|
|
|
|
// AdvanceStoreClock moves the memory session store's clock forward by d, so
|
|
// a test can expire idle sessions without waiting; a Redis store is moved
|
|
// with miniredis.FastForward instead.
|
|
func (p *Pier) AdvanceStoreClock(d time.Duration) bool {
|
|
ms, ok := p.store.(*memoryStore)
|
|
if !ok {
|
|
return false
|
|
}
|
|
ms.mu.Lock()
|
|
base := ms.now
|
|
ms.now = func() time.Time { return base().Add(d) }
|
|
ms.mu.Unlock()
|
|
return true
|
|
}
|
|
|
|
// StatelessServers counts the per-identity servers of the stateless path.
|
|
func (p *Pier) StatelessServers() int {
|
|
p.stateless.mu.Lock()
|
|
defer p.stateless.mu.Unlock()
|
|
return len(p.stateless.entries)
|
|
}
|
|
|
|
// SetRecheck sets how often a long GET stream re-verifies its bearer.
|
|
func (p *Pier) SetRecheck(d time.Duration) { p.recheck = d }
|