# Test accounts (session profiles)

A test account is an identity you test as: the headers and cookies a
signed-in session carries for one role (admin, regular user, another
tenant). Keep one per role in the vault, and Repeater sends as any of
them without pasting tokens into requests. Manage them in the **Test
accounts** card on the vault page.

## What a profile holds

- **Name** and a **role label**. The label marks every request sent as
  this account in history (the Source column, `label:admin` in search).
- **Headers**, such as `Authorization: Bearer …` or an API key.
- **Cookies**, each scoped by domain and path the way a browser scopes
  them: a cookie for `example.com` also goes to its subdomains, one
  marked **This host only** goes to that exact host; a path such as
  `/admin` covers `/admin/...` but not `/administrator`.
- A **check request**: a URL that only succeeds while signed in (for
  example `/api/me`), the status it should answer and, optionally, text
  its answer must contain.

Values are encrypted with the configuration key as soon as they are
saved and never come back: the card shows names, scopes and the last
four characters of long values. When editing, a value left empty keeps
what is stored; type a new one to replace it.

## Sending as an account

In Repeater's tab settings, **Send as** picks the account. On each send
its headers replace request headers of the same name and its matching
cookies are merged into the `Cookie` header (a cookie of the same name
in the request is replaced, others are kept). Everything else about the
send is unchanged: scope, the engagement rules and the emergency stop
apply, and the request is recorded as sent. Deleting an account leaves
the tabs that used it sending as written.

## Health

**Check now** in an account's menu sends its check request (in scope,
under the engagement rules, recorded in history) and marks the account
**Working**, **Expired** (the answer was 401 or 403) or **Failing** (any
other unexpected status, missing text, or a network error), with when it
was checked. A Repeater send as an account that answers 401 or 403 marks
it **Expired** too, so a session that timed out shows on the vault page
instead of quietly producing failed requests. Sign in again in the
browser, copy the new values into the account, and check it.

## Login recipes

> **-pre**
>
>
> An account can sign itself in. Right-click it on the vault page and
> choose **Login recipe…**:
>
> - **Secrets** are the values the recipe refers to by name, written
>   `{{password}}` in a step. They are encrypted like the account's other
>   values and never shown again. A secret value typed into a step is
>   turned into its reference when the recipe is saved.
> - **Steps** are up to ten requests, sent in order. Each can require a
>   status and take values from its answer for later steps: a response
>   header, a JSON field (`data.token`, `items.0.id`) or the first group of
>   a regular expression (a CSRF token in a form). Cookies the answers
>   set go to the account's jar and are sent by the next steps.
> - **Headers after sign-in** are rebuilt from the secrets and the values
>   taken, for example `Authorization: Bearer {{token}}`.
> - **Sign in again** repeats the recipe every 5 minutes to a day.
>
> To draft steps from a login you already performed, type its History
> numbers (`#1204 #1205`) and choose **Draft steps**. Cookies, hop-by-hop
> and cache headers are dropped; username, email, password, OTP and
> similar fields of a form or JSON body, and an `Authorization` header,
> are moved into the secrets and replaced by references.
>
> **Save and sign in** (or **Sign in now** in the account's menu) runs the
> recipe through the same path as a Repeater send: scope, engagement rules
> and the emergency stop apply, and every step is recorded in History,
> with each secret value replaced by its reference before it is written.
> When every step passes, the account's headers and cookies are updated
> and it is marked Working. Otherwise it is marked Failing with the step
> and the reason, and nothing else changes.
>
> A scheduled sign-in starts only after you ran the recipe yourself once.
> If a scheduled run fails, the schedule pauses until you run it again,
> so a refused account is never retried in a loop. Agents see an
> account's recipe and secret names; saving, drafting and running are
> yours.
>

## Agents

Agents with `workspace.read` list accounts by name, role, header names,
cookie scopes and health (`session_profile_list`), without values or
hints; with `testing.execute` they run a check (`session_profile_check`).
Creating, changing and deleting accounts is the user's: the values are
the user's credentials. An agent sends as an account only through a
Repeater tab the user set to it, and reads what it sent with credentials
masked like any other request.

## REST

| Route | Does |
|---|---|
| `GET /api/v1/vaults/{id}/session-profiles` | Accounts by name, without values |
| `POST /api/v1/vaults/{id}/session-profiles` | Add one: `name`, `role`, `headers` `[{name, value}]`, `cookies` `[{name, value, domain, path, host_only}]`, `check` `{method, url, expect_status, expect_text}` |
| `PATCH /api/v1/vaults/{id}/session-profiles/{pid}` | Change; `headers` or `cookies`, when given, are the whole new set, and a `value` of `null` keeps the stored one |
| `DELETE /api/v1/vaults/{id}/session-profiles/{pid}` | Delete |
| `POST /api/v1/vaults/{id}/session-profiles/{pid}/check` | Run the check and record the health |
| `PATCH /api/v1/vaults/{id}/repeater/tabs/{tid}` | `session_profile_id` sends the tab as an account; `null` stops |
| `GET /api/v1/vaults/{id}/session-profiles/{pid}/login` | The recipe, secret names and `unresolved` references |
| `PUT /api/v1/vaults/{id}/session-profiles/{pid}/login` | `{recipe, secrets: [{name, value}]}`: replace both; a `null` value keeps the stored one, a secret left out is removed |
| `POST /api/v1/vaults/{id}/session-profiles/{pid}/login/draft` | `{flow_ids}`: replace the steps with drafts of captured requests |
| `POST /api/v1/vaults/{id}/session-profiles/{pid}/login/run` | Sign in: `{ok, steps: [{name, flow_id, status, extracted, error}], profile}` |

A vault holds at most 50 accounts. Header names must be HTTP tokens and
no value may contain a line break, so an account can never add a header
of its own or split a request.

## Not yet

Scans can sign in as an account (**Sign in as** in the new-scan form, `http.session_profile_id`, see [Scans](scans.md)). Intruder attacks can too (**Sign in as** in the attack options, see [Intruder](intruder.md)).
