mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
* create migrations for group permissions setup * define new entities and relationships * revise migrations * rename columns * add migration to populate permission groups for existing users * Feature: User access permission group usage (#883) * create migrations for group permissions setup * define new entities and relationships * revise migrations * rename columns * add migration to populate permission groups for existing users * revise migrations * hide roles usage * setup group permissions for apps and users * fix defaultChecked * fix update permission checkbox * fix casl ability check to have params passed * fix casl apps abilities to check with app specific permission * add ability to delete groups * conditionally render edit and delete options for all and admin users * fix user role to group migration * revise group management pages to disallow updating default group * move manage users and groups to navbar dropdown * show only addable apps and users on dropdowns * rename header as profile settings * scope addable apps and users by organization * scope viewable apps on homepage * hide manage groups link from non admins * make permissions to be used with radio input * add loading state for add apps/users buttons * revise unit tests * revise migrations * fix e2e tests * comment out dead code * fix seeds script * handle folder count * captalize error toast * hide manage users dropdown for non admins * show fobidden error on blank homepage * fix folder app count * fix invalid state set * make group name clickable for edit instead * users with edit permission can deploy apps * not show edit link on homepage if user dont have update permission * remove unused entity from merge * remove roles usage from manage org users page * fix folder count and blank slate on homepage * disable add buttons if there is no selections * humanize default groups on view * make app added onto groups have read permission by default * not show app menu if user is not admin * remove admin users from group user addition dropdown * create default permissions for app cloned * fix querying index page without page params * fix admin scoped out from group add * remove apps from header * fix invitation url not shown * scope admin deletion check by org * scope public apps by organization * add specs for group permissions e2e * removed unused entity and add group permissions spec * remove console logs * remove unused permission * scope public app count by org * remove console log * refactor manage group permission resources component * update group permssion in org scope
849 lines
30 KiB
TypeScript
849 lines
30 KiB
TypeScript
import * as request from 'supertest';
|
|
import { INestApplication } from '@nestjs/common';
|
|
import {
|
|
authHeaderForUser,
|
|
clearDB,
|
|
createApplication,
|
|
createUser,
|
|
createNestAppInstance,
|
|
createApplicationVersion,
|
|
createDataQuery,
|
|
createDataSource,
|
|
createAppGroupPermission,
|
|
} from '../test.helper';
|
|
import { App } from 'src/entities/app.entity';
|
|
import { AppVersion } from 'src/entities/app_version.entity';
|
|
import { DataQuery } from 'src/entities/data_query.entity';
|
|
import { DataSource } from 'src/entities/data_source.entity';
|
|
import { AppUser } from 'src/entities/app_user.entity';
|
|
import { getRepository } from 'typeorm';
|
|
import { GroupPermission } from 'src/entities/group_permission.entity';
|
|
|
|
describe('apps controller', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeEach(async () => {
|
|
await clearDB();
|
|
});
|
|
|
|
beforeAll(async () => {
|
|
app = await createNestAppInstance();
|
|
});
|
|
|
|
describe('/apps/uuid', () => {
|
|
it('should allow only authenticated users to update app params', async () => {
|
|
await request(app.getHttpServer()).put('/apps/uuid').expect(401);
|
|
});
|
|
});
|
|
|
|
describe('/apps', () => {
|
|
describe('authorization', () => {
|
|
it('should be able to create app if user has admin group', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const organization = adminUserData.organization;
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization,
|
|
});
|
|
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
await createApplicationVersion(app, application);
|
|
|
|
for (const userData of [viewerUserData, developerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/apps`)
|
|
.set('Authorization', authHeaderForUser(userData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
}
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/apps`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
expect(response.body.name).toBe('Untitled app');
|
|
});
|
|
});
|
|
|
|
it('should create app with default values', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/apps`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
expect(response.body.name).toBe('Untitled app');
|
|
|
|
const appId = response.body.id;
|
|
const application = await App.findOne({ id: appId });
|
|
|
|
expect(application.name).toBe('Untitled app');
|
|
expect(application.id).toBe(application.slug);
|
|
});
|
|
});
|
|
|
|
describe('/apps/:id/clone', () => {
|
|
it('should be able to clone the app if user group is admin', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
|
|
const developerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
|
|
const application = await createApplication(app, {
|
|
name: 'App to clone',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
let response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/clone`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
|
|
const appId = response.body.id;
|
|
const clonedApplication = await App.findOne({ id: appId });
|
|
expect(clonedApplication.name).toBe('App to clone');
|
|
|
|
response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/clone`)
|
|
.set('Authorization', authHeaderForUser(developerUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/clone`)
|
|
.set('Authorization', authHeaderForUser(viewerUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should not be able to clone the app if app is of another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/clone`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
});
|
|
|
|
describe('/apps/:id', () => {
|
|
it('should be able to update name of the app if admin of same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.put(`/apps/${application.id}`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send({ app: { name: 'new name' } });
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
await application.reload();
|
|
expect(application.name).toBe('new name');
|
|
});
|
|
|
|
it('should not be able to update name of the app if admin of another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.put(`/apps/${application.id}`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user))
|
|
.send({ app: { name: 'new name' } });
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
await application.reload();
|
|
expect(application.name).toBe('name');
|
|
});
|
|
|
|
it('should not allow custom groups without app create permission to change the name of apps', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const developerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
|
|
let response = await request(app.getHttpServer())
|
|
.put(`/apps/${application.id}`)
|
|
.set('Authorization', authHeaderForUser(developerUserData.user))
|
|
.send({ app: { name: 'new name' } });
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
response = await request(app.getHttpServer())
|
|
.put(`/apps/${application.id}`)
|
|
.set('Authorization', authHeaderForUser(viewerUserData.user))
|
|
.send({ app: { name: 'new name' } });
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
await application.reload();
|
|
expect(application.name).toBe('name');
|
|
});
|
|
|
|
describe('delete app', () => {
|
|
it('should be possible for the admin to delete an app, cascaded with its versions, queries and data sources', async () => {
|
|
const admin = await createUser(app, {
|
|
email: 'adminForDelete@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'AppTObeDeleted',
|
|
user: admin.user,
|
|
});
|
|
const version = await createApplicationVersion(app, application);
|
|
const dataQuery = await createDataQuery(app, {
|
|
application,
|
|
kind: 'test_kind',
|
|
});
|
|
const dataSource = await createDataSource(app, {
|
|
application,
|
|
kind: 'test_kind',
|
|
name: 'test_name',
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.delete(`/apps/${application.id}`)
|
|
.set('Authorization', authHeaderForUser(admin.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
expect(await App.findOne(application.id)).toBeUndefined();
|
|
expect(await AppVersion.findOne(version.id)).toBeUndefined();
|
|
expect(await DataQuery.findOne(dataQuery.id)).toBeUndefined();
|
|
expect(await DataSource.findOne(dataSource.id)).toBeUndefined();
|
|
expect(await AppUser.findOne({ appId: application.id })).toBeUndefined();
|
|
});
|
|
|
|
it('should not be possible for non-admin user to delete an app, cascaded with its versions, queries and data sources', async () => {
|
|
const developer = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'AppTObeDeleted',
|
|
user: developer.user,
|
|
});
|
|
await createApplicationVersion(app, application);
|
|
await createDataQuery(app, { application, kind: 'test_kind' });
|
|
await createDataSource(app, {
|
|
application,
|
|
kind: 'test_kind',
|
|
name: 'test_name',
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.delete(`/apps/${application.id}`)
|
|
.set('Authorization', authHeaderForUser(developer.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
|
|
expect(await App.findOne(application.id)).not.toBeUndefined();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('/apps/uuid/users', () => {
|
|
it('should allow only authenticated users to access app users endpoint', async () => {
|
|
await request(app.getHttpServer()).get('/apps/uuid/users').expect(401);
|
|
});
|
|
});
|
|
|
|
// TODO: Remove deprecated endpoint
|
|
describe('/apps/:id/users', () => {
|
|
xit('should not be able to fetch app users if admin of another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/apps/${application.id}/users`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
xit('should be able to fetch app users if group is admin/developer/viewer of same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const organization = adminUserData.organization;
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization,
|
|
});
|
|
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData, viewerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/apps/${application.id}/users`)
|
|
.set('Authorization', authHeaderForUser(userData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.users.length).toBe(1);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('/apps/:id/versions', () => {
|
|
describe('get versions', () => {
|
|
describe('authorization', () => {
|
|
it('should be able to fetch app versions with app read permission group', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const organization = adminUserData.organization;
|
|
const defaultUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users'],
|
|
organization,
|
|
});
|
|
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
await createApplicationVersion(app, application);
|
|
|
|
const allUserGroup = await getRepository(GroupPermission).findOne({
|
|
group: 'all_users',
|
|
});
|
|
await createAppGroupPermission(app, application, allUserGroup.id, {
|
|
read: true,
|
|
update: false,
|
|
delete: false,
|
|
});
|
|
|
|
for (const userData of [adminUserData, defaultUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(userData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.versions.length).toBe(1);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('create version', () => {
|
|
describe('authorization', () => {
|
|
it('should not be able to fetch app versions if user of another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
await createApplicationVersion(app, application);
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should be able to create a new app version if group is admin or has app update permission group in same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
// setup app permissions for developer
|
|
const developerUserGroup = await getRepository(GroupPermission).findOne({
|
|
group: 'developer',
|
|
});
|
|
await createAppGroupPermission(app, application, developerUserGroup.id, {
|
|
read: false,
|
|
update: true,
|
|
delete: false,
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(userData.user))
|
|
.send({
|
|
versionName: 'v0',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
}
|
|
});
|
|
|
|
it('should not be able to create app versions if user of another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
await createApplicationVersion(app, application);
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user))
|
|
.send({
|
|
versionName: 'v0',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should not be able to create app versions if user does not have app create permission group', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
await createApplicationVersion(app, application);
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(viewerUserData.user))
|
|
.send({
|
|
versionName: 'v0',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
});
|
|
|
|
describe('app definition', () => {
|
|
it('should return null when no previous versions exists', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
let response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send({
|
|
versionName: 'v0',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
|
|
response = await request(app.getHttpServer())
|
|
.get(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.versions['0']['definition']).toBe(null);
|
|
});
|
|
|
|
it('should return previous version definition when previous versions exists', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
|
|
const application = await createApplication(app, {
|
|
user: adminUserData.user,
|
|
});
|
|
|
|
const version = await createApplicationVersion(app, application);
|
|
|
|
let response = await request(app.getHttpServer())
|
|
.put(`/apps/${application.id}/versions/${version.id}`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send({
|
|
definition: { foo: 'bar' },
|
|
});
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
|
|
response = await request(app.getHttpServer())
|
|
.post(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user))
|
|
.send({
|
|
versionName: 'v1',
|
|
});
|
|
|
|
expect(response.statusCode).toBe(201);
|
|
|
|
response = await request(app.getHttpServer())
|
|
.get(`/apps/${application.id}/versions`)
|
|
.set('Authorization', authHeaderForUser(adminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
expect(response.body.versions['0']['name']).toBe('v1');
|
|
expect(response.body.versions['0']['definition']).toMatchObject({
|
|
foo: 'bar',
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('/apps/:id/versions/:version_id', () => {
|
|
describe('get app version', () => {
|
|
describe('authorization', () => {
|
|
it('should be able to get app version by users having app read permission within same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
groups: ['all_users'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
user: adminUserData.user,
|
|
});
|
|
const version = await createApplicationVersion(app, application);
|
|
|
|
const allUserGroup = await getRepository(GroupPermission).findOne({
|
|
group: 'all_users',
|
|
});
|
|
await createAppGroupPermission(app, application, allUserGroup.id, {
|
|
read: true,
|
|
update: false,
|
|
delete: false,
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/apps/${application.id}/versions/${version.id}`)
|
|
.set('Authorization', authHeaderForUser(userData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
}
|
|
});
|
|
|
|
it('should not be able to get app versions if user of another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
const version = await createApplicationVersion(app, application);
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.get(`/apps/${application.id}/versions/${version.id}`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('update app version', () => {
|
|
it('should be able to update app version if has group admin or app update permission group in same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
user: adminUserData.user,
|
|
});
|
|
const version = await createApplicationVersion(app, application);
|
|
|
|
// setup app permissions for developer
|
|
const developerUserGroup = await getRepository(GroupPermission).findOne({ group: 'developer' });
|
|
await createAppGroupPermission(app, application, developerUserGroup.id, {
|
|
read: false,
|
|
update: true,
|
|
delete: false,
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.put(`/apps/${application.id}/versions/${version.id}`)
|
|
.set('Authorization', authHeaderForUser(userData.user))
|
|
.send({
|
|
definition: { components: {} },
|
|
});
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
await version.reload();
|
|
}
|
|
});
|
|
|
|
it('should not be able to update app version if no app create permission within same organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'dev@tooljet.io',
|
|
groups: ['all_users'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
user: adminUserData.user,
|
|
});
|
|
const version = await createApplicationVersion(app, application);
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.put(`/apps/${application.id}/versions/${version.id}`)
|
|
.set('Authorization', authHeaderForUser(viewerUserData.user))
|
|
.send({
|
|
definition: { components: {} },
|
|
});
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should not be able to update app versions if user of another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
});
|
|
const version = await createApplicationVersion(app, application);
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.put(`/apps/${application.id}/versions/${version.id}`)
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user))
|
|
.send({
|
|
definition: { components: {} },
|
|
});
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
});
|
|
});
|
|
|
|
/*
|
|
Viewing app on app viewer
|
|
All org users can launch an app
|
|
Public apps can be launched by anyone ( even unauthenticated users )
|
|
By view app endpoint, we assume the apps/slugs/:id endpoint
|
|
*/
|
|
describe('/apps/slugs/:slug', () => {
|
|
it('should be able to fetch app using slug if has read permission within an organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const developerUserData = await createUser(app, {
|
|
email: 'developer@tooljet.io',
|
|
groups: ['all_users', 'developer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const viewerUserData = await createUser(app, {
|
|
email: 'viewer@tooljet.io',
|
|
groups: ['all_users', 'viewer'],
|
|
organization: adminUserData.organization,
|
|
});
|
|
const application = await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
slug: 'foo',
|
|
});
|
|
// setup app permissions for developer
|
|
const developerUserGroup = await getRepository(GroupPermission).findOne({
|
|
group: 'developer',
|
|
});
|
|
await createAppGroupPermission(app, application, developerUserGroup.id, {
|
|
read: true,
|
|
update: true,
|
|
delete: false,
|
|
});
|
|
// setup app permissions for viewer
|
|
const viewerUserGroup = await getRepository(GroupPermission).findOne({
|
|
group: 'viewer',
|
|
});
|
|
await createAppGroupPermission(app, application, viewerUserGroup.id, {
|
|
read: true,
|
|
update: false,
|
|
delete: false,
|
|
});
|
|
|
|
for (const userData of [adminUserData, developerUserData, viewerUserData]) {
|
|
const response = await request(app.getHttpServer())
|
|
.get('/apps/slugs/foo')
|
|
.set('Authorization', authHeaderForUser(userData.user));
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
}
|
|
});
|
|
|
|
it('should not be able to fetch app using slug if member of another organization', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
const anotherOrgAdminUserData = await createUser(app, {
|
|
email: 'another@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
slug: 'foo',
|
|
});
|
|
|
|
const response = await request(app.getHttpServer())
|
|
.get('/apps/slugs/foo')
|
|
.set('Authorization', authHeaderForUser(anotherOrgAdminUserData.user));
|
|
|
|
expect(response.statusCode).toBe(403);
|
|
});
|
|
|
|
it('should be able to fetch app using slug if a public app ( even if unauthenticated )', async () => {
|
|
const adminUserData = await createUser(app, {
|
|
email: 'admin@tooljet.io',
|
|
groups: ['all_users', 'admin'],
|
|
});
|
|
|
|
await createApplication(app, {
|
|
name: 'name',
|
|
user: adminUserData.user,
|
|
slug: 'foo',
|
|
isPublic: true,
|
|
});
|
|
|
|
const response = await request(app.getHttpServer()).get('/apps/slugs/foo');
|
|
|
|
expect(response.statusCode).toBe(200);
|
|
});
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
});
|