Credentials and personas
Authenticate Canary so it can test logged-in areas of your app.
A credential is one login for your app. A persona is a role, such as Acme admin, that groups the credentials for that role. For the steps, see Test a live environment.
Which login a run uses
A test signs in as a persona. Cofactor picks the persona's credential like this:
- The credential set to the environment the run uses.
- If there is none, the credential with no environment. The form calls this All environments.
- If there is none, the run fails with
CREDENTIAL_TEMPLATE_NOT_BOUND_FOR_ENV. The message names the environments that do have a login.
A persona holds at most one credential for each environment. If a run names no environment, it uses the application's default environment.
Sandboxes work differently. Their personas come from personas in cofactor.sandbox.yaml. See Seed data and logins.
Credential types
Add credential in Test Users offers these types.
| Type | Use it for |
|---|---|
| Enter your own credentials | A username and password for a login form |
| Sign in with Google (token) | Apps behind Google sign-in, using a refresh token |
| API key or token | API requests with a key or bearer token |
| API Basic Auth | HTTP Basic authentication |
| API Login | An API call that returns a token |
Persona variables
A persona can declare extra values, such as an account ID. Each credential fills them in, and a test reads them as $var.USER.<NAME>.
cofactor persona create --application "Acme Web" --name "Acme admin" --variable ACCOUNT_ID --variable API_TOKEN:sensitive cofactor credential update <credential id> --variable ACCOUNT_ID=1234
Commands
| Command | What it does |
|---|---|
cofactor persona list, show, create, rename, delete | Manage personas on an application |
cofactor persona link, unlink | Put a credential in a persona or take it out |
cofactor credential list, create, update, delete | Manage credentials |
cofactor credential test <credential id> | Run a browser sign-in with one credential |
cofactor env create, update, set-default | Manage an application's environments |
Pass --application <name or id> to the persona and environment commands. Run cofactor persona --help for every option. To set which environment a credential belongs to, use Test Users in the app.
Treat credentials as secrets. Use test accounts with the least access they need, and enter passwords in the app, not in a command.