Documentation
¶
Overview ¶
Package authtest checks that an application's routes refuse the principals their needs exclude.
Routes calls every route of an authhttp.Mux as four principals that most routes should refuse, and fails the test when one gets a 2xx it shouldn't:
- an anonymous caller
- a human session in recovery mode, signed in with a recovery code alone
- a human session that signed in a day ago
- an agent token with no scopes
A principal "shouldn't" get a 2xx when the route's need, tightened by auth.WithNeeds, excludes it. Run it in CI, so a route that forgets its rule fails before it ships.
Routes checks only that each route enforces the need it declares. It can't tell whether that need is right, so it doesn't catch:
- a need that is too loose, for example a route that should need a human but declares auth.Need{}, or one missing a scope
- a Public route that should have a need; Routes skips Public routes
- a handler that checks the wrong thing itself, such as another user's resource, or an agent where only a person should act
Your application's own route tests catch those: call each sensitive route as the principal it must refuse, such as an agent or another user, and expect the refusal. To review Public routes, compare PublicRoutes with the list you expect in a test, so adding one fails until you add it to that list.
Index ¶
Constants ¶
const User auth.UserID = "authtest-user"
User is the account whose sessions Routes creates.
Variables ¶
This section is empty.
Functions ¶
func PublicRoutes ¶
PublicRoutes returns the pattern of every authhttp.Public route of m, in the order they were registered. Routes skips these, so compare the list with the one you expect in a test, and review each route you add.
Types ¶
This section is empty.