@nocobase/test 1.6.0-alpha.14 → 1.6.0-alpha.16

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.
@@ -59,6 +59,7 @@ interface Resource {
59
59
  interface ExtendedAgent extends SuperAgentTest {
60
60
  login: (user: any, roleName?: string) => ExtendedAgent;
61
61
  loginUsingId: (userId: number, roleName?: string) => ExtendedAgent;
62
+ loginWithJti: (user: any, roleName?: string) => Promise<ExtendedAgent>;
62
63
  resource: (name: string, resourceOf?: any) => Resource;
63
64
  }
64
65
  export declare class MockServer extends Application {
@@ -59,6 +59,7 @@ interface Resource {
59
59
  interface ExtendedAgent extends SuperAgentTest {
60
60
  login: (user: any, roleName?: string) => ExtendedAgent;
61
61
  loginUsingId: (userId: number, roleName?: string) => ExtendedAgent;
62
+ loginWithJti: (user: any, roleName?: string) => Promise<ExtendedAgent>;
62
63
  resource: (name: string, resourceOf?: any) => Resource;
63
64
  }
64
65
  export declare class MockServer extends Application {
@@ -93,6 +93,7 @@ const _MockServer = class _MockServer extends import_server.Application {
93
93
  agent(callback) {
94
94
  const agent = import_supertest.default.agent(callback || this.callback());
95
95
  const prefix = this.resourcer.options.prefix;
96
+ const authManager = this.authManager;
96
97
  const proxy = new Proxy(agent, {
97
98
  get(target, method, receiver) {
98
99
  if (["login", "loginUsingId"].includes(method)) {
@@ -113,6 +114,29 @@ const _MockServer = class _MockServer extends import_server.Application {
113
114
  ).set("X-Authenticator", "basic");
114
115
  };
115
116
  }
117
+ if (method === "loginWithJti") {
118
+ return async (userOrId, roleName) => {
119
+ const userId = typeof userOrId === "number" ? userOrId : userOrId == null ? void 0 : userOrId.id;
120
+ const tokenInfo = await authManager.tokenController.add({ userId });
121
+ const expiresIn = (await authManager.tokenController.getConfig()).tokenExpirationTime;
122
+ return proxy.auth(
123
+ import_jsonwebtoken.default.sign(
124
+ {
125
+ userId,
126
+ temp: true,
127
+ roleName,
128
+ signInTime: Date.now()
129
+ },
130
+ import_node_process.default.env.APP_KEY,
131
+ {
132
+ jwtid: tokenInfo.jti,
133
+ expiresIn
134
+ }
135
+ ),
136
+ { type: "bearer" }
137
+ ).set("X-Authenticator", "basic");
138
+ };
139
+ }
116
140
  if (method === "resource") {
117
141
  return (name, resourceOf) => {
118
142
  const keys = name.split(".");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/test",
3
- "version": "1.6.0-alpha.14",
3
+ "version": "1.6.0-alpha.16",
4
4
  "main": "lib/index.js",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./lib/index.d.ts",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "@faker-js/faker": "8.1.0",
54
- "@nocobase/server": "1.6.0-alpha.14",
54
+ "@nocobase/server": "1.6.0-alpha.16",
55
55
  "@playwright/test": "^1.45.3",
56
56
  "@testing-library/jest-dom": "^6.4.2",
57
57
  "@testing-library/react": "^14.0.0",
@@ -76,5 +76,5 @@
76
76
  "vitest-dom": "^0.1.1",
77
77
  "ws": "^8.13.0"
78
78
  },
79
- "gitHead": "1bf7648d7cf62fadef4e31535b4907046a952b4a"
79
+ "gitHead": "08a58df92b68f7df5e93c5f7cf997b4e4fbc68b5"
80
80
  }