Documentation
¶
Overview ¶
Package authtest helps test apps using auth: requests and live sessions signed in as anyone, without a login, and Users kept in memory.
Index ¶
- Variables
- func As(id *auth.Identity) web.Option
- func Context(ctx context.Context, id *auth.Identity) context.Context
- func Request(r *http.Request, id *auth.Identity) *http.Request
- type Users
- func (u *Users) Add(login, password string, id auth.Identity) *Users
- func (u *Users) AddEncoded(login, encoded string, id auth.Identity) *Users
- func (u *Users) Encoded(id string) string
- func (u *Users) FindLogin(_ context.Context, login string) (*auth.Identity, string, error)
- func (u *Users) Load(_ context.Context, id string) (*auth.Identity, error)
- func (u *Users) Remove(id string)
- func (u *Users) SetPassword(_ context.Context, id, encoded string) error
Constants ¶
This section is empty.
Variables ¶
var Cheap = auth.Argon2{Memory: 64, Time: 1, Threads: 1}
Cheap is a hashing cost for tests: fast, and far too weak for anything else. Users hashes with it; pass it as auth.Config.Passwords so logins don't re-hash.
Functions ¶
func As ¶
As signs every request of the app in as id — pages, APIs, live pages and their events — whatever credentials they carry:
app := web.New(auth.Module(cfg), authtest.As(&auth.Identity{ID: "7", Perms: []string{"orders.*"}}))
A nil id makes every request anonymous. A handler that signs in (auth.Login, auth.SignIn — a sign-in form's Save) works as it does without As: the session cookie is set on the response, the request staying signed in as id. Outside a test binary it panics: an app shipped with it would let everyone in.
Types ¶
type Users ¶
type Users struct {
// contains filtered or unexported fields
}
Users is an auth.Users kept in memory, with SetPassword.
func (*Users) AddEncoded ¶
AddEncoded adds a user whose password is already encoded (a bcrypt hash from an older system, say).