Docs/Credentials and personas
#

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:

  1. The credential set to the environment the run uses.
  2. If there is none, the credential with no environment. The form calls this All environments.
  3. 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.

TypeUse it for
Enter your own credentialsA username and password for a login form
Sign in with Google (token)Apps behind Google sign-in, using a refresh token
API key or tokenAPI requests with a key or bearer token
API Basic AuthHTTP Basic authentication
API LoginAn 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>.

bash
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

CommandWhat it does
cofactor persona list, show, create, rename, deleteManage personas on an application
cofactor persona link, unlinkPut a credential in a persona or take it out
cofactor credential list, create, update, deleteManage credentials
cofactor credential test <credential id>Run a browser sign-in with one credential
cofactor env create, update, set-defaultManage 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.