diff --git a/packages/core/auth/src/__tests__/middleware.test.ts b/packages/core/auth/src/__tests__/middleware.test.ts index 9cd086d70d..214b11aba2 100644 --- a/packages/core/auth/src/__tests__/middleware.test.ts +++ b/packages/core/auth/src/__tests__/middleware.test.ts @@ -38,7 +38,7 @@ describe('middleware', () => { const hasFn = vi.fn(); const addFn = vi.fn(); beforeEach(async () => { - await agent.loginWithJti(1); + await agent.login(1); app.authManager.setTokenBlacklistService({ has: hasFn, add: addFn, diff --git a/packages/core/test/src/server/mock-server.ts b/packages/core/test/src/server/mock-server.ts index f78333edbe..e9fb9def39 100644 --- a/packages/core/test/src/server/mock-server.ts +++ b/packages/core/test/src/server/mock-server.ts @@ -74,9 +74,8 @@ interface Resource { } interface ExtendedAgent extends SuperAgentTest { - login: (user: any, roleName?: string) => ExtendedAgent; - loginUsingId: (userId: number, roleName?: string) => ExtendedAgent; - loginWithJti: (user: any, roleName?: string) => Promise; + login: (user: any, roleName?: string) => Promise; + loginUsingId: (userId: number, roleName?: string) => Promise; resource: (name: string, resourceOf?: any) => Resource; } @@ -129,27 +128,6 @@ export class MockServer extends Application { const proxy = new Proxy(agent, { get(target, method: string, receiver) { if (['login', 'loginUsingId'].includes(method)) { - return (userOrId: any, roleName?: string) => { - return proxy - .auth( - jwt.sign( - { - userId: typeof userOrId === 'number' ? userOrId : userOrId?.id, - temp: true, - roleName, - signInTime: Date.now(), - }, - process.env.APP_KEY, - { - expiresIn: '1d', - }, - ), - { type: 'bearer' }, - ) - .set('X-Authenticator', 'basic'); - }; - } - if (method === 'loginWithJti') { return async (userOrId: any, roleName?: string) => { const userId = typeof userOrId === 'number' ? userOrId : userOrId?.id; const tokenInfo = await authManager.tokenController.add({ userId }); diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/acl.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/acl.test.ts index 8a173e701f..09858b4868 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/acl.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/acl.test.ts @@ -42,7 +42,7 @@ describe('acl', () => { }, }); - adminAgent = await app.agent().loginWithJti(admin); + adminAgent = await app.agent().login(admin); uiSchemaRepository = db.getRepository('uiSchemas'); }); @@ -126,7 +126,7 @@ describe('acl', () => { userPlugin = app.getPlugin('users') as UsersPlugin; - const testAgent = await app.agent().loginWithJti(u1); + const testAgent = await app.agent().login(u1); // @ts-ignore const response1 = await testAgent.resource('repairs').list({ @@ -247,7 +247,7 @@ describe('acl', () => { }); const userPlugin = app.getPlugin('users') as UsersPlugin; - const adminAgent = await app.agent().loginWithJti(rootUser); + const adminAgent = await app.agent().login(rootUser); expect(await db.getCollection('roles').repository.count()).toBe(3); @@ -802,7 +802,7 @@ describe('acl', () => { }, }); - const userAgent = await app.agent().loginWithJti(user); + const userAgent = await app.agent().login(user); const schema = { 'x-uid': 'test', @@ -864,7 +864,7 @@ describe('acl', () => { filterByTk: 1, }); - const rootAgent = await app.agent().loginWithJti(rootUser); + const rootAgent = await app.agent().login(rootUser); const response = await rootAgent // @ts-ignore diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/actions.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/actions.test.ts index 3646e79934..e56725cdd9 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/actions.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/actions.test.ts @@ -138,7 +138,7 @@ describe('destroy action with acl', () => { const a1 = await A.repository.findOne({ filter: { title: 'a1' } }); - const response = await (await await app.agent().loginWithJti(1)).resource('a.bs', a1.get('id')).list(); + const response = await (await app.agent().login(1)).resource('a.bs', a1.get('id')).list(); expect(response.statusCode).toEqual(200); }); @@ -173,13 +173,9 @@ describe('destroy action with acl', () => { }, ); - const response = await app - .agent() - .login(1) - .resource('posts') - .destroy({ - filterByTk: p1.get('id'), - }); + const response = await (await app.agent().login(1)).resource('posts').destroy({ + filterByTk: p1.get('id'), + }); // should throw errors expect(response.statusCode).toEqual(403); diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/association-field.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/association-field.test.ts index afef088d18..d81d5ab5b4 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/association-field.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/association-field.test.ts @@ -114,7 +114,7 @@ describe('association test', () => { }, }); - const userAgent = await app.agent().loginWithJti(user); + const userAgent = await app.agent().login(user); const postCommentsResp = await userAgent.resource('posts.userComments', post.get('id')).list({}); expect(postCommentsResp.statusCode).toEqual(200); @@ -168,9 +168,9 @@ describe.skip('association field acl', () => { }); const userPlugin = app.getPlugin('users') as UsersPlugin; - userAgent = await app.agent().loginWithJti(user); + userAgent = await app.agent().login(user); - adminAgent = await app.agent().loginWithJti(admin); + adminAgent = await app.agent().login(admin); await db.getRepository('collections').create({ values: { diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/configuration.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/configuration.test.ts index d4436412c9..ffe64e5332 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/configuration.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/configuration.test.ts @@ -55,9 +55,9 @@ describe('configuration', () => { }); const userPlugin = app.getPlugin('users') as UsersPlugin; - adminAgent = await app.agent().loginWithJti(admin); + adminAgent = await app.agent().login(admin); - userAgent = await app.agent().loginWithJti(user); + userAgent = await app.agent().login(user); guestAgent = app.agent(); }); diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/get-action.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/get-action.test.ts index cbf35aa67c..eaa6a62a22 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/get-action.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/get-action.test.ts @@ -24,7 +24,7 @@ describe('get action with acl', () => { const users = await UserRepo.create({ values: [{ nickname: 'a', roles: [{ name: 'test' }] }], }); - userAgent = await app.agent().loginWithJti(users[0]); + userAgent = await app.agent().login(users[0]); Post = app.db.collection({ name: 'posts', diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/list-action.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/list-action.test.ts index 7ef7930c39..8c34b7cd66 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/list-action.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/list-action.test.ts @@ -30,7 +30,7 @@ describe('list action with acl', () => { { id: 3, nickname: 'a', roles: [{ name: 'user' }] }, ], }); - userAgent = await app.agent().loginWithJti(users[0], 'user'); + userAgent = await app.agent().login(users[0], 'user'); Post = app.db.collection({ name: 'posts', @@ -220,7 +220,7 @@ describe('list action with acl', () => { // ); // @ts-ignore - const response = await (await app.agent().loginWithJti(users[0].id, 'user')) + const response = await (await app.agent().login(users[0].id, 'user')) .set('X-With-ACL-Meta', true) .resource('posts') .list(); @@ -391,7 +391,7 @@ describe('list association action with acl', () => { }, }); - const userAgent = await (await app.agent().loginWithJti(user, 'newRole')).set('X-With-ACL-Meta', true); + const userAgent = await (await app.agent().login(user, 'newRole')).set('X-With-ACL-Meta', true); const createResp = await userAgent.resource('posts').create({ values: { diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/middleware.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/middleware.test.ts index c3bc4f60d6..9975d2a004 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/middleware.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/middleware.test.ts @@ -47,8 +47,8 @@ describe('middleware', () => { }); const userPlugin = app.getPlugin('users') as UsersPlugin; - adminAgent = await app.agent().loginWithJti(admin); - memberAgent = await app.agent().loginWithJti(member); + adminAgent = await app.agent().login(admin); + memberAgent = await app.agent().login(member); await db.getRepository('collections').create({ values: { @@ -135,7 +135,7 @@ describe('middleware', () => { }, }, }); - const response = await (await app.agent().loginWithJti(member)).resource('posts').create({ + const response = await (await app.agent().login(member)).resource('posts').create({ values: {}, }); diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/own.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/own.test.ts index 88dcce31b7..3977609d17 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/own.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/own.test.ts @@ -77,7 +77,7 @@ describe('own test', () => { pluginUser = app.getPlugin('users'); - adminAgent = await app.agent().loginWithJti(admin); + adminAgent = await app.agent().login(admin); user = await db.getRepository('users').create({ values: { @@ -86,7 +86,7 @@ describe('own test', () => { }, }); - userAgent = await app.agent().loginWithJti(user); + userAgent = await app.agent().login(user); }); it('should list without createBy', async () => { diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role-check.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role-check.test.ts index da2e644104..300b6ae2f0 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role-check.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role-check.test.ts @@ -44,7 +44,7 @@ describe('role check action', () => { }, }); - const agent = await app.agent().loginWithJti(user); + const agent = await app.agent().login(user); // @ts-ignore const response = await agent.resource('roles').check(); @@ -92,7 +92,7 @@ describe('role check action', () => { }, }); - const agent: any = await app.agent().loginWithJti(user); + const agent: any = await app.agent().login(user); const checkResp1 = await agent.resource('roles').check(); const actions = checkResp1.body.data.actions; diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role-resource.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role-resource.test.ts index e91a2ed509..e47cd95adc 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role-resource.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role-resource.test.ts @@ -42,7 +42,7 @@ describe('role resource api', () => { }); const userPlugin = app.getPlugin('users') as UsersPlugin; - adminAgent = await app.agent().loginWithJti(admin); + adminAgent = await app.agent().login(admin); }); it('should grant resource by createRepository', async () => { diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role.test.ts index c25bf53ea4..8c0a48a817 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/role.test.ts @@ -45,7 +45,7 @@ describe('role api', () => { }); const userPlugin = app.getPlugin('users') as UsersPlugin; - adminAgent = await app.agent().loginWithJti(admin); + adminAgent = await app.agent().login(admin); }); it('should have permission to users collection with strategy', async () => { @@ -64,7 +64,7 @@ describe('role api', () => { }, }); - const userAgent = await app.agent().loginWithJti(user1); + const userAgent = await app.agent().login(user1); const response = await userAgent.resource('users').list(); expect(response.statusCode).toBe(200); diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/scope.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/scope.test.ts index c919b96aed..3be79faa7a 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/scope.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/scope.test.ts @@ -35,7 +35,7 @@ describe('scope api', () => { }); const userPlugin = app.getPlugin('users') as UsersPlugin; - adminAgent = await app.agent().loginWithJti(admin); + adminAgent = await app.agent().login(admin); }); it('should create scope of resource', async () => { diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/snippets.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/snippets.test.ts index 2b6eb3f27c..4e1db0309f 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/snippets.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/snippets.test.ts @@ -36,7 +36,7 @@ describe('snippet', () => { }); const userPlugin: any = app.getPlugin('users'); - const userAgent: any = await app.agent().loginWithJti(user); + const userAgent: any = await app.agent().login(user); const createCollectionResponse = await userAgent.resource('collections').create({}); expect(createCollectionResponse.statusCode).toEqual(403); @@ -57,7 +57,7 @@ describe('snippet', () => { }, }); - const userAgent: any = await app.agent().loginWithJti(testUser); + const userAgent: any = await app.agent().login(testUser); const listResp = await userAgent.resource('users').list(); @@ -79,7 +79,7 @@ describe('snippet', () => { }, }); - const userAgent: any = await app.agent().loginWithJti(testUser); + const userAgent: any = await app.agent().login(testUser); const getResp = await userAgent.resource('dataSources.roles', 'main').get({ filterByTk: 'testRole', @@ -110,7 +110,7 @@ describe('snippet', () => { }, }); - const userAgent: any = await app.agent().loginWithJti(testUser); + const userAgent: any = await app.agent().login(testUser); const getResp = await userAgent.resource('roles.dataSourcesCollections', 'testRole').list({ filter: { diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/users.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/users.test.ts index 5b09d27aaf..84b888e89d 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/users.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/users.test.ts @@ -36,7 +36,7 @@ describe('actions', () => { }); agent = app.agent(); - adminAgent = await app.agent().loginWithJti(adminUser); + adminAgent = await app.agent().login(adminUser); }); afterEach(async () => { @@ -166,7 +166,7 @@ describe('actions', () => { }); // list with user - const userAgent: any = (await app.agent().loginWithJti(testUser)).set('x-role', 'testRole'); + const userAgent: any = (await app.agent().login(testUser)).set('x-role', 'testRole'); const listResp = await userAgent.resource('items').list({}); expect(listResp.status).toBe(200); diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/validate-filter-params.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/validate-filter-params.test.ts index 0214d8dce2..96265de687 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/validate-filter-params.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/validate-filter-params.test.ts @@ -41,7 +41,7 @@ describe('acl', () => { }, }); - adminAgent = await app.agent().loginWithJti(admin); + adminAgent = await app.agent().login(admin); uiSchemaRepository = db.getRepository('uiSchemas'); await db.getRepository('collections').create({ context: {}, diff --git a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/write-role-to-acl.test.ts b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/write-role-to-acl.test.ts index 37dac1cf5f..d3db1b6e50 100644 --- a/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/write-role-to-acl.test.ts +++ b/packages/plugins/@nocobase/plugin-acl/src/server/__tests__/write-role-to-acl.test.ts @@ -40,7 +40,7 @@ describe('write role to acl', () => { }, }); - const agent = await app.agent().loginWithJti(user); + const agent = await app.agent().login(user); // @ts-ignore const response = await agent.resource('roles').check(); diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/actions.test.ts b/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/actions.test.ts index fb087db444..a8ac281cdc 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/actions.test.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/actions.test.ts @@ -222,7 +222,7 @@ describe('actions', () => { password: '12345', }, }); - const userAgent = await agent.loginWithJti(user, null); + const userAgent = await agent.login(user, null); // Should check password consistency const res = await userAgent.post('/auth:changePassword').set({ 'X-Authenticator': 'basic' }).send({ @@ -256,7 +256,7 @@ describe('actions', () => { password: '12345', }, }); - const res3 = await (await agent.loginWithJti(user1)) + const res3 = await (await agent.login(user1)) .post('/auth:changePassword') .set({ 'X-Authenticator': 'basic' }) .send({ @@ -281,7 +281,7 @@ describe('actions', () => { password: '12345', }, }); - const userAgent = await agent.loginWithJti(user); + const userAgent = await agent.login(user); const res = await userAgent.post('/auth:changePassword').set({ 'X-Authenticator': 'basic' }).send({ oldPassword: '12345', @@ -445,7 +445,7 @@ describe('actions', () => { password: '12345', }, }); - const userAgent = await agent.loginWithJti(user, null); + const userAgent = await agent.login(user, null); const res = await userAgent.post('/auth:check').set({ 'X-Authenticator': 'basic' }).send(); expect(res.statusCode).toEqual(200); expect(res.body.data.id).toBeDefined(); diff --git a/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/token-policy-settings.test.ts b/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/token-policy-settings.test.ts index b14848dd6b..4b2d3ac62c 100644 --- a/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/token-policy-settings.test.ts +++ b/packages/plugins/@nocobase/plugin-auth/src/server/__tests__/token-policy-settings.test.ts @@ -80,7 +80,7 @@ describe('auth', () => { username: 'admin', }, }); - adminAgent = await app.agent().loginWithJti(user, 'admin'); + adminAgent = await app.agent().login(user, 'admin'); class MockBaseAuth extends BaseAuth { async validate() { diff --git a/packages/plugins/@nocobase/plugin-backup-restore/src/server/__tests__/api.test.ts b/packages/plugins/@nocobase/plugin-backup-restore/src/server/__tests__/api.test.ts index 5170249eed..55188290d1 100644 --- a/packages/plugins/@nocobase/plugin-backup-restore/src/server/__tests__/api.test.ts +++ b/packages/plugins/@nocobase/plugin-backup-restore/src/server/__tests__/api.test.ts @@ -16,7 +16,7 @@ describe('backup files', () => { beforeEach(async () => { app = await createApp(); - adminAgent = await app.agent().loginWithJti(1); + adminAgent = await app.agent().login(1); }); afterEach(async () => { diff --git a/packages/plugins/@nocobase/plugin-collection-tree/src/server/__tests__/tree.test.ts b/packages/plugins/@nocobase/plugin-collection-tree/src/server/__tests__/tree.test.ts index 24c82bb28e..4e8c623365 100644 --- a/packages/plugins/@nocobase/plugin-collection-tree/src/server/__tests__/tree.test.ts +++ b/packages/plugins/@nocobase/plugin-collection-tree/src/server/__tests__/tree.test.ts @@ -42,7 +42,7 @@ describe('tree', () => { }); const userPlugin = app.getPlugin('users'); - const agent = await app.agent().loginWithJti(user); + const agent = await app.agent().login(user); agent.set('X-With-ACL-Meta', 'true'); app.acl.allow('table_a', ['*']); app.acl.allow('collections', ['*']); diff --git a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/__tests__/data-source-with-acl.test.ts b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/__tests__/data-source-with-acl.test.ts index 04cb6af219..d552a41ee6 100644 --- a/packages/plugins/@nocobase/plugin-data-source-manager/src/server/__tests__/data-source-with-acl.test.ts +++ b/packages/plugins/@nocobase/plugin-data-source-manager/src/server/__tests__/data-source-with-acl.test.ts @@ -117,7 +117,7 @@ describe('data source with acl', () => { }, }); - const adminAgent: any = (await app.agent().loginWithJti(adminUser)).set('x-data-source', 'mockInstance1'); + const adminAgent: any = (await app.agent().login(adminUser)).set('x-data-source', 'mockInstance1'); const listRes = await adminAgent.resource('api/posts').list(); expect(listRes.status).toBe(200); expect(middlewareFn).toBeCalledTimes(1); @@ -130,7 +130,7 @@ describe('data source with acl', () => { }, }); - const adminAgent: any = (await app.agent().loginWithJti(adminUser)).set('x-data-source', 'mockInstance1'); + const adminAgent: any = (await app.agent().login(adminUser)).set('x-data-source', 'mockInstance1'); const postRes = await adminAgent.resource('api/posts').list({}); expect(postRes.status).toBe(200); }); @@ -142,7 +142,7 @@ describe('data source with acl', () => { }, }); - const adminAgent: any = await app.agent().loginWithJti(adminUser); + const adminAgent: any = await app.agent().login(adminUser); await adminAgent.resource('dataSources.roles', 'mockInstance1').update({ filterByTk: 'member', @@ -195,9 +195,9 @@ describe('data source with acl', () => { context: {}, }); - const adminAgent: any = await app.agent().loginWithJti(adminUser); + const adminAgent: any = await app.agent().login(adminUser); - const testUserAgent: any = await app.agent().loginWithJti(testUser); + const testUserAgent: any = await app.agent().login(testUser); const listRes = await testUserAgent.resource('posts').list({}); expect(listRes.status).toBe(403); @@ -251,10 +251,10 @@ describe('data source with acl', () => { }, }); - const adminAgent: any = await app.agent().loginWithJti(adminUser); + const adminAgent: any = await app.agent().login(adminUser); // should get permission error - const testAgent = await app.agent().loginWithJti(testUser); + const testAgent = await app.agent().login(testUser); const testUserAgent = getDataSourceAgent(testAgent, 'mockInstance1'); // @ts-ignore @@ -313,10 +313,10 @@ describe('data source with acl', () => { }, }); - const adminAgent: any = await app.agent().loginWithJti(adminUser); + const adminAgent: any = await app.agent().login(adminUser); // should get permission error - const testUserAgent = getDataSourceAgent(await app.agent().loginWithJti(testUser), 'mockInstance1'); + const testUserAgent = getDataSourceAgent(await app.agent().login(testUser), 'mockInstance1'); const createResourceResp = await adminAgent.resource('dataSources.rolesResourcesScopes', 'mockInstance1').create({ values: { @@ -402,7 +402,7 @@ describe('data source with acl', () => { // call roles check // @ts-ignore - const checkRep = await (await app.agent().loginWithJti(testUser)).resource('roles').check({}); + const checkRep = await (await app.agent().login(testUser)).resource('roles').check({}); expect(checkRep.status).toBe(200); const checkData = checkRep.body; @@ -419,21 +419,17 @@ describe('data source with acl', () => { }); // update strategy - const updateRes = await app - .agent() - .login(adminUser) - .resource('dataSources.roles', 'main') - .update({ - filterByTk: 'admin', - values: { - strategy: { - actions: [], - }, + const updateRes = await (await app.agent().login(adminUser)).resource('dataSources.roles', 'main').update({ + filterByTk: 'admin', + values: { + strategy: { + actions: [], }, - }); + }, + }); // get role - const adminRoleResp = await (await app.agent().loginWithJti(adminUser)).resource('dataSources.roles', 'main').get({ + const adminRoleResp = await (await app.agent().login(adminUser)).resource('dataSources.roles', 'main').get({ filterByTk: 'admin', }); @@ -441,20 +437,16 @@ describe('data source with acl', () => { expect(data.data.strategy.actions).toHaveLength(0); // update role - const updateRoleRes = await app - .agent() - .login(adminUser) - .resource('roles') - .update({ - filterByTk: 'admin', - values: { - snippets: ['pm.*'], - }, - }); + const updateRoleRes = await (await app.agent().login(adminUser)).resource('roles').update({ + filterByTk: 'admin', + values: { + snippets: ['pm.*'], + }, + }); expect(updateRoleRes.status).toBe(200); - const adminRoleResp2 = await (await app.agent().loginWithJti(adminUser)).resource('dataSources.roles', 'main').get({ + const adminRoleResp2 = await (await app.agent().login(adminUser)).resource('dataSources.roles', 'main').get({ filterByTk: 'admin', }); diff --git a/packages/plugins/@nocobase/plugin-data-visualization/src/server/__tests__/external-data-source.test.ts b/packages/plugins/@nocobase/plugin-data-visualization/src/server/__tests__/external-data-source.test.ts index 64188cd2b2..a5fdc75a4a 100644 --- a/packages/plugins/@nocobase/plugin-data-visualization/src/server/__tests__/external-data-source.test.ts +++ b/packages/plugins/@nocobase/plugin-data-visualization/src/server/__tests__/external-data-source.test.ts @@ -19,7 +19,7 @@ describe('external data source', () => { beforeAll(async () => { process.env.INIT_ROOT_USERNAME = 'test'; app = await createMockServer({ - plugins: ['field-sort', 'data-source-manager', 'users', 'acl'], + plugins: ['field-sort', 'data-source-manager', 'users', 'acl', 'auth'], }); db = app.db; ctx = { @@ -40,7 +40,7 @@ describe('external data source', () => { username: process.env.INIT_ROOT_USERNAME, }, }); - adminAgent = app.agent().login(adminUser); + adminAgent = await app.agent().login(adminUser); }); it('should check permission for external data source', async () => { diff --git a/packages/plugins/@nocobase/plugin-notification-in-app-message/src/server/__tests__/server.test.ts b/packages/plugins/@nocobase/plugin-notification-in-app-message/src/server/__tests__/server.test.ts index 48882a2806..2336d105d7 100644 --- a/packages/plugins/@nocobase/plugin-notification-in-app-message/src/server/__tests__/server.test.ts +++ b/packages/plugins/@nocobase/plugin-notification-in-app-message/src/server/__tests__/server.test.ts @@ -43,7 +43,7 @@ describe('inapp message channels', () => { ], }); - userAgents = await Promise.all(users.map((user) => app.agent().loginWithJti(user))); + userAgents = await Promise.all(users.map((user) => app.agent().login(user))); currUserAgent = userAgents[0]; currUserId = users[0].id; }); diff --git a/packages/plugins/@nocobase/plugin-theme-editor/src/server/__tests__/actions.test.ts b/packages/plugins/@nocobase/plugin-theme-editor/src/server/__tests__/actions.test.ts index b0a6667bed..2c114d409b 100644 --- a/packages/plugins/@nocobase/plugin-theme-editor/src/server/__tests__/actions.test.ts +++ b/packages/plugins/@nocobase/plugin-theme-editor/src/server/__tests__/actions.test.ts @@ -33,7 +33,7 @@ describe('actions', () => { }); agent = app.agent(); - adminAgent = await app.agent().loginWithJti(adminUser); + adminAgent = await app.agent().login(adminUser); }); afterEach(async () => { diff --git a/packages/plugins/@nocobase/plugin-users/src/server/__tests__/actions.test.ts b/packages/plugins/@nocobase/plugin-users/src/server/__tests__/actions.test.ts index 57721cca50..ccb1091425 100644 --- a/packages/plugins/@nocobase/plugin-users/src/server/__tests__/actions.test.ts +++ b/packages/plugins/@nocobase/plugin-users/src/server/__tests__/actions.test.ts @@ -36,7 +36,7 @@ describe('actions', () => { }); agent = app.agent(); - adminAgent = await app.agent().loginWithJti(adminUser); + adminAgent = await app.agent().login(adminUser); }); afterEach(async () => { diff --git a/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/server/__tests__/trigger.test.ts b/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/server/__tests__/trigger.test.ts index 917a12181a..2573e03e6e 100644 --- a/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/server/__tests__/trigger.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-action-trigger/src/server/__tests__/trigger.test.ts @@ -42,7 +42,7 @@ describe('workflow > action-trigger', () => { UserRepo = db.getCollection('users').repository; root = await UserRepo.findOne({}); - rootAgent = await app.agent().loginWithJti(root); + rootAgent = await app.agent().login(root); users = await UserRepo.create({ values: [ @@ -51,7 +51,7 @@ describe('workflow > action-trigger', () => { ], }); - userAgents = await Promise.all(users.map((user) => app.agent().loginWithJti(user))); + userAgents = await Promise.all(users.map((user) => app.agent().login(user))); }); afterEach(() => app.destroy()); @@ -812,8 +812,9 @@ describe('workflow > action-trigger', () => { // values: { title: 't2' }, // triggerWorkflows: `${workflow.key}`, // }); - const res2 = await agent - .login(users[0]) + const res2 = await ( + await agent.login(users[0]) + ) .set('x-data-source', 'another') .post('/api/posts:create') .query({ triggerWorkflows: `${workflow.key}` }) diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/assignees.test.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/assignees.test.ts index ca986c1f33..a9fa2b3369 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/assignees.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/assignees.test.ts @@ -44,7 +44,7 @@ describe('workflow > instructions > manual > assignees', () => { { id: 3, nickname: 'b' }, ]); - userAgents = users.map((user) => app.agent().login(user)); + userAgents = await Promise.all(users.map((user) => app.agent().login(user))); workflow = await WorkflowModel.create({ enabled: true, diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/data-source.test.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/data-source.test.ts index 2831e8d333..6c7999cb3e 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/data-source.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/data-source.test.ts @@ -44,7 +44,7 @@ describe('workflow > instructions > manual', () => { { id: 3, nickname: 'b' }, ]); - userAgents = users.map((user) => app.agent().login(user)); + userAgents = await Promise.all(users.map((user) => app.agent().login(user))); workflow = await WorkflowModel.create({ enabled: true, diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/form.test.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/form.test.ts index c62deb20e5..8543c269bf 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/form.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/form.test.ts @@ -44,7 +44,7 @@ describe('workflow > instructions > manual', () => { { id: 3, nickname: 'b' }, ]); - userAgents = await Promise.all(users.map((user) => app.agent().loginWithJti(user))); + userAgents = await Promise.all(users.map((user) => app.agent().login(user))); workflow = await WorkflowModel.create({ enabled: true, diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/mode.test.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/mode.test.ts index b7060eeabd..3c08f95f7c 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/mode.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/__tests__/mode.test.ts @@ -44,7 +44,7 @@ describe('workflow > instructions > manual', () => { { id: 3, nickname: 'b' }, ]); - userAgents = await Promise.all(users.map((user) => app.agent().loginWithJti(user))); + userAgents = await Promise.all(users.map((user) => app.agent().login(user))); workflow = await WorkflowModel.create({ enabled: true, diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/executions.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/executions.test.ts index f5f3781a15..d676a93f44 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/executions.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/actions/executions.test.ts @@ -27,7 +27,7 @@ describe('workflow > actions > executions', () => { plugins: ['users', 'acl', 'auth', 'data-source-manager'], acl: true, }); - agent = app.agent().loginUsingId(1); + agent = await app.agent().loginUsingId(1); db = app.db; WorkflowModel = db.getCollection('workflows').model; PostRepo = db.getCollection('posts').repository; @@ -47,7 +47,7 @@ describe('workflow > actions > executions', () => { { id: 3, nickname: 'b' }, ], }); - userAgents = await Promise.all(users.map((user) => app.agent().loginWithJti(user))); + userAgents = await Promise.all(users.map((user) => app.agent().login(user))); }); afterEach(async () => await app.destroy()); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts index c78f211900..ac31803958 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/__tests__/triggers/collection.test.ts @@ -40,7 +40,7 @@ describe('workflow > triggers > collection', () => { TagRepo = db.getCollection('tags').repository; const user = await app.db.getRepository('users').findOne(); - agent = await app.agent().loginWithJti(user); + agent = await app.agent().login(user); }); afterEach(() => app.destroy());