Documentation
¶
Overview ¶
Package authtest checks a host's auth.Authenticator in the host's own CI, against the contract the libraries that take it enforce.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check(t testing.TB, a auth.Authenticator, c Cases)
Check fails t when a admits what it must refuse: an anonymous request or a Refused credential, a permission to someone who does not hold it, in a scope it was not granted in, or for a pattern; a stale sign-in as recent; an application as a person or as signed in; a credential bound to one scope as bound to another, or holding a permission outside it (but a person's in RootScope); any credential but Asserted as asserted, or Asserted as not. With auth.Root, it fails when RootScope fails, is not whole or changes, when a root: permission is held in a Scope other than RootScope, and when BoundStaff loses Staff's root permissions. With auth.Headers, it fails when a header Staff's credential is sent in is not allowed, or a header a refusal's Challenge carries is not exposed. It fails when a refuses Staff, User, a Holder, Application, Bound, Foreign or Asserted, so a check cannot pass vacuously, and when an error classifies as anything but the contract says (auth.Refuse), so every consumer answers it the same.
Types ¶
type Cases ¶
type Cases struct {
// Scope is where Permissions are held. Zero is the Authenticator's
// RootScope (auth.Root), where root: permissions are held.
Scope auth.Scope
// Permissions are the permissions the host gives the library, at least
// one.
Permissions []string
// Staff is a person signed in recently, holding every one of
// Permissions in Scope.
Staff func() *http.Request
// User is another person, signed in, holding none of them in Scope.
User func() *http.Request
// Holders are people each holding only the permission they are keyed
// by. Nil skips the case.
Holders map[string]func() *http.Request
// Stale is a person holding every one of Permissions whose sign-in is
// too old for an action that moves money. Nil skips the case.
Stale func() *http.Request
// Application is an application's credential (client credentials, an
// API key) holding every one of Permissions in Scope. Nil skips the
// case.
Application func() *http.Request
// Refused are credentials Authenticate must refuse, by name: an expired
// token, a forged one, a signed-out session, a banned or deleted
// account's.
Refused map[string]func() *http.Request
// Bound is a credential bound to Scope (auth.Bound), such as the
// group's API key or a trusted issuer's token for it. Nil skips the
// case.
Bound func() *http.Request
// Foreign is a credential bound to another scope, such as another
// group's API key; it holds none of Permissions in Scope. Nil skips the
// case.
Foreign func() *http.Request
// BoundStaff is Staff's sign-in bound to another scope, such as a token
// exchanged for one group. With Scope the Authenticator's RootScope, it
// still holds every one of Permissions there: a person keeps their root
// role (auth.Bound). Nil skips the case.
BoundStaff func() *http.Request
// Asserted is a credential minted from an application's assertion
// (auth.Asserted), such as a backend's token for its customer. Nil skips
// the case.
Asserted func() *http.Request
// Revoke ends the sign-in behind Staff's credential, as signing out
// does. Check calls it last; Authenticate must then refuse Staff. Nil
// skips the case.
Revoke func()
}
Cases are credentials the host's auth holds when Check runs. Each is a function returning a fresh request, since a sender proof is spent once.