@adonis-agora/authkit-testing 0.3.0 → 0.4.0
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 +3 -4
- package/build/src/authenticator.d.ts +0 -3
- package/build/src/authenticator.js +0 -6
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -53,20 +53,19 @@ provides one locally with no external network. You can also reuse a single
|
|
|
53
53
|
keypair across tokens via `generateTestKeyPair()` + the `key` option, or get the
|
|
54
54
|
raw public JWKS object with `jwksFromKey(key)` / `testJwks(key)`.
|
|
55
55
|
|
|
56
|
-
### `fakeAuthenticator({ identity?, user
|
|
56
|
+
### `fakeAuthenticator({ identity?, user? })`
|
|
57
57
|
|
|
58
58
|
Object satisfying the client's `Authenticator` surface, for injecting into
|
|
59
|
-
`ctx.auth` in controller tests.
|
|
59
|
+
`ctx.auth` in controller tests. O AuthKit só autentica — autorização por role é
|
|
60
|
+
do `@adonis-agora/authz`, então o fake expõe só `hasGlobalRole` (roles do token).
|
|
60
61
|
|
|
61
62
|
```ts
|
|
62
63
|
import { fakeAuthenticator } from '@adonis-agora/authkit-testing'
|
|
63
64
|
|
|
64
65
|
const auth = fakeAuthenticator({
|
|
65
66
|
identity: createTestIdentity({ globalRoles: ['ADMIN'] }),
|
|
66
|
-
appRoles: ['editor'],
|
|
67
67
|
})
|
|
68
68
|
auth.hasGlobalRole('ADMIN') // true
|
|
69
|
-
await auth.hasAppRole('editor') // true
|
|
70
69
|
```
|
|
71
70
|
|
|
72
71
|
Pass `identity: null` to simulate an anonymous request.
|
|
@@ -9,7 +9,6 @@ export interface FakeAuthenticatorLike {
|
|
|
9
9
|
authenticate(): Promise<Identity>;
|
|
10
10
|
check(): Promise<boolean>;
|
|
11
11
|
hasGlobalRole(role: string): boolean;
|
|
12
|
-
hasAppRole(role: string): Promise<boolean>;
|
|
13
12
|
getUser(): Promise<unknown>;
|
|
14
13
|
}
|
|
15
14
|
export interface FakeAuthenticatorOptions {
|
|
@@ -17,8 +16,6 @@ export interface FakeAuthenticatorOptions {
|
|
|
17
16
|
identity?: Identity | null;
|
|
18
17
|
/** usuário de domínio retornado por `getUser()`. */
|
|
19
18
|
user?: unknown;
|
|
20
|
-
/** roles de app reconhecidas por `hasAppRole`. */
|
|
21
|
-
appRoles?: string[];
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
24
21
|
* Cria um objeto que satisfaz a superfície do `Authenticator` do client para
|
|
@@ -5,7 +5,6 @@ import { createTestIdentity } from './identity.js';
|
|
|
5
5
|
*/
|
|
6
6
|
export function fakeAuthenticator(options = {}) {
|
|
7
7
|
const identity = options.identity === undefined ? createTestIdentity() : options.identity;
|
|
8
|
-
const appRoles = options.appRoles ?? [];
|
|
9
8
|
const user = 'user' in options ? options.user : identity;
|
|
10
9
|
return {
|
|
11
10
|
async getIdentity() {
|
|
@@ -25,11 +24,6 @@ export function fakeAuthenticator(options = {}) {
|
|
|
25
24
|
hasGlobalRole(role) {
|
|
26
25
|
return identity?.globalRoles.includes(role) ?? false;
|
|
27
26
|
},
|
|
28
|
-
async hasAppRole(role) {
|
|
29
|
-
if (!identity)
|
|
30
|
-
return false;
|
|
31
|
-
return appRoles.includes(role);
|
|
32
|
-
},
|
|
33
27
|
async getUser() {
|
|
34
28
|
if (!identity)
|
|
35
29
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonis-agora/authkit-testing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Test helpers for apps built on AuthKit: mint real signed ID tokens with a local JWKS, fake authenticators and account stores, and build valid identities — so host apps can test auth flows without booting an IdP.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "dudousxd",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@poppinss/ts-exec": "1.4.4",
|
|
47
47
|
"@types/node": "25.9.1",
|
|
48
48
|
"typescript": "6.0.3",
|
|
49
|
-
"@adonis-agora/authkit-client": "0.
|
|
49
|
+
"@adonis-agora/authkit-client": "0.11.0"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsc",
|