@owlmeans/test-auth 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -11,3 +11,20 @@ Helpers exported here:
|
|
|
11
11
|
- `signMockEnvelope(msg, type, kind?, kp?)` — wraps `makeEnvelopeModel` with a fixture keypair to produce a signed envelope.
|
|
12
12
|
- `makeBearer(auth, kp?)` — `ED25519-BASIC-TOKEN <encoded>` header value for unit tests of header parsing.
|
|
13
13
|
- Canonical fixtures: `SUPERUSER`, `USER`, `SERVICE` `Auth` payloads.
|
|
14
|
+
|
|
15
|
+
<!-- owlmeans:agent-guidance:start -->
|
|
16
|
+
## Agent guidance
|
|
17
|
+
|
|
18
|
+
This package ships embedded Claude Code skills and GitHub Copilot instructions under
|
|
19
|
+
`agent-meta/`. After installing your `@owlmeans/*` packages, run the OwlMeans
|
|
20
|
+
agent-skills installer to place them into your project's native locations
|
|
21
|
+
(`.claude/skills/` and `.github/instructions/`):
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
npx @owlmeans/agent-skills
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The embedded files are version-matched to this package release. Do not edit them
|
|
28
|
+
directly — they are regenerated on each publish. To contribute guidance edits,
|
|
29
|
+
open a PR against the source monorepo.
|
|
30
|
+
<!-- owlmeans:agent-guidance:end -->
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/*.test.ts, **/*.spec.ts, **/*.ts"
|
|
3
|
+
---
|
|
4
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
5
|
+
|
|
6
|
+
# Category B — Auth Unit Tests
|
|
7
|
+
|
|
8
|
+
- Tests in `<your-package>/tests/*.spec.ts`. Use `bun:test`.
|
|
9
|
+
- The **only** mocks allowed: `@owlmeans/test-auth` helpers (`makeFixtureKeyPair`, `makeMemoryTrustedResource`, `makeMockGuard`, `withAuth`, `signMockEnvelope`, `makeBearer`).
|
|
10
|
+
- Never roll a new auth mock in a per-package `tests/`. Add it to `@owlmeans/test-auth` and update its skill instead.
|
|
11
|
+
- Use deterministic seeds: `makeFixtureKeyPair('alice')` keeps signatures stable.
|
|
12
|
+
- Cover `.claude/skills/<pkg>/SKILL.md` and `README.md` cases first.
|
|
13
|
+
- Max 3-4 tests per method/function.
|
|
14
|
+
- Don't test utils, types, or context plumbing.
|
|
15
|
+
- Per-package `package.json` script: `"test": "bun test ./tests"`.
|
|
16
|
+
|
|
17
|
+
For the protocol reference (Ed25519 path, OIDC path, types, errors, mocking points), see `.claude/skills/auth-protocol/SKILL.md`. For helper specifics, see `.claude/skills/testing-auth-unit/SKILL.md`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"package": "@owlmeans/test-auth",
|
|
4
|
+
"version": "0.1.8",
|
|
5
|
+
"generatedAt": "2026-06-11T16:30:27.163Z",
|
|
6
|
+
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
|
+
"entries": [
|
|
8
|
+
{
|
|
9
|
+
"kind": "skill",
|
|
10
|
+
"name": "testing-auth-unit",
|
|
11
|
+
"category": "package-specific",
|
|
12
|
+
"file": "skills/testing-auth-unit/SKILL.md",
|
|
13
|
+
"canonicalPath": ".claude/skills/testing-auth-unit/SKILL.md"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"kind": "instruction",
|
|
17
|
+
"name": "testing-auth-unit",
|
|
18
|
+
"category": "package-specific",
|
|
19
|
+
"file": "instructions/testing-auth-unit.instructions.md",
|
|
20
|
+
"canonicalPath": ".github/instructions/testing-auth-unit.instructions.md"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: testing-auth-unit
|
|
3
|
+
description: Category-B unit tests for OwlMeans Common — auth/authz packages where the test substitutes a fake authenticated identity via @owlmeans/test-auth. Auto-invoked when writing tests in auth, auth-common, basic-keys, basic-envelope, did, client-auth, client-did, server-auth, oidc, server-oidc-*, web-oidc-*, wled, client-payment.
|
|
4
|
+
---
|
|
5
|
+
<!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
|
|
6
|
+
|
|
7
|
+
# Auth Unit Tests — Category B
|
|
8
|
+
|
|
9
|
+
Category B applies to the auth/authz packages: `auth`, `auth-common`, `basic-keys`, `basic-envelope`, `did`, `client-auth`, `client-did`, `server-auth`, `oidc`, `server-oidc-rp`, `server-oidc-provider`, `web-oidc-rp`, `web-oidc-provider`, `wled`, `client-payment`. These tests run under `bun test` (no Playwright even when there are React bits) and are the **only** place mocks are allowed — and only for authentication/authorization, via `@owlmeans/test-auth`.
|
|
10
|
+
|
|
11
|
+
For background on the protocol you're mocking, read the `auth-protocol` skill.
|
|
12
|
+
|
|
13
|
+
## Helpers from `@owlmeans/test-auth`
|
|
14
|
+
|
|
15
|
+
| Helper | Purpose |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `makeFixtureKeyPair(seed?)` | Deterministic Ed25519 `KeyPairModel`. Same seed → same keys. |
|
|
18
|
+
| `makeMemoryTrustedResource(records?)` | `Resource<TrustedRecord>` that satisfies `trust()` lookups. |
|
|
19
|
+
| `makeMockGuard({ alias?, auth?, allow? })` | `GuardService` resolving to a chosen `Auth`. |
|
|
20
|
+
| `withAuth(ctx, auth)` | Registers a mock guard on `ctx` that resolves to `auth`. |
|
|
21
|
+
| `signMockEnvelope(msg, type, kind?, kp?)` | Wraps `makeEnvelopeModel` with a fixture keypair. |
|
|
22
|
+
| `makeBearer(auth, kp?)` | Produces an `ED25519-BASIC-TOKEN <encoded>` header. |
|
|
23
|
+
| `SUPERUSER`, `USER`, `SERVICE` | Canonical `Auth` payload fixtures. |
|
|
24
|
+
|
|
25
|
+
## `tests/context.ts` pattern
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { AppType, Layer, makeBasicContext } from '@owlmeans/context'
|
|
29
|
+
import { makeMemoryTrustedResource, withAuth, USER } from '@owlmeans/test-auth'
|
|
30
|
+
|
|
31
|
+
export const makeTestCtx = () => {
|
|
32
|
+
const ctx = makeBasicContext({
|
|
33
|
+
ready: false, service: '<pkg>-tests', layer: Layer.Service, type: AppType.Backend,
|
|
34
|
+
})
|
|
35
|
+
ctx.registerResource(makeMemoryTrustedResource([
|
|
36
|
+
{ id: 'svc', name: 'svc', credential: '<fixture-pubkey>' },
|
|
37
|
+
]))
|
|
38
|
+
withAuth(ctx, USER) // register a mock guard resolving to USER
|
|
39
|
+
return ctx
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The trusted resource, mock guard, and any fixture keys are the **only** mocks allowed. Everything else (the service under test, sibling packages it depends on) is the real thing.
|
|
44
|
+
|
|
45
|
+
## Spec shape
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { describe, expect, test } from 'bun:test'
|
|
49
|
+
import { makeFixtureKeyPair } from '@owlmeans/test-auth'
|
|
50
|
+
import { packAuthCredentials, unpackAuthCredentials } from '@owlmeans/basic-keys'
|
|
51
|
+
|
|
52
|
+
const key = makeFixtureKeyPair('alice')
|
|
53
|
+
|
|
54
|
+
describe('@owlmeans/basic-keys — packAuthCredentials', () => {
|
|
55
|
+
test('round-trips a signed credential', async () => {
|
|
56
|
+
const signed = await packAuthCredentials(/* … */, undefined, key)
|
|
57
|
+
const result = await unpackAuthCredentials(signed, key)
|
|
58
|
+
expect(result.isValid).toBe(true)
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Rules
|
|
64
|
+
|
|
65
|
+
- **Mocks only for auth/authz.** No mocks for databases, network, or any sibling package. If you need one, move the spec to category C and write an integration test.
|
|
66
|
+
- **Don't replicate `@owlmeans/test-auth` helpers in your package.** If you need a new mocking primitive (e.g. an OIDC userinfo endpoint stub), add it to `@owlmeans/test-auth` and its skill — never to a per-package `tests/`.
|
|
67
|
+
- **Use deterministic seeds.** `makeFixtureKeyPair('<seed>')` keeps signatures stable run-to-run; random keypairs break snapshot-style assertions.
|
|
68
|
+
- **Cover SKILL.md cases first.** The package's `.claude/skills/<pkg>/SKILL.md` documents the consumer-facing surface — that's the test priority order.
|
|
69
|
+
- **Max 3-4 tests per method/function.** Same as category A.
|
|
70
|
+
- **Don't test types or utils.**
|
|
71
|
+
|
|
72
|
+
## When you actually want OIDC end-to-end
|
|
73
|
+
|
|
74
|
+
The current `@owlmeans/test-auth` does not ship a fake JWKS server. Use the real `makeOidcGuard` against the in-memory trusted resource and a fixture keypair. If a future test needs a hostable IdP fake, add it to `@owlmeans/test-auth` and document it here — don't bolt it on per package.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/test-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@owlmeans/auth": "^0.1.
|
|
25
|
-
"@owlmeans/auth-common": "^0.1.
|
|
26
|
-
"@owlmeans/basic-envelope": "^0.1.
|
|
27
|
-
"@owlmeans/basic-keys": "^0.1.
|
|
28
|
-
"@owlmeans/context": "^0.1.
|
|
29
|
-
"@owlmeans/entrypoint": "^0.1.
|
|
30
|
-
"@owlmeans/resource": "^0.1.
|
|
31
|
-
"@owlmeans/test": "^0.1.
|
|
24
|
+
"@owlmeans/auth": "^0.1.8",
|
|
25
|
+
"@owlmeans/auth-common": "^0.1.8",
|
|
26
|
+
"@owlmeans/basic-envelope": "^0.1.8",
|
|
27
|
+
"@owlmeans/basic-keys": "^0.1.8",
|
|
28
|
+
"@owlmeans/context": "^0.1.8",
|
|
29
|
+
"@owlmeans/entrypoint": "^0.1.8",
|
|
30
|
+
"@owlmeans/resource": "^0.1.8",
|
|
31
|
+
"@owlmeans/test": "^0.1.8"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@owlmeans/dep-config": "workspace:*",
|