mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
refactor(test): modify the test function login to be asynchronous and update the relevant test cases (#6181)
* refactor(test): modify the test function login to be asynchronous and update the relevant test cases
This commit is contained in:
parent
4561ad02ec
commit
feb9074e56
@ -38,7 +38,7 @@ describe('middleware', () => {
|
|||||||
const hasFn = vi.fn();
|
const hasFn = vi.fn();
|
||||||
const addFn = vi.fn();
|
const addFn = vi.fn();
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await agent.loginWithJti(1);
|
await agent.login(1);
|
||||||
app.authManager.setTokenBlacklistService({
|
app.authManager.setTokenBlacklistService({
|
||||||
has: hasFn,
|
has: hasFn,
|
||||||
add: addFn,
|
add: addFn,
|
||||||
|
@ -74,9 +74,8 @@ interface Resource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ExtendedAgent extends SuperAgentTest {
|
interface ExtendedAgent extends SuperAgentTest {
|
||||||
login: (user: any, roleName?: string) => ExtendedAgent;
|
login: (user: any, roleName?: string) => Promise<ExtendedAgent>;
|
||||||
loginUsingId: (userId: number, roleName?: string) => ExtendedAgent;
|
loginUsingId: (userId: number, roleName?: string) => Promise<ExtendedAgent>;
|
||||||
loginWithJti: (user: any, roleName?: string) => Promise<ExtendedAgent>;
|
|
||||||
resource: (name: string, resourceOf?: any) => Resource;
|
resource: (name: string, resourceOf?: any) => Resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,27 +128,6 @@ export class MockServer extends Application {
|
|||||||
const proxy = new Proxy(agent, {
|
const proxy = new Proxy(agent, {
|
||||||
get(target, method: string, receiver) {
|
get(target, method: string, receiver) {
|
||||||
if (['login', 'loginUsingId'].includes(method)) {
|
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) => {
|
return async (userOrId: any, roleName?: string) => {
|
||||||
const userId = typeof userOrId === 'number' ? userOrId : userOrId?.id;
|
const userId = typeof userOrId === 'number' ? userOrId : userOrId?.id;
|
||||||
const tokenInfo = await authManager.tokenController.add({ userId });
|
const tokenInfo = await authManager.tokenController.add({ userId });
|
||||||
|
@ -42,7 +42,7 @@ describe('acl', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
adminAgent = await app.agent().loginWithJti(admin);
|
adminAgent = await app.agent().login(admin);
|
||||||
uiSchemaRepository = db.getRepository('uiSchemas');
|
uiSchemaRepository = db.getRepository('uiSchemas');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ describe('acl', () => {
|
|||||||
|
|
||||||
userPlugin = app.getPlugin('users') as UsersPlugin;
|
userPlugin = app.getPlugin('users') as UsersPlugin;
|
||||||
|
|
||||||
const testAgent = await app.agent().loginWithJti(u1);
|
const testAgent = await app.agent().login(u1);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const response1 = await testAgent.resource('repairs').list({
|
const response1 = await testAgent.resource('repairs').list({
|
||||||
@ -247,7 +247,7 @@ describe('acl', () => {
|
|||||||
});
|
});
|
||||||
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
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);
|
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 = {
|
const schema = {
|
||||||
'x-uid': 'test',
|
'x-uid': 'test',
|
||||||
@ -864,7 +864,7 @@ describe('acl', () => {
|
|||||||
filterByTk: 1,
|
filterByTk: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
const rootAgent = await app.agent().loginWithJti(rootUser);
|
const rootAgent = await app.agent().login(rootUser);
|
||||||
|
|
||||||
const response = await rootAgent
|
const response = await rootAgent
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -138,7 +138,7 @@ describe('destroy action with acl', () => {
|
|||||||
|
|
||||||
const a1 = await A.repository.findOne({ filter: { title: 'a1' } });
|
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);
|
expect(response.statusCode).toEqual(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -173,13 +173,9 @@ describe('destroy action with acl', () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const response = await app
|
const response = await (await app.agent().login(1)).resource('posts').destroy({
|
||||||
.agent()
|
filterByTk: p1.get('id'),
|
||||||
.login(1)
|
});
|
||||||
.resource('posts')
|
|
||||||
.destroy({
|
|
||||||
filterByTk: p1.get('id'),
|
|
||||||
});
|
|
||||||
|
|
||||||
// should throw errors
|
// should throw errors
|
||||||
expect(response.statusCode).toEqual(403);
|
expect(response.statusCode).toEqual(403);
|
||||||
|
@ -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({});
|
const postCommentsResp = await userAgent.resource('posts.userComments', post.get('id')).list({});
|
||||||
expect(postCommentsResp.statusCode).toEqual(200);
|
expect(postCommentsResp.statusCode).toEqual(200);
|
||||||
@ -168,9 +168,9 @@ describe.skip('association field acl', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
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({
|
await db.getRepository('collections').create({
|
||||||
values: {
|
values: {
|
||||||
|
@ -55,9 +55,9 @@ describe('configuration', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
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();
|
guestAgent = app.agent();
|
||||||
});
|
});
|
||||||
|
@ -24,7 +24,7 @@ describe('get action with acl', () => {
|
|||||||
const users = await UserRepo.create({
|
const users = await UserRepo.create({
|
||||||
values: [{ nickname: 'a', roles: [{ name: 'test' }] }],
|
values: [{ nickname: 'a', roles: [{ name: 'test' }] }],
|
||||||
});
|
});
|
||||||
userAgent = await app.agent().loginWithJti(users[0]);
|
userAgent = await app.agent().login(users[0]);
|
||||||
|
|
||||||
Post = app.db.collection({
|
Post = app.db.collection({
|
||||||
name: 'posts',
|
name: 'posts',
|
||||||
|
@ -30,7 +30,7 @@ describe('list action with acl', () => {
|
|||||||
{ id: 3, nickname: 'a', roles: [{ name: 'user' }] },
|
{ 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({
|
Post = app.db.collection({
|
||||||
name: 'posts',
|
name: 'posts',
|
||||||
@ -220,7 +220,7 @@ describe('list action with acl', () => {
|
|||||||
// );
|
// );
|
||||||
|
|
||||||
// @ts-ignore
|
// @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)
|
.set('X-With-ACL-Meta', true)
|
||||||
.resource('posts')
|
.resource('posts')
|
||||||
.list();
|
.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({
|
const createResp = await userAgent.resource('posts').create({
|
||||||
values: {
|
values: {
|
||||||
|
@ -47,8 +47,8 @@ describe('middleware', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
||||||
adminAgent = await app.agent().loginWithJti(admin);
|
adminAgent = await app.agent().login(admin);
|
||||||
memberAgent = await app.agent().loginWithJti(member);
|
memberAgent = await app.agent().login(member);
|
||||||
|
|
||||||
await db.getRepository('collections').create({
|
await db.getRepository('collections').create({
|
||||||
values: {
|
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: {},
|
values: {},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ describe('own test', () => {
|
|||||||
|
|
||||||
pluginUser = app.getPlugin('users');
|
pluginUser = app.getPlugin('users');
|
||||||
|
|
||||||
adminAgent = await app.agent().loginWithJti(admin);
|
adminAgent = await app.agent().login(admin);
|
||||||
|
|
||||||
user = await db.getRepository('users').create({
|
user = await db.getRepository('users').create({
|
||||||
values: {
|
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 () => {
|
it('should list without createBy', async () => {
|
||||||
|
@ -44,7 +44,7 @@ describe('role check action', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const agent = await app.agent().loginWithJti(user);
|
const agent = await app.agent().login(user);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const response = await agent.resource('roles').check();
|
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 checkResp1 = await agent.resource('roles').check();
|
||||||
const actions = checkResp1.body.data.actions;
|
const actions = checkResp1.body.data.actions;
|
||||||
|
@ -42,7 +42,7 @@ describe('role resource api', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
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 () => {
|
it('should grant resource by createRepository', async () => {
|
||||||
|
@ -45,7 +45,7 @@ describe('role api', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
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 () => {
|
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();
|
const response = await userAgent.resource('users').list();
|
||||||
expect(response.statusCode).toBe(200);
|
expect(response.statusCode).toBe(200);
|
||||||
|
@ -35,7 +35,7 @@ describe('scope api', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userPlugin = app.getPlugin('users') as UsersPlugin;
|
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 () => {
|
it('should create scope of resource', async () => {
|
||||||
|
@ -36,7 +36,7 @@ describe('snippet', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userPlugin: any = app.getPlugin('users');
|
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({});
|
const createCollectionResponse = await userAgent.resource('collections').create({});
|
||||||
|
|
||||||
expect(createCollectionResponse.statusCode).toEqual(403);
|
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();
|
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({
|
const getResp = await userAgent.resource('dataSources.roles', 'main').get({
|
||||||
filterByTk: 'testRole',
|
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({
|
const getResp = await userAgent.resource('roles.dataSourcesCollections', 'testRole').list({
|
||||||
filter: {
|
filter: {
|
||||||
|
@ -36,7 +36,7 @@ describe('actions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
agent = app.agent();
|
agent = app.agent();
|
||||||
adminAgent = await app.agent().loginWithJti(adminUser);
|
adminAgent = await app.agent().login(adminUser);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@ -166,7 +166,7 @@ describe('actions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// list with user
|
// 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({});
|
const listResp = await userAgent.resource('items').list({});
|
||||||
expect(listResp.status).toBe(200);
|
expect(listResp.status).toBe(200);
|
||||||
|
@ -41,7 +41,7 @@ describe('acl', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
adminAgent = await app.agent().loginWithJti(admin);
|
adminAgent = await app.agent().login(admin);
|
||||||
uiSchemaRepository = db.getRepository('uiSchemas');
|
uiSchemaRepository = db.getRepository('uiSchemas');
|
||||||
await db.getRepository('collections').create({
|
await db.getRepository('collections').create({
|
||||||
context: {},
|
context: {},
|
||||||
|
@ -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
|
// @ts-ignore
|
||||||
const response = await agent.resource('roles').check();
|
const response = await agent.resource('roles').check();
|
||||||
|
@ -222,7 +222,7 @@ describe('actions', () => {
|
|||||||
password: '12345',
|
password: '12345',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const userAgent = await agent.loginWithJti(user, null);
|
const userAgent = await agent.login(user, null);
|
||||||
|
|
||||||
// Should check password consistency
|
// Should check password consistency
|
||||||
const res = await userAgent.post('/auth:changePassword').set({ 'X-Authenticator': 'basic' }).send({
|
const res = await userAgent.post('/auth:changePassword').set({ 'X-Authenticator': 'basic' }).send({
|
||||||
@ -256,7 +256,7 @@ describe('actions', () => {
|
|||||||
password: '12345',
|
password: '12345',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const res3 = await (await agent.loginWithJti(user1))
|
const res3 = await (await agent.login(user1))
|
||||||
.post('/auth:changePassword')
|
.post('/auth:changePassword')
|
||||||
.set({ 'X-Authenticator': 'basic' })
|
.set({ 'X-Authenticator': 'basic' })
|
||||||
.send({
|
.send({
|
||||||
@ -281,7 +281,7 @@ describe('actions', () => {
|
|||||||
password: '12345',
|
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({
|
const res = await userAgent.post('/auth:changePassword').set({ 'X-Authenticator': 'basic' }).send({
|
||||||
oldPassword: '12345',
|
oldPassword: '12345',
|
||||||
@ -445,7 +445,7 @@ describe('actions', () => {
|
|||||||
password: '12345',
|
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();
|
const res = await userAgent.post('/auth:check').set({ 'X-Authenticator': 'basic' }).send();
|
||||||
expect(res.statusCode).toEqual(200);
|
expect(res.statusCode).toEqual(200);
|
||||||
expect(res.body.data.id).toBeDefined();
|
expect(res.body.data.id).toBeDefined();
|
||||||
|
@ -80,7 +80,7 @@ describe('auth', () => {
|
|||||||
username: 'admin',
|
username: 'admin',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
adminAgent = await app.agent().loginWithJti(user, 'admin');
|
adminAgent = await app.agent().login(user, 'admin');
|
||||||
|
|
||||||
class MockBaseAuth extends BaseAuth {
|
class MockBaseAuth extends BaseAuth {
|
||||||
async validate() {
|
async validate() {
|
||||||
|
@ -16,7 +16,7 @@ describe('backup files', () => {
|
|||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
app = await createApp();
|
app = await createApp();
|
||||||
adminAgent = await app.agent().loginWithJti(1);
|
adminAgent = await app.agent().login(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -42,7 +42,7 @@ describe('tree', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const userPlugin = app.getPlugin('users');
|
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');
|
agent.set('X-With-ACL-Meta', 'true');
|
||||||
app.acl.allow('table_a', ['*']);
|
app.acl.allow('table_a', ['*']);
|
||||||
app.acl.allow('collections', ['*']);
|
app.acl.allow('collections', ['*']);
|
||||||
|
@ -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();
|
const listRes = await adminAgent.resource('api/posts').list();
|
||||||
expect(listRes.status).toBe(200);
|
expect(listRes.status).toBe(200);
|
||||||
expect(middlewareFn).toBeCalledTimes(1);
|
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({});
|
const postRes = await adminAgent.resource('api/posts').list({});
|
||||||
expect(postRes.status).toBe(200);
|
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({
|
await adminAgent.resource('dataSources.roles', 'mockInstance1').update({
|
||||||
filterByTk: 'member',
|
filterByTk: 'member',
|
||||||
@ -195,9 +195,9 @@ describe('data source with acl', () => {
|
|||||||
context: {},
|
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({});
|
const listRes = await testUserAgent.resource('posts').list({});
|
||||||
expect(listRes.status).toBe(403);
|
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
|
// should get permission error
|
||||||
const testAgent = await app.agent().loginWithJti(testUser);
|
const testAgent = await app.agent().login(testUser);
|
||||||
const testUserAgent = getDataSourceAgent(testAgent, 'mockInstance1');
|
const testUserAgent = getDataSourceAgent(testAgent, 'mockInstance1');
|
||||||
|
|
||||||
// @ts-ignore
|
// @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
|
// 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({
|
const createResourceResp = await adminAgent.resource('dataSources.rolesResourcesScopes', 'mockInstance1').create({
|
||||||
values: {
|
values: {
|
||||||
@ -402,7 +402,7 @@ describe('data source with acl', () => {
|
|||||||
|
|
||||||
// call roles check
|
// call roles check
|
||||||
// @ts-ignore
|
// @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);
|
expect(checkRep.status).toBe(200);
|
||||||
|
|
||||||
const checkData = checkRep.body;
|
const checkData = checkRep.body;
|
||||||
@ -419,21 +419,17 @@ describe('data source with acl', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// update strategy
|
// update strategy
|
||||||
const updateRes = await app
|
const updateRes = await (await app.agent().login(adminUser)).resource('dataSources.roles', 'main').update({
|
||||||
.agent()
|
filterByTk: 'admin',
|
||||||
.login(adminUser)
|
values: {
|
||||||
.resource('dataSources.roles', 'main')
|
strategy: {
|
||||||
.update({
|
actions: [],
|
||||||
filterByTk: 'admin',
|
|
||||||
values: {
|
|
||||||
strategy: {
|
|
||||||
actions: [],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// get role
|
// 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',
|
filterByTk: 'admin',
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -441,20 +437,16 @@ describe('data source with acl', () => {
|
|||||||
expect(data.data.strategy.actions).toHaveLength(0);
|
expect(data.data.strategy.actions).toHaveLength(0);
|
||||||
|
|
||||||
// update role
|
// update role
|
||||||
const updateRoleRes = await app
|
const updateRoleRes = await (await app.agent().login(adminUser)).resource('roles').update({
|
||||||
.agent()
|
filterByTk: 'admin',
|
||||||
.login(adminUser)
|
values: {
|
||||||
.resource('roles')
|
snippets: ['pm.*'],
|
||||||
.update({
|
},
|
||||||
filterByTk: 'admin',
|
});
|
||||||
values: {
|
|
||||||
snippets: ['pm.*'],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(updateRoleRes.status).toBe(200);
|
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',
|
filterByTk: 'admin',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ describe('external data source', () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
process.env.INIT_ROOT_USERNAME = 'test';
|
process.env.INIT_ROOT_USERNAME = 'test';
|
||||||
app = await createMockServer({
|
app = await createMockServer({
|
||||||
plugins: ['field-sort', 'data-source-manager', 'users', 'acl'],
|
plugins: ['field-sort', 'data-source-manager', 'users', 'acl', 'auth'],
|
||||||
});
|
});
|
||||||
db = app.db;
|
db = app.db;
|
||||||
ctx = {
|
ctx = {
|
||||||
@ -40,7 +40,7 @@ describe('external data source', () => {
|
|||||||
username: process.env.INIT_ROOT_USERNAME,
|
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 () => {
|
it('should check permission for external data source', async () => {
|
||||||
|
@ -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];
|
currUserAgent = userAgents[0];
|
||||||
currUserId = users[0].id;
|
currUserId = users[0].id;
|
||||||
});
|
});
|
||||||
|
@ -33,7 +33,7 @@ describe('actions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
agent = app.agent();
|
agent = app.agent();
|
||||||
adminAgent = await app.agent().loginWithJti(adminUser);
|
adminAgent = await app.agent().login(adminUser);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -36,7 +36,7 @@ describe('actions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
agent = app.agent();
|
agent = app.agent();
|
||||||
adminAgent = await app.agent().loginWithJti(adminUser);
|
adminAgent = await app.agent().login(adminUser);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
@ -42,7 +42,7 @@ describe('workflow > action-trigger', () => {
|
|||||||
UserRepo = db.getCollection('users').repository;
|
UserRepo = db.getCollection('users').repository;
|
||||||
|
|
||||||
root = await UserRepo.findOne({});
|
root = await UserRepo.findOne({});
|
||||||
rootAgent = await app.agent().loginWithJti(root);
|
rootAgent = await app.agent().login(root);
|
||||||
|
|
||||||
users = await UserRepo.create({
|
users = await UserRepo.create({
|
||||||
values: [
|
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());
|
afterEach(() => app.destroy());
|
||||||
@ -812,8 +812,9 @@ describe('workflow > action-trigger', () => {
|
|||||||
// values: { title: 't2' },
|
// values: { title: 't2' },
|
||||||
// triggerWorkflows: `${workflow.key}`,
|
// triggerWorkflows: `${workflow.key}`,
|
||||||
// });
|
// });
|
||||||
const res2 = await agent
|
const res2 = await (
|
||||||
.login(users[0])
|
await agent.login(users[0])
|
||||||
|
)
|
||||||
.set('x-data-source', 'another')
|
.set('x-data-source', 'another')
|
||||||
.post('/api/posts:create')
|
.post('/api/posts:create')
|
||||||
.query({ triggerWorkflows: `${workflow.key}` })
|
.query({ triggerWorkflows: `${workflow.key}` })
|
||||||
|
@ -44,7 +44,7 @@ describe('workflow > instructions > manual > assignees', () => {
|
|||||||
{ id: 3, nickname: 'b' },
|
{ 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({
|
workflow = await WorkflowModel.create({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -44,7 +44,7 @@ describe('workflow > instructions > manual', () => {
|
|||||||
{ id: 3, nickname: 'b' },
|
{ 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({
|
workflow = await WorkflowModel.create({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -44,7 +44,7 @@ describe('workflow > instructions > manual', () => {
|
|||||||
{ id: 3, nickname: 'b' },
|
{ 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({
|
workflow = await WorkflowModel.create({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -44,7 +44,7 @@ describe('workflow > instructions > manual', () => {
|
|||||||
{ id: 3, nickname: 'b' },
|
{ 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({
|
workflow = await WorkflowModel.create({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -27,7 +27,7 @@ describe('workflow > actions > executions', () => {
|
|||||||
plugins: ['users', 'acl', 'auth', 'data-source-manager'],
|
plugins: ['users', 'acl', 'auth', 'data-source-manager'],
|
||||||
acl: true,
|
acl: true,
|
||||||
});
|
});
|
||||||
agent = app.agent().loginUsingId(1);
|
agent = await app.agent().loginUsingId(1);
|
||||||
db = app.db;
|
db = app.db;
|
||||||
WorkflowModel = db.getCollection('workflows').model;
|
WorkflowModel = db.getCollection('workflows').model;
|
||||||
PostRepo = db.getCollection('posts').repository;
|
PostRepo = db.getCollection('posts').repository;
|
||||||
@ -47,7 +47,7 @@ describe('workflow > actions > executions', () => {
|
|||||||
{ id: 3, nickname: 'b' },
|
{ 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());
|
afterEach(async () => await app.destroy());
|
||||||
|
@ -40,7 +40,7 @@ describe('workflow > triggers > collection', () => {
|
|||||||
TagRepo = db.getCollection('tags').repository;
|
TagRepo = db.getCollection('tags').repository;
|
||||||
|
|
||||||
const user = await app.db.getRepository('users').findOne();
|
const user = await app.db.getRepository('users').findOne();
|
||||||
agent = await app.agent().loginWithJti(user);
|
agent = await app.agent().login(user);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => app.destroy());
|
afterEach(() => app.destroy());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user