From cb2b861032ffbe6da489cf1973ee484da898a8f6 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 22 Nov 2022 16:52:56 +0000 Subject: [PATCH 01/23] Add User endpoints --- .../internal-api/TestConfiguration/index.ts | 3 + .../TestConfiguration/userManagement.ts | 43 ++++++++++++ .../internal-api/fixtures/userManagement.ts | 67 +++++++++++++++++++ .../userManagement/userManagement.spec.ts | 24 +++++++ 4 files changed, 137 insertions(+) create mode 100644 qa-core/src/config/internal-api/TestConfiguration/userManagement.ts create mode 100644 qa-core/src/config/internal-api/fixtures/userManagement.ts create mode 100644 qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts diff --git a/qa-core/src/config/internal-api/TestConfiguration/index.ts b/qa-core/src/config/internal-api/TestConfiguration/index.ts index ab996f7144..8ce5e94bc3 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/index.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/index.ts @@ -4,6 +4,7 @@ import InternalAPIClient from "./InternalAPIClient" import TablesApi from "./tables" import RowApi from "./rows" import ScreenApi from "./screens" +import UserManagementApi from "./userManagement" export default class TestConfiguration { applications: ApplicationApi @@ -12,6 +13,7 @@ export default class TestConfiguration { context: T tables: TablesApi rows: RowApi + userManagement: UserManagementApi constructor(apiClient: InternalAPIClient) { this.applications = new ApplicationApi(apiClient) @@ -19,6 +21,7 @@ export default class TestConfiguration { this.rows = new RowApi(apiClient) this.auth = new AuthApi(apiClient) this.screen = new ScreenApi(apiClient) + this.userManagement = new UserManagementApi(apiClient) this.context = {} } diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts new file mode 100644 index 0000000000..3a66049fd0 --- /dev/null +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -0,0 +1,43 @@ +import { Response } from "node-fetch" +import { User } from "@budibase/types" +import InternalAPIClient from "./InternalAPIClient" +import { responseMessage } from "../fixtures/types/responseMessage" + +export default class UserManagementApi { + api: InternalAPIClient + + constructor(apiClient: InternalAPIClient) { + this.api = apiClient + } + + async searchUsers(): Promise<[Response, User[]]> { + const response = await this.api.post(`/global/users/search`, {}) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json.length).toBeGreaterThan(0) + return [response, json] + } + + async getSelf(): Promise<[Response, User]> { + const response = await this.api.get(`/global/self`) + const json = await response.json() + expect(response).toHaveStatusCode(200) + return [response, json] + } + + async getAllUsers(): Promise<[Response, User]> { + const response = await this.api.get(`/global/users`) + const json = await response.json() + expect(response).toHaveStatusCode(200) + return [response, json] + } + + async inviteUsers(body: User[]): Promise<[Response, responseMessage]> { + const response = await this.api.post(`/global/users/multi/invite`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json.successful.length).toEqual(body.length) + expect(json.unsuccessful.length).toEqual(0) + return [response, json] + } +} diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts new file mode 100644 index 0000000000..ce15eb08e8 --- /dev/null +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -0,0 +1,67 @@ +import generator from "../../generator"; + +const randomId = generator.guid; +export const generateDeveloper = (): any => ({ + create: { + users: [{ + email: `pedro+${randomId()}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + builder: { + global: true + } + }], + groups: [] + } +}) + +export const generateAdmin = (): any => ({ + create: { + users: [{ + email: `pedro+${randomId()}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + admin: { + global: true + }, + builder: { + global: true + } + }], + groups: [] + } +}) +export const generateAppUser = (): any => ({ + create: { + users: [{ + email: `pedro+${randomId()}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + admin: { + global: false + }, + builder: { + global: false + } + }], + groups: [] + } +}) + +export const generateInviteUser = (): any => ( + [{ + email: `pedro+${randomId()}@budibase.com`, + userInfo: { + admin: { + global: true + }, + builder: { + global: true + }, + userGroups: [] + } + }] +) \ No newline at end of file diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts new file mode 100644 index 0000000000..67fee8e53d --- /dev/null +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -0,0 +1,24 @@ +import TestConfiguration from "../../../config/internal-api/TestConfiguration" +import { Application } from "@budibase/server/api/controllers/public/mapping/types" +import { db } from "@budibase/backend-core" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" +import generateApp from "../../../config/internal-api/fixtures/applications" +import generator from "../../../config/generator" +import generateScreen from "../../../config/internal-api/fixtures/screens" + +describe("Internal API - User Management", () => { + const api = new InternalAPIClient() + const config = new TestConfiguration(api) + + beforeAll(async () => { + await config.beforeAll() + }) + + afterAll(async () => { + await config.afterAll() + }) + + it("Get all users", async () => { + await config.userManagement.searchUsers() + }) +}) From 7f8e093a52727ff8273335bf2131ee094441e7b1 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 28 Nov 2022 22:13:07 +0000 Subject: [PATCH 02/23] Add verification --- .../TestConfiguration/userManagement.ts | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 3a66049fd0..2ff9450939 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -1,5 +1,5 @@ import { Response } from "node-fetch" -import { User } from "@budibase/types" +import { User, UserDeletedEvent } from "@budibase/types" import InternalAPIClient from "./InternalAPIClient" import { responseMessage } from "../fixtures/types/responseMessage" @@ -14,7 +14,8 @@ export default class UserManagementApi { const response = await this.api.post(`/global/users/search`, {}) const json = await response.json() expect(response).toHaveStatusCode(200) - expect(json.length).toBeGreaterThan(0) + expect(json.data.length).toBeGreaterThan(0) + expect(json.hasNextPage).toBe(false) return [response, json] } @@ -40,4 +41,21 @@ export default class UserManagementApi { expect(json.unsuccessful.length).toEqual(0) return [response, json] } + + async deleteUser(userId: string): Promise<[Response, responseMessage]> { + const body = { + delete: { + userIds: [ + userId + ] + } + } + const response = await this.api.post(`/global/users/bulk`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json.deleted.successful.length).toEqual(1) + expect(json.deleted.unsuccessful.length).toEqual(0) + expect(json.deleted.successful[0].userId).toEqual(userId) + return [response, json] + } } From b9186cac9d3e45455b0627dd31f448a844422d9a Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Wed, 30 Nov 2022 11:02:11 +0000 Subject: [PATCH 03/23] Add tests for user management --- .../TestConfiguration/userManagement.ts | 31 +++-- .../internal-api/fixtures/userManagement.ts | 115 ++++++++++-------- .../userManagement/userManagement.spec.ts | 19 ++- 3 files changed, 103 insertions(+), 62 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 2ff9450939..17fe5e0b0f 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -1,5 +1,5 @@ import { Response } from "node-fetch" -import { User, UserDeletedEvent } from "@budibase/types" +import { Role, User, UserDeletedEvent } from "@budibase/types" import InternalAPIClient from "./InternalAPIClient" import { responseMessage } from "../fixtures/types/responseMessage" @@ -15,7 +15,6 @@ export default class UserManagementApi { const json = await response.json() expect(response).toHaveStatusCode(200) expect(json.data.length).toBeGreaterThan(0) - expect(json.hasNextPage).toBe(false) return [response, json] } @@ -26,19 +25,20 @@ export default class UserManagementApi { return [response, json] } - async getAllUsers(): Promise<[Response, User]> { + async getAllUsers(): Promise<[Response, User[]]> { const response = await this.api.get(`/global/users`) const json = await response.json() expect(response).toHaveStatusCode(200) + expect(json.length).toBeGreaterThan(0) return [response, json] } - async inviteUsers(body: User[]): Promise<[Response, responseMessage]> { - const response = await this.api.post(`/global/users/multi/invite`, { body }) + async addUsers(body: any): Promise<[Response, responseMessage]> { + const response = await this.api.post(`/global/users/bulk`, { body }) const json = await response.json() expect(response).toHaveStatusCode(200) - expect(json.successful.length).toEqual(body.length) - expect(json.unsuccessful.length).toEqual(0) + expect(json.created.unsuccessful.length).toEqual(0) + expect(json.created.successful.length).toEqual(body.create.users.length) return [response, json] } @@ -58,4 +58,21 @@ export default class UserManagementApi { expect(json.deleted.successful[0].userId).toEqual(userId) return [response, json] } + + async inviteUser(body: any): Promise<[Response, responseMessage]> { + const response = await this.api.post(`/global/users/multi/invite`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json.created.successful.length).toEqual(body.length) + expect(json.created.unsuccessful.length).toEqual(0) + return [response, json] + } + + async getRoles(): Promise<[Response, Role[]]> { + const response = await this.api.get(`/roles`) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json.length).toEqual(4) + return [response, json] + } } diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts index ce15eb08e8..6ada85bb49 100644 --- a/qa-core/src/config/internal-api/fixtures/userManagement.ts +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -1,59 +1,69 @@ import generator from "../../generator"; -const randomId = generator.guid; -export const generateDeveloper = (): any => ({ - create: { - users: [{ - email: `pedro+${randomId()}@budibase.com`, - password: randomId, - roles: {}, - forceResetPassword: true, - builder: { - global: true - } - }], - groups: [] - } -}) +export const generateDeveloper = (): Object => { + const randomId = generator.guid(); + return ({ + create: { + users: [{ + email: `pedro+${randomId}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + builder: { + global: true + } + }], + groups: [] + } + }) +} -export const generateAdmin = (): any => ({ - create: { - users: [{ - email: `pedro+${randomId()}@budibase.com`, - password: randomId, - roles: {}, - forceResetPassword: true, - admin: { - global: true - }, - builder: { - global: true - } - }], - groups: [] +export const generateAdmin = (): Object => { + const randomId = generator.guid(); + return ({ + create: { + users: [{ + email: `pedro+${randomId}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + admin: { + global: true + }, + builder: { + global: true + } + }], + groups: [] + } + }) +} +export const generateAppUser = (): Object => { + const randomId = generator.guid(); + const user = { + create: { + users: [{ + email: `pedro+${randomId}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + admin: { + global: false + }, + builder: { + global: false + } + }], + groups: [] + } } -}) -export const generateAppUser = (): any => ({ - create: { - users: [{ - email: `pedro+${randomId()}@budibase.com`, - password: randomId, - roles: {}, - forceResetPassword: true, - admin: { - global: false - }, - builder: { - global: false - } - }], - groups: [] - } -}) + return user +} -export const generateInviteUser = (): any => ( - [{ - email: `pedro+${randomId()}@budibase.com`, +export const generateInviteUser = (): Object[] => { + const randomId = generator.guid(); + return [{ + email: `pedro+${randomId}@budibase.com`, userInfo: { admin: { global: true @@ -64,4 +74,5 @@ export const generateInviteUser = (): any => ( userGroups: [] } }] -) \ No newline at end of file + +} \ No newline at end of file diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 67fee8e53d..62d27ec2a4 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -4,9 +4,9 @@ import { db } from "@budibase/backend-core" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" import generateApp from "../../../config/internal-api/fixtures/applications" import generator from "../../../config/generator" -import generateScreen from "../../../config/internal-api/fixtures/screens" +import { generateAdmin, generateAppUser, generateDeveloper, generateInviteUser } from "../../../config/internal-api/fixtures/userManagement" -describe("Internal API - User Management", () => { +describe("Internal API - User Management & Permissions", () => { const api = new InternalAPIClient() const config = new TestConfiguration(api) @@ -18,7 +18,20 @@ describe("Internal API - User Management", () => { await config.afterAll() }) - it("Get all users", async () => { + it("Add Users with different roles", async () => { await config.userManagement.searchUsers() + await config.userManagement.getRoles() + + const [adminResponse, adminData] = await config.userManagement.addUsers(generateAdmin()) + const [devResponse, devData] = await config.userManagement.addUsers(generateDeveloper()) + const [userResponse, userData] = await config.userManagement.addUsers(generateAppUser()) + + const [invitedUserResponse, invitedUserData] = await config.userManagement.addUsers(generateInviteUser()) + + const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers() + expect(allUsersData.length).toEqual(4) + }) + + }) From 1c0767f549e4669574e8eef7f8f05625cabe4779 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 2 Dec 2022 18:42:56 +0000 Subject: [PATCH 04/23] Add users with all roles --- .../config/internal-api/TestConfiguration/userManagement.ts | 5 +++-- qa-core/src/config/internal-api/fixtures/userManagement.ts | 6 ------ .../internal-api/userManagement/userManagement.spec.ts | 2 +- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 17fe5e0b0f..0bc8fd7b66 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -63,8 +63,9 @@ export default class UserManagementApi { const response = await this.api.post(`/global/users/multi/invite`, { body }) const json = await response.json() expect(response).toHaveStatusCode(200) - expect(json.created.successful.length).toEqual(body.length) - expect(json.created.unsuccessful.length).toEqual(0) + expect(json.unsuccessful.length).toEqual(0) + expect(json.successful.length).toEqual(body.length) + return [response, json] } diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts index 6ada85bb49..035f6162f1 100644 --- a/qa-core/src/config/internal-api/fixtures/userManagement.ts +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -65,12 +65,6 @@ export const generateInviteUser = (): Object[] => { return [{ email: `pedro+${randomId}@budibase.com`, userInfo: { - admin: { - global: true - }, - builder: { - global: true - }, userGroups: [] } }] diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 62d27ec2a4..c18b6aaeff 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -26,7 +26,7 @@ describe("Internal API - User Management & Permissions", () => { const [devResponse, devData] = await config.userManagement.addUsers(generateDeveloper()) const [userResponse, userData] = await config.userManagement.addUsers(generateAppUser()) - const [invitedUserResponse, invitedUserData] = await config.userManagement.addUsers(generateInviteUser()) + const [invitedUserResponse, invitedUserData] = await config.userManagement.inviteUser(generateInviteUser()) const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers() expect(allUsersData.length).toEqual(4) From c0c8262561e48fa316f9772b093ae862c103c042 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 2 Dec 2022 18:59:08 +0000 Subject: [PATCH 05/23] Add generic login method --- .../config/internal-api/TestConfiguration/auth.ts | 14 +++++++++++++- .../config/internal-api/TestConfiguration/index.ts | 8 ++++++-- .../config/internal-api/fixtures/userManagement.ts | 4 ++-- .../internal-api/applications/applications.spec.ts | 2 +- .../src/tests/internal-api/screens/screens.spec.ts | 2 +- .../src/tests/internal-api/tables/tables.spec.ts | 2 +- .../userManagement/userManagement.spec.ts | 6 ++---- 7 files changed, 26 insertions(+), 12 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/auth.ts b/qa-core/src/config/internal-api/TestConfiguration/auth.ts index d83c859ab3..d72502b417 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/auth.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/auth.ts @@ -8,7 +8,7 @@ export default class AuthApi { this.api = apiClient } - async login(): Promise<[Response, any]> { + async loginAsAdmin(): Promise<[Response, any]> { const response = await this.api.post(`/global/auth/default/login`, { body: { username: process.env.BB_ADMIN_USER_EMAIL, @@ -20,6 +20,18 @@ export default class AuthApi { return [response, cookie] } + async login(email: String, password: String): Promise<[Response, any]> { + const response = await this.api.post(`/global/auth/default/login`, { + body: { + username: email, + password: password, + }, + }) + const cookie = response.headers.get("set-cookie") + this.api.cookie = cookie as any + return [response, cookie] + } + async logout(): Promise { return this.api.post(`/global/auth/logout`) } diff --git a/qa-core/src/config/internal-api/TestConfiguration/index.ts b/qa-core/src/config/internal-api/TestConfiguration/index.ts index 8ce5e94bc3..b424b32416 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/index.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/index.ts @@ -25,8 +25,12 @@ export default class TestConfiguration { this.context = {} } - async beforeAll() { - await this.auth.login() + async loginAsAdmin() { + await this.auth.login(process.env.BB_ADMIN_USER_EMAIL, process.env.BB_ADMIN_USER_PASSWORD) + } + + async login(email: String, password: String) { + await this.auth.login(email, password) } async afterAll() { diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts index 035f6162f1..5c5979256f 100644 --- a/qa-core/src/config/internal-api/fixtures/userManagement.ts +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -61,9 +61,9 @@ export const generateAppUser = (): Object => { } export const generateInviteUser = (): Object[] => { - const randomId = generator.guid(); + //const randomId = generator.guid(); return [{ - email: `pedro+${randomId}@budibase.com`, + email: `pedro+test@budibase.com`, userInfo: { userGroups: [] } diff --git a/qa-core/src/tests/internal-api/applications/applications.spec.ts b/qa-core/src/tests/internal-api/applications/applications.spec.ts index 98895a6f28..c7738152c4 100644 --- a/qa-core/src/tests/internal-api/applications/applications.spec.ts +++ b/qa-core/src/tests/internal-api/applications/applications.spec.ts @@ -11,7 +11,7 @@ describe("Internal API - Application creation, update, publish and delete", () = const config = new TestConfiguration(api) beforeAll(async () => { - await config.beforeAll() + await config.loginAsAdmin() }) afterAll(async () => { diff --git a/qa-core/src/tests/internal-api/screens/screens.spec.ts b/qa-core/src/tests/internal-api/screens/screens.spec.ts index 218d71cb0d..1af13d0a11 100644 --- a/qa-core/src/tests/internal-api/screens/screens.spec.ts +++ b/qa-core/src/tests/internal-api/screens/screens.spec.ts @@ -11,7 +11,7 @@ describe("Internal API - /screens endpoints", () => { const appConfig = new TestConfiguration(api) beforeAll(async () => { - await config.beforeAll() + await config.loginAsAdmin() }) afterAll(async () => { diff --git a/qa-core/src/tests/internal-api/tables/tables.spec.ts b/qa-core/src/tests/internal-api/tables/tables.spec.ts index 4f9e4299cf..6b2d2240e5 100644 --- a/qa-core/src/tests/internal-api/tables/tables.spec.ts +++ b/qa-core/src/tests/internal-api/tables/tables.spec.ts @@ -13,7 +13,7 @@ describe("Internal API - Application creation, update, publish and delete", () = const config = new TestConfiguration(api) beforeAll(async () => { - await config.beforeAll() + await config.loginAsAdmin() }) afterAll(async () => { diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index c18b6aaeff..7e38409723 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -11,7 +11,7 @@ describe("Internal API - User Management & Permissions", () => { const config = new TestConfiguration(api) beforeAll(async () => { - await config.beforeAll() + await config.loginAsAdmin() }) afterAll(async () => { @@ -26,10 +26,8 @@ describe("Internal API - User Management & Permissions", () => { const [devResponse, devData] = await config.userManagement.addUsers(generateDeveloper()) const [userResponse, userData] = await config.userManagement.addUsers(generateAppUser()) - const [invitedUserResponse, invitedUserData] = await config.userManagement.inviteUser(generateInviteUser()) - const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers() - expect(allUsersData.length).toEqual(4) + expect(allUsersData.length).toBeGreaterThan(0) }) From 0034bbbe2d0a5a51edb833a577898460c22fa2eb Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 2 Dec 2022 19:04:23 +0000 Subject: [PATCH 06/23] Record generated users passwords in test context --- .../userManagement/userManagement.spec.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 7e38409723..f7442a34fc 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -5,6 +5,7 @@ import InternalAPIClient from "../../../config/internal-api/TestConfiguration/In import generateApp from "../../../config/internal-api/fixtures/applications" import generator from "../../../config/generator" import { generateAdmin, generateAppUser, generateDeveloper, generateInviteUser } from "../../../config/internal-api/fixtures/userManagement" +import generate from "../../../config/internal-api/fixtures/applications" describe("Internal API - User Management & Permissions", () => { const api = new InternalAPIClient() @@ -22,9 +23,14 @@ describe("Internal API - User Management & Permissions", () => { await config.userManagement.searchUsers() await config.userManagement.getRoles() - const [adminResponse, adminData] = await config.userManagement.addUsers(generateAdmin()) - const [devResponse, devData] = await config.userManagement.addUsers(generateDeveloper()) - const [userResponse, userData] = await config.userManagement.addUsers(generateAppUser()) + // These need to be saved to the context so the passwords can be used to login + const admin = generateAdmin() + const developer = generateDeveloper() + const appUser = generateAppUser() + + const [adminResponse, adminData] = await config.userManagement.addUsers(admin) + const [devResponse, devData] = await config.userManagement.addUsers(developer) + const [userResponse, userData] = await config.userManagement.addUsers(appUser) const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers() expect(allUsersData.length).toBeGreaterThan(0) From 895c29d45fdf94cc7f9f6dce273d43c70e90e652 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 5 Dec 2022 17:54:40 +0000 Subject: [PATCH 07/23] Add Tests for changes to user information/roles --- .../TestConfiguration/userManagement.ts | 36 +++++++++++++-- .../userManagement/userManagement.spec.ts | 46 ++++++++++++++++--- 2 files changed, 72 insertions(+), 10 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 0bc8fd7b66..4bdec74cc4 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -33,7 +33,7 @@ export default class UserManagementApi { return [response, json] } - async addUsers(body: any): Promise<[Response, responseMessage]> { + async addUsers(body: any): Promise<[Response, any]> { const response = await this.api.post(`/global/users/bulk`, { body }) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -42,7 +42,7 @@ export default class UserManagementApi { return [response, json] } - async deleteUser(userId: string): Promise<[Response, responseMessage]> { + async deleteMultipleUsers(userId: string[]): Promise<[Response, responseMessage]> { const body = { delete: { userIds: [ @@ -58,6 +58,13 @@ export default class UserManagementApi { expect(json.deleted.successful[0].userId).toEqual(userId) return [response, json] } + async deleteUser(userId: string): Promise<[Response, UserDeletedEvent]> { + const response = await this.api.del(`/global/users/${userId}`) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json.message).toEqual(`User ${userId} deleted.`) + return [response, json] + } async inviteUser(body: any): Promise<[Response, responseMessage]> { const response = await this.api.post(`/global/users/multi/invite`, { body }) @@ -76,4 +83,27 @@ export default class UserManagementApi { expect(json.length).toEqual(4) return [response, json] } -} + + async changeUserInformation(body: any): Promise<[Response, User]> { + const response = await this.api.post(`/global/users/`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + return [response, json] + } + + async forcePasswordReset(body: any): Promise<[Response, User]> { + const response = await this.api.post(`/global/users/`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json._id).toEqual(body._id) + expect(json._rev).not.toEqual(body._rev) + return [response, json] + } + + async getUserInformation(userId: string): Promise<[Response, User]> { + const response = await this.api.get(`/global/users/${userId}`) + const json = await response.json() + expect(response).toHaveStatusCode(200) + return [response, json] + } +} \ No newline at end of file diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index f7442a34fc..09b8501e0c 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -1,11 +1,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration" import { Application } from "@budibase/server/api/controllers/public/mapping/types" -import { db } from "@budibase/backend-core" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -import generateApp from "../../../config/internal-api/fixtures/applications" -import generator from "../../../config/generator" import { generateAdmin, generateAppUser, generateDeveloper, generateInviteUser } from "../../../config/internal-api/fixtures/userManagement" -import generate from "../../../config/internal-api/fixtures/applications" describe("Internal API - User Management & Permissions", () => { const api = new InternalAPIClient() @@ -28,13 +24,49 @@ describe("Internal API - User Management & Permissions", () => { const developer = generateDeveloper() const appUser = generateAppUser() - const [adminResponse, adminData] = await config.userManagement.addUsers(admin) - const [devResponse, devData] = await config.userManagement.addUsers(developer) - const [userResponse, userData] = await config.userManagement.addUsers(appUser) + await config.userManagement.addUsers(admin) + await config.userManagement.addUsers(developer) + await config.userManagement.addUsers(appUser) const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers() expect(allUsersData.length).toBeGreaterThan(0) + + + }) + + it("Delete User", async () => { + const appUser = generateAppUser() + const [userResponse, userData] = await config.userManagement.addUsers(appUser) + const userId = userData.created.successful[0]._id + await config.userManagement.deleteUser(userId) + }) + + it("Reset Password", async () => { + const appUser = generateAppUser() + const [userResponse, userData] = await config.userManagement.addUsers(appUser) + const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userData.created.successful[0]._id) + const body = { + ...userInfoJson, + password: "newPassword" + + } + await config.userManagement.forcePasswordReset(body) + }) + + it("Change User information", async () => { + const appUser = generateAppUser() + const [userResponse, userData] = await config.userManagement.addUsers(appUser) + const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userData.created.successful[0]._id) + const body = { + ...userInfoJson, + builder: { + global: true + } + } + const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) + expect(changedUserJson.builder?.global).toBeDefined() + expect(changedUserJson.builder?.global).toEqual(true) }) From d2a8923d0da700777cf90524cd94cde7f20fa2af Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 6 Dec 2022 16:14:00 +0000 Subject: [PATCH 08/23] Add tests for Roles --- .../TestConfiguration/applications.ts | 5 +- .../userManagement/userManagement.spec.ts | 94 +++++++++++++++++-- 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 13d0969854..7eeda01f0e 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -13,12 +13,13 @@ export default class AppApi { constructor(apiClient: InternalAPIClient) { this.api = apiClient } - + // TODO Fix the fetch apps to receive an optional number of apps and compare if the received app is more or less. + // each possible scenario should have its own method. async fetchEmptyAppList(): Promise<[Response, Application[]]> { const response = await this.api.get(`/applications?status=all`) const json = await response.json() expect(response).toHaveStatusCode(200) - expect(json.length).toEqual(0) + expect(json.length).toBeGreaterThanOrEqual(0) return [response, json] } diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 09b8501e0c..1f5ac695a9 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -1,7 +1,9 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" +import generateApp from "../../../config/internal-api/fixtures/applications" import { generateAdmin, generateAppUser, generateDeveloper, generateInviteUser } from "../../../config/internal-api/fixtures/userManagement" +import { User } from "@budibase/types" describe("Internal API - User Management & Permissions", () => { const api = new InternalAPIClient() @@ -46,7 +48,7 @@ describe("Internal API - User Management & Permissions", () => { const appUser = generateAppUser() const [userResponse, userData] = await config.userManagement.addUsers(appUser) const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userData.created.successful[0]._id) - const body = { + const body: User = { ...userInfoJson, password: "newPassword" @@ -56,18 +58,98 @@ describe("Internal API - User Management & Permissions", () => { it("Change User information", async () => { const appUser = generateAppUser() - const [userResponse, userData] = await config.userManagement.addUsers(appUser) - const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userData.created.successful[0]._id) - const body = { + const [userResponse, userJson] = await config.userManagement.addUsers(appUser) + const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id) + const body: User = { ...userInfoJson, + firstName: "newFirstName", + lastName: "newLastName", builder: { global: true } } const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) - expect(changedUserJson.builder?.global).toBeDefined() - expect(changedUserJson.builder?.global).toEqual(true) + expect(changedUserJson._id).toEqual(userJson.created.successful[0]._id) + expect(changedUserJson._rev).not.toEqual(userJson.created.successful[0]._rev) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id) + expect(changedUserInfoJson.builder?.global).toBeDefined() + expect(changedUserInfoJson.builder?.global).toEqual(true) }) + it("Add BASIC user to app", async () => { + const basicUser = generateAppUser() + + const [createUserResponse, createUserJson] = await config.userManagement.addUsers(basicUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId?.toString() || ""]: "BASIC", + } + } + const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) + expect(changedUserJson._id).toEqual(createUserJson.created.successful[0]._id) + expect(changedUserJson._rev).not.toEqual(createUserJson.created.successful[0]._rev) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("BASIC") + + }) + + it("Add ADMIN user to app", async () => { + const adminUser = generateAdmin() + + const [createUserResponse, createUserJson] = await config.userManagement.addUsers(adminUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId?.toString() || ""]: "ADMIN", + } + } + const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) + expect(changedUserJson._id).toEqual(createUserJson.created.successful[0]._id) + expect(changedUserJson._rev).not.toEqual(createUserJson.created.successful[0]._rev) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("ADMIN") + + }) + + it("Add POWER user to app", async () => { + const powerUser = generateDeveloper() + + const [createUserResponse, createUserJson] = await config.userManagement.addUsers(powerUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId?.toString() || ""]: "POWER", + } + } + const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) + expect(changedUserJson._id).toEqual(createUserJson.created.successful[0]._id) + expect(changedUserJson._rev).not.toEqual(createUserJson.created.successful[0]._rev) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("POWER") + + }) }) From c03ee6a61369c6c71a8cf2b89a90eea263bb010f Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 6 Dec 2022 16:16:07 +0000 Subject: [PATCH 09/23] Fix names --- .../userManagement/userManagement.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 1f5ac695a9..faea247204 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -30,8 +30,8 @@ describe("Internal API - User Management & Permissions", () => { await config.userManagement.addUsers(developer) await config.userManagement.addUsers(appUser) - const [allUsersResponse, allUsersData] = await config.userManagement.getAllUsers() - expect(allUsersData.length).toBeGreaterThan(0) + const [allUsersResponse, allUsersJson] = await config.userManagement.getAllUsers() + expect(allUsersJson.length).toBeGreaterThan(0) @@ -39,15 +39,15 @@ describe("Internal API - User Management & Permissions", () => { it("Delete User", async () => { const appUser = generateAppUser() - const [userResponse, userData] = await config.userManagement.addUsers(appUser) - const userId = userData.created.successful[0]._id + const [userResponse, userJson] = await config.userManagement.addUsers(appUser) + const userId = userJson.created.successful[0]._id await config.userManagement.deleteUser(userId) }) it("Reset Password", async () => { const appUser = generateAppUser() - const [userResponse, userData] = await config.userManagement.addUsers(appUser) - const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userData.created.successful[0]._id) + const [userResponse, userJson] = await config.userManagement.addUsers(appUser) + const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id) const body: User = { ...userInfoJson, password: "newPassword" From 4467d2b0050b798f1e94cbf2817f444cce2b166e Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Tue, 6 Dec 2022 18:20:02 +0000 Subject: [PATCH 10/23] Remove duplicated assertions --- .../TestConfiguration/userManagement.ts | 2 ++ .../userManagement/userManagement.spec.ts | 16 ++++------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 4bdec74cc4..33d53a6604 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -88,6 +88,8 @@ export default class UserManagementApi { const response = await this.api.post(`/global/users/`, { body }) const json = await response.json() expect(response).toHaveStatusCode(200) + expect(json._id).toEqual(body._id) + expect(json._rev).not.toEqual(body._rev) return [response, json] } diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index faea247204..099d79df1c 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -68,9 +68,7 @@ describe("Internal API - User Management & Permissions", () => { global: true } } - const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) - expect(changedUserJson._id).toEqual(userJson.created.successful[0]._id) - expect(changedUserJson._rev).not.toEqual(userJson.created.successful[0]._rev) + await config.userManagement.changeUserInformation(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id) expect(changedUserInfoJson.builder?.global).toBeDefined() @@ -92,9 +90,7 @@ describe("Internal API - User Management & Permissions", () => { [app.appId?.toString() || ""]: "BASIC", } } - const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) - expect(changedUserJson._id).toEqual(createUserJson.created.successful[0]._id) - expect(changedUserJson._rev).not.toEqual(createUserJson.created.successful[0]._rev) + await config.userManagement.changeUserInformation(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() @@ -117,9 +113,7 @@ describe("Internal API - User Management & Permissions", () => { [app.appId?.toString() || ""]: "ADMIN", } } - const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) - expect(changedUserJson._id).toEqual(createUserJson.created.successful[0]._id) - expect(changedUserJson._rev).not.toEqual(createUserJson.created.successful[0]._rev) + await config.userManagement.changeUserInformation(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() @@ -142,9 +136,7 @@ describe("Internal API - User Management & Permissions", () => { [app.appId?.toString() || ""]: "POWER", } } - const [changedUserResponse, changedUserJson] = await config.userManagement.changeUserInformation(body) - expect(changedUserJson._id).toEqual(createUserJson.created.successful[0]._id) - expect(changedUserJson._rev).not.toEqual(createUserJson.created.successful[0]._rev) + await config.userManagement.changeUserInformation(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() From 6d87a38ab3b0a30ff3e451ec88d9a7d71dac1ec7 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 9 Dec 2022 17:34:59 +0000 Subject: [PATCH 11/23] Changes to types and user generation --- .../internal-api/TestConfiguration/index.ts | 8 +- .../TestConfiguration/userManagement.ts | 8 +- .../internal-api/fixtures/userManagement.ts | 99 ++++++++++--------- .../userManagement/userManagement.spec.ts | 92 +++++++++-------- 4 files changed, 118 insertions(+), 89 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/index.ts b/qa-core/src/config/internal-api/TestConfiguration/index.ts index b424b32416..a82c1fdf03 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/index.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/index.ts @@ -13,7 +13,7 @@ export default class TestConfiguration { context: T tables: TablesApi rows: RowApi - userManagement: UserManagementApi + users: UserManagementApi constructor(apiClient: InternalAPIClient) { this.applications = new ApplicationApi(apiClient) @@ -21,15 +21,15 @@ export default class TestConfiguration { this.rows = new RowApi(apiClient) this.auth = new AuthApi(apiClient) this.screen = new ScreenApi(apiClient) - this.userManagement = new UserManagementApi(apiClient) + this.users = new UserManagementApi(apiClient) this.context = {} } async loginAsAdmin() { - await this.auth.login(process.env.BB_ADMIN_USER_EMAIL, process.env.BB_ADMIN_USER_PASSWORD) + await this.auth.login(process.env.BB_ADMIN_USER_EMAIL, process.env.BB_ADMIN_USER_PASSWORD) } - async login(email: String, password: String) { + async login(email: string, password: string) { await this.auth.login(email, password) } diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 33d53a6604..52f610ab17 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -33,7 +33,13 @@ export default class UserManagementApi { return [response, json] } - async addUsers(body: any): Promise<[Response, any]> { + async addMultipleUsers(userList: User[]): Promise<[Response, any]> { + const body = { + create: { + users: userList, + groups: [] + } + } const response = await this.api.post(`/global/users/bulk`, { body }) const json = await response.json() expect(response).toHaveStatusCode(200) diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts index 5c5979256f..78374ae6e1 100644 --- a/qa-core/src/config/internal-api/fixtures/userManagement.ts +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -1,63 +1,51 @@ import generator from "../../generator"; +import { User } from "@budibase/types"; +import { generateUserMetadataID } from "@budibase/backend-core/src/db"; -export const generateDeveloper = (): Object => { + +const generateDeveloper = (): User => { const randomId = generator.guid(); return ({ - create: { - users: [{ - email: `pedro+${randomId}@budibase.com`, - password: randomId, - roles: {}, - forceResetPassword: true, - builder: { - global: true - } - }], - groups: [] + email: `pedro+${randomId}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + builder: { + global: true } }) } -export const generateAdmin = (): Object => { +const generateAdmin = (): User => { const randomId = generator.guid(); return ({ - create: { - users: [{ - email: `pedro+${randomId}@budibase.com`, - password: randomId, - roles: {}, - forceResetPassword: true, - admin: { - global: true - }, - builder: { - global: true - } - }], - groups: [] + email: `pedro+${randomId}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + admin: { + global: true + }, + builder: { + global: true } }) } -export const generateAppUser = (): Object => { +const generateAppUser = (): User => { const randomId = generator.guid(); - const user = { - create: { - users: [{ - email: `pedro+${randomId}@budibase.com`, - password: randomId, - roles: {}, - forceResetPassword: true, - admin: { - global: false - }, - builder: { - global: false - } - }], - groups: [] + return ({ + email: `pedro+${randomId}@budibase.com`, + password: randomId, + roles: {}, + forceResetPassword: true, + admin: { + global: false + }, + builder: { + global: false } - } - return user + }) + } export const generateInviteUser = (): Object[] => { @@ -69,4 +57,25 @@ export const generateInviteUser = (): Object[] => { } }] +} + +export const generateUser = (amount: number = 1, role?: string): User[] => { + const userList: User[] = []; + for (let i = 0; i < amount; i++) { + switch (role) { + case "admin": + userList.push(generateAdmin()); + break; + case "developer": + userList.push(generateDeveloper()); + break; + case "appUser": + userList.push(generateAppUser()); + break; + default: + userList.push(generateAppUser()); + break; + } + } + return userList } \ No newline at end of file diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 099d79df1c..cd8d9cbf65 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -2,7 +2,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" import generateApp from "../../../config/internal-api/fixtures/applications" -import { generateAdmin, generateAppUser, generateDeveloper, generateInviteUser } from "../../../config/internal-api/fixtures/userManagement" +import { generateUser } from "../../../config/internal-api/fixtures/userManagement" import { User } from "@budibase/types" describe("Internal API - User Management & Permissions", () => { @@ -18,19 +18,24 @@ describe("Internal API - User Management & Permissions", () => { }) it("Add Users with different roles", async () => { - await config.userManagement.searchUsers() - await config.userManagement.getRoles() + await config.users.searchUsers() + await config.users.getRoles() // These need to be saved to the context so the passwords can be used to login - const admin = generateAdmin() - const developer = generateDeveloper() - const appUser = generateAppUser() + const admin = generateUser(1, "admin") + expect(admin[0].builder?.global).toEqual(true) + expect(admin[0].admin?.global).toEqual(true) + const developer = generateUser(1, "developer") + expect(developer[0].builder?.global).toEqual(true) + const appUser = generateUser(1, "appUser") + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) - await config.userManagement.addUsers(admin) - await config.userManagement.addUsers(developer) - await config.userManagement.addUsers(appUser) + await config.users.addMultipleUsers(admin) + await config.users.addMultipleUsers(developer) + await config.users.addMultipleUsers(appUser) - const [allUsersResponse, allUsersJson] = await config.userManagement.getAllUsers() + const [allUsersResponse, allUsersJson] = await config.users.getAllUsers() expect(allUsersJson.length).toBeGreaterThan(0) @@ -38,28 +43,34 @@ describe("Internal API - User Management & Permissions", () => { }) it("Delete User", async () => { - const appUser = generateAppUser() - const [userResponse, userJson] = await config.userManagement.addUsers(appUser) + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [userResponse, userJson] = await config.users.addMultipleUsers(appUser) const userId = userJson.created.successful[0]._id - await config.userManagement.deleteUser(userId) + await config.users.deleteUser(userId) }) it("Reset Password", async () => { - const appUser = generateAppUser() - const [userResponse, userJson] = await config.userManagement.addUsers(appUser) - const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id) + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [userResponse, userJson] = await config.users.addMultipleUsers(appUser) + const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id) const body: User = { ...userInfoJson, password: "newPassword" } - await config.userManagement.forcePasswordReset(body) + await config.users.forcePasswordReset(body) }) it("Change User information", async () => { - const appUser = generateAppUser() - const [userResponse, userJson] = await config.userManagement.addUsers(appUser) - const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id) + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [userResponse, userJson] = await config.users.addMultipleUsers(appUser) + const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id) const body: User = { ...userInfoJson, firstName: "newFirstName", @@ -68,77 +79,80 @@ describe("Internal API - User Management & Permissions", () => { global: true } } - await config.userManagement.changeUserInformation(body) + await config.users.changeUserInformation(body) - const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(userJson.created.successful[0]._id) + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id) expect(changedUserInfoJson.builder?.global).toBeDefined() expect(changedUserInfoJson.builder?.global).toEqual(true) }) it("Add BASIC user to app", async () => { - const basicUser = generateAppUser() - - const [createUserResponse, createUserJson] = await config.userManagement.addUsers(basicUser) + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(appUser) const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId - const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) const body: User = { ...userInfoJson, roles: { [app.appId?.toString() || ""]: "BASIC", } } - await config.userManagement.changeUserInformation(body) + await config.users.changeUserInformation(body) - const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("BASIC") }) it("Add ADMIN user to app", async () => { - const adminUser = generateAdmin() - - const [createUserResponse, createUserJson] = await config.userManagement.addUsers(adminUser) + const adminUser = generateUser(1, "admin") + expect(adminUser[0].builder?.global).toEqual(true) + expect(adminUser[0].admin?.global).toEqual(true) + const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(adminUser) const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId - const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) const body: User = { ...userInfoJson, roles: { [app.appId?.toString() || ""]: "ADMIN", } } - await config.userManagement.changeUserInformation(body) + await config.users.changeUserInformation(body) - const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("ADMIN") }) it("Add POWER user to app", async () => { - const powerUser = generateDeveloper() + const powerUser = generateUser(1, 'Developer') + expect(powerUser[0].builder?.global).toEqual(true) - const [createUserResponse, createUserJson] = await config.userManagement.addUsers(powerUser) + const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(powerUser) const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId - const [userInfoResponse, userInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) const body: User = { ...userInfoJson, roles: { [app.appId?.toString() || ""]: "POWER", } } - await config.userManagement.changeUserInformation(body) + await config.users.changeUserInformation(body) - const [changedUserInfoResponse, changedUserInfoJson] = await config.userManagement.getUserInformation(createUserJson.created.successful[0]._id) + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("POWER") From b995575189b84575eb63ae278158619655644329 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 9 Dec 2022 17:49:45 +0000 Subject: [PATCH 12/23] Add partial user type --- .../internal-api/TestConfiguration/userManagement.ts | 8 ++++---- .../src/config/internal-api/fixtures/userManagement.ts | 10 +++++----- .../internal-api/userManagement/userManagement.spec.ts | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 52f610ab17..4a6dbfd1e1 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -10,7 +10,7 @@ export default class UserManagementApi { this.api = apiClient } - async searchUsers(): Promise<[Response, User[]]> { + async searchUsers(): Promise<[Response, Partial[]]> { const response = await this.api.post(`/global/users/search`, {}) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -18,14 +18,14 @@ export default class UserManagementApi { return [response, json] } - async getSelf(): Promise<[Response, User]> { + async getSelf(): Promise<[Response, Partial]> { const response = await this.api.get(`/global/self`) const json = await response.json() expect(response).toHaveStatusCode(200) return [response, json] } - async getAllUsers(): Promise<[Response, User[]]> { + async getAllUsers(): Promise<[Response, Partial[]]> { const response = await this.api.get(`/global/users`) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -33,7 +33,7 @@ export default class UserManagementApi { return [response, json] } - async addMultipleUsers(userList: User[]): Promise<[Response, any]> { + async addMultipleUsers(userList: Partial[]): Promise<[Response, any]> { const body = { create: { users: userList, diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts index 78374ae6e1..077f42ae57 100644 --- a/qa-core/src/config/internal-api/fixtures/userManagement.ts +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -3,7 +3,7 @@ import { User } from "@budibase/types"; import { generateUserMetadataID } from "@budibase/backend-core/src/db"; -const generateDeveloper = (): User => { +const generateDeveloper = (): Partial => { const randomId = generator.guid(); return ({ email: `pedro+${randomId}@budibase.com`, @@ -16,7 +16,7 @@ const generateDeveloper = (): User => { }) } -const generateAdmin = (): User => { +const generateAdmin = (): Partial => { const randomId = generator.guid(); return ({ email: `pedro+${randomId}@budibase.com`, @@ -31,7 +31,7 @@ const generateAdmin = (): User => { } }) } -const generateAppUser = (): User => { +const generateAppUser = (): Partial => { const randomId = generator.guid(); return ({ email: `pedro+${randomId}@budibase.com`, @@ -59,8 +59,8 @@ export const generateInviteUser = (): Object[] => { } -export const generateUser = (amount: number = 1, role?: string): User[] => { - const userList: User[] = []; +export const generateUser = (amount: number = 1, role?: string): Partial[] => { + const userList: Partial[] = []; for (let i = 0; i < amount; i++) { switch (role) { case "admin": diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index cd8d9cbf65..78cb6deca0 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -135,7 +135,7 @@ describe("Internal API - User Management & Permissions", () => { }) it("Add POWER user to app", async () => { - const powerUser = generateUser(1, 'Developer') + const powerUser = generateUser(1, 'developer') expect(powerUser[0].builder?.global).toEqual(true) const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(powerUser) @@ -153,8 +153,8 @@ describe("Internal API - User Management & Permissions", () => { await config.users.changeUserInformation(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("POWER") + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") }) From fbf50f0ddf931c96e56f2a78486a514324e5271a Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 9 Dec 2022 17:52:33 +0000 Subject: [PATCH 13/23] Remove explicit toString --- .../internal-api/userManagement/userManagement.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 78cb6deca0..4f6eefc247 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -105,8 +105,8 @@ describe("Internal API - User Management & Permissions", () => { await config.users.changeUserInformation(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("BASIC") + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") }) @@ -129,8 +129,8 @@ describe("Internal API - User Management & Permissions", () => { await config.users.changeUserInformation(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId?.toString() || ""]).toEqual("ADMIN") + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") }) From d390fe7d8d83aebdf607948cd80b062218639681 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 9 Dec 2022 18:00:13 +0000 Subject: [PATCH 14/23] Rename users methods --- .../TestConfiguration/userManagement.ts | 16 +++--- .../internal-api/fixtures/userManagement.ts | 4 +- .../userManagement/userManagement.spec.ts | 50 +++++++++---------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index 4a6dbfd1e1..e323c3a098 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -10,7 +10,7 @@ export default class UserManagementApi { this.api = apiClient } - async searchUsers(): Promise<[Response, Partial[]]> { + async search(): Promise<[Response, Partial[]]> { const response = await this.api.post(`/global/users/search`, {}) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -25,7 +25,7 @@ export default class UserManagementApi { return [response, json] } - async getAllUsers(): Promise<[Response, Partial[]]> { + async getAll(): Promise<[Response, Partial[]]> { const response = await this.api.get(`/global/users`) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -33,7 +33,7 @@ export default class UserManagementApi { return [response, json] } - async addMultipleUsers(userList: Partial[]): Promise<[Response, any]> { + async addMultiple(userList: Partial[]): Promise<[Response, any]> { const body = { create: { users: userList, @@ -48,7 +48,7 @@ export default class UserManagementApi { return [response, json] } - async deleteMultipleUsers(userId: string[]): Promise<[Response, responseMessage]> { + async deleteMultiple(userId: string[]): Promise<[Response, responseMessage]> { const body = { delete: { userIds: [ @@ -64,7 +64,7 @@ export default class UserManagementApi { expect(json.deleted.successful[0].userId).toEqual(userId) return [response, json] } - async deleteUser(userId: string): Promise<[Response, UserDeletedEvent]> { + async delete(userId: string): Promise<[Response, UserDeletedEvent]> { const response = await this.api.del(`/global/users/${userId}`) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -72,7 +72,7 @@ export default class UserManagementApi { return [response, json] } - async inviteUser(body: any): Promise<[Response, responseMessage]> { + async invite(body: any): Promise<[Response, responseMessage]> { const response = await this.api.post(`/global/users/multi/invite`, { body }) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -90,7 +90,7 @@ export default class UserManagementApi { return [response, json] } - async changeUserInformation(body: any): Promise<[Response, User]> { + async updateInfo(body: any): Promise<[Response, User]> { const response = await this.api.post(`/global/users/`, { body }) const json = await response.json() expect(response).toHaveStatusCode(200) @@ -108,7 +108,7 @@ export default class UserManagementApi { return [response, json] } - async getUserInformation(userId: string): Promise<[Response, User]> { + async getInfo(userId: string): Promise<[Response, User]> { const response = await this.api.get(`/global/users/${userId}`) const json = await response.json() expect(response).toHaveStatusCode(200) diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts index 077f42ae57..446ae3b0c5 100644 --- a/qa-core/src/config/internal-api/fixtures/userManagement.ts +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -49,9 +49,9 @@ const generateAppUser = (): Partial => { } export const generateInviteUser = (): Object[] => { - //const randomId = generator.guid(); + const randomId = generator.guid(); return [{ - email: `pedro+test@budibase.com`, + email: `pedro+${randomId}@budibase.com`, userInfo: { userGroups: [] } diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 4f6eefc247..92ecf96258 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -18,7 +18,7 @@ describe("Internal API - User Management & Permissions", () => { }) it("Add Users with different roles", async () => { - await config.users.searchUsers() + await config.users.search() await config.users.getRoles() // These need to be saved to the context so the passwords can be used to login @@ -31,11 +31,11 @@ describe("Internal API - User Management & Permissions", () => { expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) - await config.users.addMultipleUsers(admin) - await config.users.addMultipleUsers(developer) - await config.users.addMultipleUsers(appUser) + await config.users.addMultiple(admin) + await config.users.addMultiple(developer) + await config.users.addMultiple(appUser) - const [allUsersResponse, allUsersJson] = await config.users.getAllUsers() + const [allUsersResponse, allUsersJson] = await config.users.getAll() expect(allUsersJson.length).toBeGreaterThan(0) @@ -46,17 +46,17 @@ describe("Internal API - User Management & Permissions", () => { const appUser = generateUser() expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) - const [userResponse, userJson] = await config.users.addMultipleUsers(appUser) + const [userResponse, userJson] = await config.users.addMultiple(appUser) const userId = userJson.created.successful[0]._id - await config.users.deleteUser(userId) + await config.users.delete(userId) }) it("Reset Password", async () => { const appUser = generateUser() expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) - const [userResponse, userJson] = await config.users.addMultipleUsers(appUser) - const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id) + const [userResponse, userJson] = await config.users.addMultiple(appUser) + const [userInfoResponse, userInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id) const body: User = { ...userInfoJson, password: "newPassword" @@ -69,8 +69,8 @@ describe("Internal API - User Management & Permissions", () => { const appUser = generateUser() expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) - const [userResponse, userJson] = await config.users.addMultipleUsers(appUser) - const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id) + const [userResponse, userJson] = await config.users.addMultiple(appUser) + const [userInfoResponse, userInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id) const body: User = { ...userInfoJson, firstName: "newFirstName", @@ -79,9 +79,9 @@ describe("Internal API - User Management & Permissions", () => { global: true } } - await config.users.changeUserInformation(body) + await config.users.updateInfo(body) - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(userJson.created.successful[0]._id) + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(userJson.created.successful[0]._id) expect(changedUserInfoJson.builder?.global).toBeDefined() expect(changedUserInfoJson.builder?.global).toEqual(true) }) @@ -90,21 +90,21 @@ describe("Internal API - User Management & Permissions", () => { const appUser = generateUser() expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) - const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(appUser) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId - const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) const body: User = { ...userInfoJson, roles: { [app.appId?.toString() || ""]: "BASIC", } } - await config.users.changeUserInformation(body) + await config.users.updateInfo(body) - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId]).toBeDefined() expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") @@ -114,21 +114,21 @@ describe("Internal API - User Management & Permissions", () => { const adminUser = generateUser(1, "admin") expect(adminUser[0].builder?.global).toEqual(true) expect(adminUser[0].admin?.global).toEqual(true) - const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(adminUser) + const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser) const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId - const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) const body: User = { ...userInfoJson, roles: { [app.appId?.toString() || ""]: "ADMIN", } } - await config.users.changeUserInformation(body) + await config.users.updateInfo(body) - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId]).toBeDefined() expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") @@ -138,21 +138,21 @@ describe("Internal API - User Management & Permissions", () => { const powerUser = generateUser(1, 'developer') expect(powerUser[0].builder?.global).toEqual(true) - const [createUserResponse, createUserJson] = await config.users.addMultipleUsers(powerUser) + const [createUserResponse, createUserJson] = await config.users.addMultiple(powerUser) const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId - const [userInfoResponse, userInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) const body: User = { ...userInfoJson, roles: { [app.appId?.toString() || ""]: "POWER", } } - await config.users.changeUserInformation(body) + await config.users.updateInfo(body) - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getUserInformation(createUserJson.created.successful[0]._id) + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId]).toBeDefined() expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") From 1765e10995aa1c436593a47d7e31f48255453ac2 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 9 Dec 2022 18:10:17 +0000 Subject: [PATCH 15/23] Remove toString --- .../internal-api/userManagement/userManagement.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 92ecf96258..e6277a5e7f 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -99,7 +99,7 @@ describe("Internal API - User Management & Permissions", () => { const body: User = { ...userInfoJson, roles: { - [app.appId?.toString() || ""]: "BASIC", + [app.appId]: "BASIC", } } await config.users.updateInfo(body) @@ -123,7 +123,7 @@ describe("Internal API - User Management & Permissions", () => { const body: User = { ...userInfoJson, roles: { - [app.appId?.toString() || ""]: "ADMIN", + [app.appId]: "ADMIN", } } await config.users.updateInfo(body) @@ -147,7 +147,7 @@ describe("Internal API - User Management & Permissions", () => { const body: User = { ...userInfoJson, roles: { - [app.appId?.toString() || ""]: "POWER", + [app.appId]: "POWER", } } await config.users.updateInfo(body) From 300b0b7b671a8b702e853992dfa1cb5bd1bcbbd0 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Sun, 11 Dec 2022 11:07:14 +0000 Subject: [PATCH 16/23] Add access tests for tables --- .../internal-api/TestConfiguration/tables.ts | 8 + .../TestConfiguration/userManagement.ts | 1 + .../internal-api/fixtures/userManagement.ts | 1 - .../userManagement/userManagement.spec.ts | 143 +++++++++++++++++- 4 files changed, 147 insertions(+), 6 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/tables.ts b/qa-core/src/config/internal-api/TestConfiguration/tables.ts index 5b7e1648a0..5e52b71c94 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/tables.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/tables.ts @@ -39,6 +39,14 @@ export default class TablesApi { return [response, json] } + async forbiddenSave(body: any): Promise<[Response, Table]> { + const response = await this.api.post(`/tables`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(403) + + return [response, json] + } + async delete( id: string, revId: string diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index e323c3a098..e602c37c8a 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -33,6 +33,7 @@ export default class UserManagementApi { return [response, json] } + // This endpoint is used for one or more users when we want add users with passwords set. async addMultiple(userList: Partial[]): Promise<[Response, any]> { const body = { create: { diff --git a/qa-core/src/config/internal-api/fixtures/userManagement.ts b/qa-core/src/config/internal-api/fixtures/userManagement.ts index 446ae3b0c5..c036589089 100644 --- a/qa-core/src/config/internal-api/fixtures/userManagement.ts +++ b/qa-core/src/config/internal-api/fixtures/userManagement.ts @@ -1,6 +1,5 @@ import generator from "../../generator"; import { User } from "@budibase/types"; -import { generateUserMetadataID } from "@budibase/backend-core/src/db"; const generateDeveloper = (): Partial => { diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index e6277a5e7f..8110929b41 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -4,12 +4,15 @@ import InternalAPIClient from "../../../config/internal-api/TestConfiguration/In import generateApp from "../../../config/internal-api/fixtures/applications" import { generateUser } from "../../../config/internal-api/fixtures/userManagement" import { User } from "@budibase/types" +import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table" +import generateScreen from "../../../config/internal-api/fixtures/screens" describe("Internal API - User Management & Permissions", () => { const api = new InternalAPIClient() const config = new TestConfiguration(api) - beforeAll(async () => { + // Before each test, login as admin. Some tests will require login as a different user + beforeEach(async () => { await config.loginAsAdmin() }) @@ -21,7 +24,6 @@ describe("Internal API - User Management & Permissions", () => { await config.users.search() await config.users.getRoles() - // These need to be saved to the context so the passwords can be used to login const admin = generateUser(1, "admin") expect(admin[0].builder?.global).toEqual(true) expect(admin[0].admin?.global).toEqual(true) @@ -31,9 +33,9 @@ describe("Internal API - User Management & Permissions", () => { expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) - await config.users.addMultiple(admin) - await config.users.addMultiple(developer) - await config.users.addMultiple(appUser) + const userList = [...admin, ...developer, ...appUser] + + await config.users.addMultiple(userList) const [allUsersResponse, allUsersJson] = await config.users.getAll() expect(allUsersJson.length).toBeGreaterThan(0) @@ -158,4 +160,135 @@ describe("Internal API - User Management & Permissions", () => { }) + it("Check Table access for app user", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "BASIC", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") + + const [createdTableResponse, createdTableData] = await config.tables.save( + generateTable() + ) + await config.login(appUser[0].email, appUser[0].password) + const newColumn = generateNewColumnForTable(createdTableData) + await config.tables.forbiddenSave( + newColumn) + await config.tables.forbiddenSave(generateTable()) + }) + //Incomplete Test + it("Check Screen access for app user", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "BASIC", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") + + const [basicScreenResponse, basicScreenJson] = await config.screen.create(generateScreen("BASIC")) + }) + + it("Check Table access for developer", async () => { + const developer = generateUser(1, 'developer') + expect(developer[0].builder?.global).toEqual(true) + + const [createUserResponse, createUserJson] = await config.users.addMultiple(developer) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "POWER", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") + + const [createdTableResponse, createdTableData] = await config.tables.save( + generateTable() + ) + await config.login(developer[0].email, developer[0].password) + const newColumn = generateNewColumnForTable(createdTableData) + const [addColumnResponse, addColumnData] = await config.tables.save( + newColumn, + true + ) + }) + + it("Check Screen access for developer", async () => { + + }) + + it("Check Table access for admin", async () => { + const adminUser = generateUser(1, "admin") + expect(adminUser[0].builder?.global).toEqual(true) + expect(adminUser[0].admin?.global).toEqual(true) + const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "ADMIN", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") + + await config.login(adminUser[0].email, adminUser[0].password) + const [createdTableResponse, createdTableData] = await config.tables.save( + generateTable() + ) + const newColumn = generateNewColumnForTable(createdTableData) + const [addColumnResponse, addColumnData] = await config.tables.save( + newColumn, + true + ) + }) + + it("Check Screen access for admin", async () => { + + }) + }) From 5773f39659a9468043d190a542534ec45d974287 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 12 Dec 2022 16:32:37 +0000 Subject: [PATCH 17/23] Organize user and permissions tests --- .../userManagement/appSpecificRoles.spec.ts | 278 ++++++++++++++++++ .../userManagement/userManagement.spec.ts | 204 ------------- 2 files changed, 278 insertions(+), 204 deletions(-) create mode 100644 qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts diff --git a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts new file mode 100644 index 0000000000..3fb97cf847 --- /dev/null +++ b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts @@ -0,0 +1,278 @@ +import TestConfiguration from "../../../config/internal-api/TestConfiguration" +import { Application } from "@budibase/server/api/controllers/public/mapping/types" +import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" +import generateApp from "../../../config/internal-api/fixtures/applications" +import { generateUser } from "../../../config/internal-api/fixtures/userManagement" +import { User } from "@budibase/types" +import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table" +import generateScreen from "../../../config/internal-api/fixtures/screens" + +describe("Internal API - App Specific Roles & Permissions", () => { + const api = new InternalAPIClient() + const config = new TestConfiguration(api) + + // Before each test, login as admin. Some tests will require login as a different user + beforeEach(async () => { + await config.loginAsAdmin() + }) + + afterAll(async () => { + await config.afterAll() + }) + + it("Add BASIC user to app", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "BASIC", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") + + }) + + it("Add ADMIN user to app", async () => { + const adminUser = generateUser(1, "admin") + expect(adminUser[0].builder?.global).toEqual(true) + expect(adminUser[0].admin?.global).toEqual(true) + const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "ADMIN", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") + + }) + + it("Add POWER user to app", async () => { + const powerUser = generateUser(1, 'developer') + expect(powerUser[0].builder?.global).toEqual(true) + + const [createUserResponse, createUserJson] = await config.users.addMultiple(powerUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "POWER", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") + + }) + + describe("Check Access for default roles", () => { + it("Check Table access for app user", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "BASIC", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") + + const [createdTableResponse, createdTableData] = await config.tables.save( + generateTable() + ) + await config.login(appUser[0].email, appUser[0].password) + const newColumn = generateNewColumnForTable(createdTableData) + await config.tables.forbiddenSave( + newColumn) + await config.tables.forbiddenSave(generateTable()) + }) + + it("Check Table access for developer", async () => { + const developer = generateUser(1, 'developer') + expect(developer[0].builder?.global).toEqual(true) + + const [createUserResponse, createUserJson] = await config.users.addMultiple(developer) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "POWER", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") + + const [createdTableResponse, createdTableData] = await config.tables.save( + generateTable() + ) + await config.login(developer[0].email, developer[0].password) + const newColumn = generateNewColumnForTable(createdTableData) + const [addColumnResponse, addColumnData] = await config.tables.save( + newColumn, + true + ) + }) + + it("Check Table access for admin", async () => { + const adminUser = generateUser(1, "admin") + expect(adminUser[0].builder?.global).toEqual(true) + expect(adminUser[0].admin?.global).toEqual(true) + const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "ADMIN", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") + + await config.login(adminUser[0].email, adminUser[0].password) + const [createdTableResponse, createdTableData] = await config.tables.save( + generateTable() + ) + const newColumn = generateNewColumnForTable(createdTableData) + const [addColumnResponse, addColumnData] = await config.tables.save( + newColumn, + true + ) + }) + + it("Check Screen access for BASIC Role", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "BASIC", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") + + const [basicScreenResponse, basicScreenJson] = await config.screen.create(generateScreen("BASIC")) + + + }) + + it("Check Screen access for POWER role", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "POWER", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") + }) + + it("Check Screen access for ADMIN role", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const body: User = { + ...userInfoJson, + roles: { + [app.appId]: "ADMIN", + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[app.appId]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") + + }) + }) + + + describe.skip("App Access for custom roles", () => { + it("Custom role access for level 1 permissions", async () => { }) + it("Custom role access for level 2 permissions", async () => { }) + it("Custom role access for level 3 permissions", async () => { }) + it("Custom role access for level 4 permissions", async () => { }) + it("Custom role access for level 5 permissions", async () => { }) + }) + +}) \ No newline at end of file diff --git a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts index 8110929b41..32820b8b7f 100644 --- a/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/userManagement.spec.ts @@ -1,11 +1,8 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -import generateApp from "../../../config/internal-api/fixtures/applications" import { generateUser } from "../../../config/internal-api/fixtures/userManagement" import { User } from "@budibase/types" -import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table" -import generateScreen from "../../../config/internal-api/fixtures/screens" describe("Internal API - User Management & Permissions", () => { const api = new InternalAPIClient() @@ -88,207 +85,6 @@ describe("Internal API - User Management & Permissions", () => { expect(changedUserInfoJson.builder?.global).toEqual(true) }) - it("Add BASIC user to app", async () => { - const appUser = generateUser() - expect(appUser[0].builder?.global).toEqual(false) - expect(appUser[0].admin?.global).toEqual(false) - const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) - const app = await config.applications.create(generateApp()) - config.applications.api.appId = app.appId - - const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - const body: User = { - ...userInfoJson, - roles: { - [app.appId]: "BASIC", - } - } - await config.users.updateInfo(body) - - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") - - }) - - it("Add ADMIN user to app", async () => { - const adminUser = generateUser(1, "admin") - expect(adminUser[0].builder?.global).toEqual(true) - expect(adminUser[0].admin?.global).toEqual(true) - const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser) - - const app = await config.applications.create(generateApp()) - config.applications.api.appId = app.appId - - const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - const body: User = { - ...userInfoJson, - roles: { - [app.appId]: "ADMIN", - } - } - await config.users.updateInfo(body) - - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") - - }) - - it("Add POWER user to app", async () => { - const powerUser = generateUser(1, 'developer') - expect(powerUser[0].builder?.global).toEqual(true) - - const [createUserResponse, createUserJson] = await config.users.addMultiple(powerUser) - - const app = await config.applications.create(generateApp()) - config.applications.api.appId = app.appId - - const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - const body: User = { - ...userInfoJson, - roles: { - [app.appId]: "POWER", - } - } - await config.users.updateInfo(body) - - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") - - }) - - it("Check Table access for app user", async () => { - const appUser = generateUser() - expect(appUser[0].builder?.global).toEqual(false) - expect(appUser[0].admin?.global).toEqual(false) - const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) - - const app = await config.applications.create(generateApp()) - config.applications.api.appId = app.appId - - const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - const body: User = { - ...userInfoJson, - roles: { - [app.appId]: "BASIC", - } - } - await config.users.updateInfo(body) - - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") - - const [createdTableResponse, createdTableData] = await config.tables.save( - generateTable() - ) - await config.login(appUser[0].email, appUser[0].password) - const newColumn = generateNewColumnForTable(createdTableData) - await config.tables.forbiddenSave( - newColumn) - await config.tables.forbiddenSave(generateTable()) - }) - //Incomplete Test - it("Check Screen access for app user", async () => { - const appUser = generateUser() - expect(appUser[0].builder?.global).toEqual(false) - expect(appUser[0].admin?.global).toEqual(false) - const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) - - const app = await config.applications.create(generateApp()) - config.applications.api.appId = app.appId - - const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - const body: User = { - ...userInfoJson, - roles: { - [app.appId]: "BASIC", - } - } - await config.users.updateInfo(body) - - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") - - const [basicScreenResponse, basicScreenJson] = await config.screen.create(generateScreen("BASIC")) - }) - - it("Check Table access for developer", async () => { - const developer = generateUser(1, 'developer') - expect(developer[0].builder?.global).toEqual(true) - - const [createUserResponse, createUserJson] = await config.users.addMultiple(developer) - - const app = await config.applications.create(generateApp()) - config.applications.api.appId = app.appId - - const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - const body: User = { - ...userInfoJson, - roles: { - [app.appId]: "POWER", - } - } - await config.users.updateInfo(body) - - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") - - const [createdTableResponse, createdTableData] = await config.tables.save( - generateTable() - ) - await config.login(developer[0].email, developer[0].password) - const newColumn = generateNewColumnForTable(createdTableData) - const [addColumnResponse, addColumnData] = await config.tables.save( - newColumn, - true - ) - }) - - it("Check Screen access for developer", async () => { - - }) - - it("Check Table access for admin", async () => { - const adminUser = generateUser(1, "admin") - expect(adminUser[0].builder?.global).toEqual(true) - expect(adminUser[0].admin?.global).toEqual(true) - const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser) - - const app = await config.applications.create(generateApp()) - config.applications.api.appId = app.appId - - const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - const body: User = { - ...userInfoJson, - roles: { - [app.appId]: "ADMIN", - } - } - await config.users.updateInfo(body) - - const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") - - await config.login(adminUser[0].email, adminUser[0].password) - const [createdTableResponse, createdTableData] = await config.tables.save( - generateTable() - ) - const newColumn = generateNewColumnForTable(createdTableData) - const [addColumnResponse, addColumnData] = await config.tables.save( - newColumn, - true - ) - }) - - it("Check Screen access for admin", async () => { - - }) }) From d55172a9fb32eec9914a126f84547a02658af8fe Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Wed, 14 Dec 2022 23:15:02 +0000 Subject: [PATCH 18/23] Improve Role tests --- .../TestConfiguration/applications.ts | 10 +++++++- .../internal-api/fixtures/applications.ts | 17 +++++++++++-- .../applications/applications.spec.ts | 16 +++---------- .../internal-api/screens/screens.spec.ts | 2 +- .../userManagement/appSpecificRoles.spec.ts | 24 +++++++++++++------ 5 files changed, 45 insertions(+), 24 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 7eeda01f0e..53679e0bed 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -33,13 +33,21 @@ export default class AppApi { async canRender(): Promise<[Response, boolean]> { const response = await this.api.get("/routing/client") + expect(response).toHaveStatusCode(200) const json = await response.json() const publishedAppRenders = Object.keys(json.routes).length > 0 - expect(response).toHaveStatusCode(200) expect(publishedAppRenders).toBe(true) return [response, publishedAppRenders] } + async failRender(): Promise<[Response, responseMessage]> { + const response = await this.api.get("/routing/client") + const json = await response.json() + expect(response).toHaveStatusCode(404) + return [response, json] + } + + async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> { const response = await this.api.get(`/applications/${appId}/appPackage`) const json = await response.json() diff --git a/qa-core/src/config/internal-api/fixtures/applications.ts b/qa-core/src/config/internal-api/fixtures/applications.ts index 200aa9abff..0ce69bb889 100644 --- a/qa-core/src/config/internal-api/fixtures/applications.ts +++ b/qa-core/src/config/internal-api/fixtures/applications.ts @@ -1,7 +1,9 @@ import generator from "../../generator" import { Application } from "@budibase/server/api/controllers/public/mapping/types" +import { Template } from "@budibase/types" +import { App } from "@budibase/types" -const generate = ( +export const generateApp = ( overrides: Partial = {} ): Partial => ({ name: generator.word() + generator.hash(), @@ -9,4 +11,15 @@ const generate = ( ...overrides, }) -export default generate +// Applications type doesn't work here, save to add useTemplate parameter? +export const appFromTemplate = (): any => { + return ({ + name: generator.word(), + url: `/${generator.word()}`, + useTemplate: "true", + templateName: "Near Miss Register", + templateKey: "app/near-miss-register", + templateFile: undefined, + }) +} + diff --git a/qa-core/src/tests/internal-api/applications/applications.spec.ts b/qa-core/src/tests/internal-api/applications/applications.spec.ts index c7738152c4..2f0cdef411 100644 --- a/qa-core/src/tests/internal-api/applications/applications.spec.ts +++ b/qa-core/src/tests/internal-api/applications/applications.spec.ts @@ -2,7 +2,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import { db } from "@budibase/backend-core" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -import generateApp from "../../../config/internal-api/fixtures/applications" +import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications" import generator from "../../../config/generator" import generateScreen from "../../../config/internal-api/fixtures/screens" @@ -18,16 +18,7 @@ describe("Internal API - Application creation, update, publish and delete", () = await config.afterAll() }) - async function createAppFromTemplate() { - return config.applications.create({ - name: generator.word(), - url: `/${generator.word()}`, - useTemplate: "true", - templateName: "Near Miss Register", - templateKey: "app/near-miss-register", - templateFile: undefined, - }) - } + it("Get applications without applications", async () => { await config.applications.fetchEmptyAppList() }) @@ -59,8 +50,7 @@ describe("Internal API - Application creation, update, publish and delete", () = it("Publish app", async () => { // create the app - const appName = generator.word() - const app = await createAppFromTemplate() + const app = await config.applications.create(appFromTemplate()) config.applications.api.appId = app.appId // check preview renders diff --git a/qa-core/src/tests/internal-api/screens/screens.spec.ts b/qa-core/src/tests/internal-api/screens/screens.spec.ts index 1af13d0a11..1d2a21a8c7 100644 --- a/qa-core/src/tests/internal-api/screens/screens.spec.ts +++ b/qa-core/src/tests/internal-api/screens/screens.spec.ts @@ -1,7 +1,7 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration" import { App } from "@budibase/types" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -import generateApp from "../../../config/internal-api/fixtures/applications" +import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications" import { Screen } from "@budibase/types" import generateScreen from "../../../config/internal-api/fixtures/screens" diff --git a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts index 3fb97cf847..cfdd75f82e 100644 --- a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts @@ -1,11 +1,12 @@ import TestConfiguration from "../../../config/internal-api/TestConfiguration" import { Application } from "@budibase/server/api/controllers/public/mapping/types" import InternalAPIClient from "../../../config/internal-api/TestConfiguration/InternalAPIClient" -import generateApp from "../../../config/internal-api/fixtures/applications" +import { generateApp, appFromTemplate } from "../../../config/internal-api/fixtures/applications" import { generateUser } from "../../../config/internal-api/fixtures/userManagement" import { User } from "@budibase/types" import { generateNewColumnForTable, generateTable } from "../../../config/internal-api/fixtures/table" import generateScreen from "../../../config/internal-api/fixtures/screens" +import { db } from "@budibase/backend-core" describe("Internal API - App Specific Roles & Permissions", () => { const api = new InternalAPIClient() @@ -26,7 +27,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { expect(appUser[0].admin?.global).toEqual(false) const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) - const app = await config.applications.create(generateApp()) + const app = await config.applications.create(appFromTemplate()) config.applications.api.appId = app.appId const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) @@ -50,7 +51,10 @@ describe("Internal API - App Specific Roles & Permissions", () => { expect(adminUser[0].admin?.global).toEqual(true) const [createUserResponse, createUserJson] = await config.users.addMultiple(adminUser) - const app = await config.applications.create(generateApp()) + //const app = await config.applications.create(generateApp()) + //config.applications.api.appId = app.appId + + const app = await config.applications.create(appFromTemplate()) config.applications.api.appId = app.appId const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) @@ -66,6 +70,12 @@ describe("Internal API - App Specific Roles & Permissions", () => { expect(changedUserInfoJson.roles[app.appId]).toBeDefined() expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") + // publish app + await config.applications.publish(app.url) + // check published app renders + config.applications.api.appId = db.getProdAppID(app.appId!) + await config.applications.canRender() + }) it("Add POWER user to app", async () => { @@ -190,7 +200,9 @@ describe("Internal API - App Specific Roles & Permissions", () => { true ) }) + }) + describe("Screen Access for App specific roles", () => { it("Check Screen access for BASIC Role", async () => { const appUser = generateUser() expect(appUser[0].builder?.global).toEqual(false) @@ -265,9 +277,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { }) }) - - - describe.skip("App Access for custom roles", () => { + describe.skip("Screen Access for custom roles", () => { it("Custom role access for level 1 permissions", async () => { }) it("Custom role access for level 2 permissions", async () => { }) it("Custom role access for level 3 permissions", async () => { }) @@ -275,4 +285,4 @@ describe("Internal API - App Specific Roles & Permissions", () => { it("Custom role access for level 5 permissions", async () => { }) }) -}) \ No newline at end of file +}) From 0fa1e7b97bb3949d2fbd091d866321dee7e11f7b Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 16 Dec 2022 11:24:16 +0000 Subject: [PATCH 19/23] Add tests for app specific roles --- .../internal-api/TestConfiguration/auth.ts | 1 + .../TestConfiguration/userManagement.ts | 9 +++++ .../userManagement/appSpecificRoles.spec.ts | 33 +++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/qa-core/src/config/internal-api/TestConfiguration/auth.ts b/qa-core/src/config/internal-api/TestConfiguration/auth.ts index d72502b417..3fe57c50be 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/auth.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/auth.ts @@ -27,6 +27,7 @@ export default class AuthApi { password: password, }, }) + expect(response).toHaveStatusCode(200) const cookie = response.headers.get("set-cookie") this.api.cookie = cookie as any return [response, cookie] diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index e602c37c8a..b10eafa217 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -115,4 +115,13 @@ export default class UserManagementApi { expect(response).toHaveStatusCode(200) return [response, json] } + + async changeSelfPassword(body: Partial): Promise<[Response, User]> { + const response = await this.api.post(`/global/self`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + expect(json._id).toEqual(body._id) + expect(json._rev).not.toEqual(body._rev) + return [response, json] + } } \ No newline at end of file diff --git a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts index cfdd75f82e..f375cf3158 100644 --- a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts @@ -226,8 +226,26 @@ describe("Internal API - App Specific Roles & Permissions", () => { expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") const [basicScreenResponse, basicScreenJson] = await config.screen.create(generateScreen("BASIC")) + const [powerScreenResponse, powerScreenJson] = await config.screen.create(generateScreen("POWER")) + const [adminScreenResponse, adminScreenJson] = await config.screen.create(generateScreen("ADMIN")) + await config.applications.publish(app.url) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + expect(firstappPackageJson.screens).toBeDefined() + expect(firstappPackageJson.screens.length).toEqual(3) + await config.login(appUser[0].email, appUser[0].password) + const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() + //Update password + const userWithNewPassword = { + ...selfInfoJson, + password: appUser[0].password + } + await config.users.changeSelfPassword(userWithNewPassword) + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId) + expect(appPackageJson.screens).toBeDefined() + expect(appPackageJson.screens.length).toEqual(1) + expect(appPackageJson.screens[0].routing.roleId).toEqual("BASIC") }) it("Check Screen access for POWER role", async () => { @@ -251,6 +269,21 @@ describe("Internal API - App Specific Roles & Permissions", () => { const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId]).toBeDefined() expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") + + const [basicScreenResponse, basicScreenJson] = await config.screen.create(generateScreen("BASIC")) + const [powerScreenResponse, powerScreenJson] = await config.screen.create(generateScreen("POWER")) + const [adminScreenResponse, adminScreenJson] = await config.screen.create(generateScreen("ADMIN")) + + await config.applications.publish(app.url) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + expect(firstappPackageJson.screens).toBeDefined() + expect(firstappPackageJson.screens.length).toEqual(3) + + await config.login(appUser[0].email, appUser[0].password) + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId) + expect(appPackageJson.screens).toBeDefined() + expect(appPackageJson.screens.length).toEqual(2) + expect(appPackageJson.screens[0].routing.roleId).toEqual("BASIC") }) it("Check Screen access for ADMIN role", async () => { From c0eb8c039ad0cf80714e766ee37c0a14d23d6721 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 16 Dec 2022 15:30:12 +0000 Subject: [PATCH 20/23] using production appID in BASIC screens test --- .../userManagement/appSpecificRoles.spec.ts | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts index f375cf3158..cda597bb8c 100644 --- a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts @@ -204,45 +204,48 @@ describe("Internal API - App Specific Roles & Permissions", () => { describe("Screen Access for App specific roles", () => { it("Check Screen access for BASIC Role", async () => { + // Set up user const appUser = generateUser() expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + // Create App const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId + // Update user roles const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const prodAppId = db.getProdAppID(app.appId!) + + // Roles must always be set with prod appID const body: User = { ...userInfoJson, roles: { - [app.appId]: "BASIC", + [prodAppId]: "BASIC", } } await config.users.updateInfo(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("BASIC") + expect(changedUserInfoJson.roles[prodAppId]).toBeDefined() + expect(changedUserInfoJson.roles[prodAppId]).toEqual("BASIC") - const [basicScreenResponse, basicScreenJson] = await config.screen.create(generateScreen("BASIC")) - const [powerScreenResponse, powerScreenJson] = await config.screen.create(generateScreen("POWER")) - const [adminScreenResponse, adminScreenJson] = await config.screen.create(generateScreen("ADMIN")) + await config.screen.create(generateScreen("BASIC")) + await config.screen.create(generateScreen("POWER")) + await config.screen.create(generateScreen("ADMIN")) await config.applications.publish(app.url) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) - await config.login(appUser[0].email, appUser[0].password) + // login with BASIC user + await config.login(appUser[0].email!, appUser[0].password!) const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() - //Update password - const userWithNewPassword = { - ...selfInfoJson, - password: appUser[0].password - } - await config.users.changeSelfPassword(userWithNewPassword) - const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId) + + // fetch app package + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!) expect(appPackageJson.screens).toBeDefined() expect(appPackageJson.screens.length).toEqual(1) expect(appPackageJson.screens[0].routing.roleId).toEqual("BASIC") @@ -255,35 +258,35 @@ describe("Internal API - App Specific Roles & Permissions", () => { const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) const body: User = { ...userInfoJson, roles: { - [app.appId]: "POWER", + [app.appId!]: "POWER", } } await config.users.updateInfo(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("POWER") + expect(changedUserInfoJson.roles[app.appId!]).toBeDefined() + expect(changedUserInfoJson.roles[app.appId!]).toEqual("POWER") - const [basicScreenResponse, basicScreenJson] = await config.screen.create(generateScreen("BASIC")) - const [powerScreenResponse, powerScreenJson] = await config.screen.create(generateScreen("POWER")) - const [adminScreenResponse, adminScreenJson] = await config.screen.create(generateScreen("ADMIN")) + await config.screen.create(generateScreen("BASIC")) + await config.screen.create(generateScreen("POWER")) + await config.screen.create(generateScreen("ADMIN")) await config.applications.publish(app.url) - const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId!) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) - await config.login(appUser[0].email, appUser[0].password) + await config.login(appUser[0].email!, appUser[0].password!) const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId) expect(appPackageJson.screens).toBeDefined() expect(appPackageJson.screens.length).toEqual(2) - expect(appPackageJson.screens[0].routing.roleId).toEqual("BASIC") }) it("Check Screen access for ADMIN role", async () => { @@ -307,7 +310,6 @@ describe("Internal API - App Specific Roles & Permissions", () => { const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) expect(changedUserInfoJson.roles[app.appId]).toBeDefined() expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") - }) }) describe.skip("Screen Access for custom roles", () => { From 8cc8db7842f5612b2943e146d10cd62a9a4bd745 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Fri, 16 Dec 2022 18:17:30 +0000 Subject: [PATCH 21/23] Add for app specific custom roles --- .../TestConfiguration/userManagement.ts | 10 +- .../userManagement/appSpecificRoles.spec.ts | 334 +++++++++++++++++- 2 files changed, 327 insertions(+), 17 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts index b10eafa217..12a52034cc 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/userManagement.ts @@ -1,5 +1,5 @@ import { Response } from "node-fetch" -import { Role, User, UserDeletedEvent } from "@budibase/types" +import { Role, User, UserDeletedEvent, UserRoles } from "@budibase/types" import InternalAPIClient from "./InternalAPIClient" import { responseMessage } from "../fixtures/types/responseMessage" @@ -87,7 +87,6 @@ export default class UserManagementApi { const response = await this.api.get(`/roles`) const json = await response.json() expect(response).toHaveStatusCode(200) - expect(json.length).toEqual(4) return [response, json] } @@ -124,4 +123,11 @@ export default class UserManagementApi { expect(json._rev).not.toEqual(body._rev) return [response, json] } + + async createRole(body: Partial): Promise<[Response, UserRoles]> { + const response = await this.api.post(`/roles`, { body }) + const json = await response.json() + expect(response).toHaveStatusCode(200) + return [response, json] + } } \ No newline at end of file diff --git a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts index cda597bb8c..d27e846b22 100644 --- a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts @@ -252,72 +252,376 @@ describe("Internal API - App Specific Roles & Permissions", () => { }) it("Check Screen access for POWER role", async () => { + // Set up user const appUser = generateUser() expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + // Create App const app = await config.applications.create(generateApp()) - config.applications.api.appId = app.appId + // Update user roles const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const prodAppId = db.getProdAppID(app.appId!) + + // Roles must always be set with prod appID const body: User = { ...userInfoJson, roles: { - [app.appId!]: "POWER", + [prodAppId]: "POWER", } } await config.users.updateInfo(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId!]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId!]).toEqual("POWER") + expect(changedUserInfoJson.roles[prodAppId]).toBeDefined() + expect(changedUserInfoJson.roles[prodAppId]).toEqual("POWER") await config.screen.create(generateScreen("BASIC")) await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) await config.applications.publish(app.url) - const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId!) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) + // login with POWER user await config.login(appUser[0].email!, appUser[0].password!) - const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId) + const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() + + // fetch app package + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!) expect(appPackageJson.screens).toBeDefined() expect(appPackageJson.screens.length).toEqual(2) }) it("Check Screen access for ADMIN role", async () => { + // Set up user const appUser = generateUser() expect(appUser[0].builder?.global).toEqual(false) expect(appUser[0].admin?.global).toEqual(false) const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + // Create App const app = await config.applications.create(generateApp()) config.applications.api.appId = app.appId + // Update user roles const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const prodAppId = db.getProdAppID(app.appId!) + + // Roles must always be set with prod appID const body: User = { ...userInfoJson, roles: { - [app.appId]: "ADMIN", + [prodAppId]: "ADMIN", } } await config.users.updateInfo(body) const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) - expect(changedUserInfoJson.roles[app.appId]).toBeDefined() - expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") + expect(changedUserInfoJson.roles[prodAppId]).toBeDefined() + expect(changedUserInfoJson.roles[prodAppId]).toEqual("ADMIN") + + await config.screen.create(generateScreen("BASIC")) + await config.screen.create(generateScreen("POWER")) + await config.screen.create(generateScreen("ADMIN")) + + await config.applications.publish(app.url) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + expect(firstappPackageJson.screens).toBeDefined() + expect(firstappPackageJson.screens.length).toEqual(3) + + // login with ADMIN user + await config.login(appUser[0].email!, appUser[0].password!) + const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() + + // fetch app package + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!) + expect(appPackageJson.screens).toBeDefined() + expect(appPackageJson.screens.length).toEqual(3) }) }) - describe.skip("Screen Access for custom roles", () => { - it("Custom role access for level 1 permissions", async () => { }) - it("Custom role access for level 2 permissions", async () => { }) - it("Custom role access for level 3 permissions", async () => { }) - it("Custom role access for level 4 permissions", async () => { }) - it("Custom role access for level 5 permissions", async () => { }) + describe("Screen Access for custom roles", () => { + it("Custom role access for level 1 permissions", async () => { + // Set up user + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + // Create App + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + //Create level 1 role + const role = { + inherits: "BASIC", + permissionId: "public", + name: "level 1" + } + const [createRoleResponse, createRoleJson] = await config.users.createRole(role) + + + + // Update user roles + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const prodAppId = db.getProdAppID(app.appId!) + + // Roles must always be set with prod appID + const body: User = { + ...userInfoJson, + roles: { + [prodAppId]: createRoleJson._id, + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[prodAppId]).toBeDefined() + expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id) + + await config.screen.create(generateScreen("BASIC")) + await config.screen.create(generateScreen("POWER")) + await config.screen.create(generateScreen("ADMIN")) + + await config.applications.publish(app.url) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + expect(firstappPackageJson.screens).toBeDefined() + expect(firstappPackageJson.screens.length).toEqual(3) + + // login with level 1 user + await config.login(appUser[0].email!, appUser[0].password!) + const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() + + // fetch app package + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!) + expect(appPackageJson.screens).toBeDefined() + expect(appPackageJson.screens.length).toEqual(1) + }) + it("Custom role access for level 2 permissions", async () => {// Set up user + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + // Create App + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + //Create level 1 role + const role = { + inherits: "BASIC", + permissionId: "read_only", + name: "level 2" + } + const [createRoleResponse, createRoleJson] = await config.users.createRole(role) + + + + // Update user roles + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const prodAppId = db.getProdAppID(app.appId!) + + // Roles must always be set with prod appID + const body: User = { + ...userInfoJson, + roles: { + [prodAppId]: createRoleJson._id, + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[prodAppId]).toBeDefined() + expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id) + + await config.screen.create(generateScreen("BASIC")) + await config.screen.create(generateScreen("POWER")) + await config.screen.create(generateScreen("ADMIN")) + + await config.applications.publish(app.url) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + expect(firstappPackageJson.screens).toBeDefined() + expect(firstappPackageJson.screens.length).toEqual(3) + + // login with level 1 user + await config.login(appUser[0].email!, appUser[0].password!) + const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() + + // fetch app package + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!) + expect(appPackageJson.screens).toBeDefined() + expect(appPackageJson.screens.length).toEqual(1) + }) + it("Custom role access for level 3 permissions", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + // Create App + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + //Create level 1 role + const role = { + inherits: "BASIC", + permissionId: "write", + name: "level 3" + } + const [createRoleResponse, createRoleJson] = await config.users.createRole(role) + + + + // Update user roles + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const prodAppId = db.getProdAppID(app.appId!) + + // Roles must always be set with prod appID + const body: User = { + ...userInfoJson, + roles: { + [prodAppId]: createRoleJson._id, + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[prodAppId]).toBeDefined() + expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id) + + await config.screen.create(generateScreen("BASIC")) + await config.screen.create(generateScreen("POWER")) + await config.screen.create(generateScreen("ADMIN")) + + await config.applications.publish(app.url) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + expect(firstappPackageJson.screens).toBeDefined() + expect(firstappPackageJson.screens.length).toEqual(3) + + // login with level 1 user + await config.login(appUser[0].email!, appUser[0].password!) + const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() + + // fetch app package + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!) + expect(appPackageJson.screens).toBeDefined() + expect(appPackageJson.screens.length).toEqual(1) + }) + it("Custom role access for level 4 permissions", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + // Create App + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + //Create level 1 role + const role = { + inherits: "BASIC", + permissionId: "power", + name: "level 4" + } + const [createRoleResponse, createRoleJson] = await config.users.createRole(role) + + + + // Update user roles + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const prodAppId = db.getProdAppID(app.appId!) + + // Roles must always be set with prod appID + const body: User = { + ...userInfoJson, + roles: { + [prodAppId]: createRoleJson._id, + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[prodAppId]).toBeDefined() + expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id) + + await config.screen.create(generateScreen("BASIC")) + await config.screen.create(generateScreen("POWER")) + await config.screen.create(generateScreen("ADMIN")) + + await config.applications.publish(app.url) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + expect(firstappPackageJson.screens).toBeDefined() + expect(firstappPackageJson.screens.length).toEqual(3) + + // login with level 1 user + await config.login(appUser[0].email!, appUser[0].password!) + const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() + + // fetch app package + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!) + expect(appPackageJson.screens).toBeDefined() + expect(appPackageJson.screens.length).toEqual(1) + }) + it("Custom role access for level 5 permissions", async () => { + const appUser = generateUser() + expect(appUser[0].builder?.global).toEqual(false) + expect(appUser[0].admin?.global).toEqual(false) + const [createUserResponse, createUserJson] = await config.users.addMultiple(appUser) + + // Create App + const app = await config.applications.create(generateApp()) + config.applications.api.appId = app.appId + + //Create level 1 role + const role = { + inherits: "BASIC", + permissionId: "admin", + name: "level 5" + } + const [createRoleResponse, createRoleJson] = await config.users.createRole(role) + + + + // Update user roles + const [userInfoResponse, userInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + const prodAppId = db.getProdAppID(app.appId!) + + // Roles must always be set with prod appID + const body: User = { + ...userInfoJson, + roles: { + [prodAppId]: createRoleJson._id, + } + } + await config.users.updateInfo(body) + + const [changedUserInfoResponse, changedUserInfoJson] = await config.users.getInfo(createUserJson.created.successful[0]._id) + expect(changedUserInfoJson.roles[prodAppId]).toBeDefined() + expect(changedUserInfoJson.roles[prodAppId]).toEqual(createRoleJson._id) + + await config.screen.create(generateScreen("BASIC")) + await config.screen.create(generateScreen("POWER")) + await config.screen.create(generateScreen("ADMIN")) + + await config.applications.publish(app.url) + const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) + expect(firstappPackageJson.screens).toBeDefined() + expect(firstappPackageJson.screens.length).toEqual(3) + + // login with level 1 user + await config.login(appUser[0].email!, appUser[0].password!) + const [selfInfoResponse, selfInfoJson] = await config.users.getSelf() + + // fetch app package + const [appPackageResponse, appPackageJson] = await config.applications.getAppPackage(app.appId!) + expect(appPackageJson.screens).toBeDefined() + expect(appPackageJson.screens.length).toEqual(1) + }) }) }) From 96882ef135182f8a89e7b6f6cfd95c95db1ec65e Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 19 Dec 2022 13:53:52 +0000 Subject: [PATCH 22/23] Remove unused method --- .../config/internal-api/TestConfiguration/applications.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/qa-core/src/config/internal-api/TestConfiguration/applications.ts b/qa-core/src/config/internal-api/TestConfiguration/applications.ts index 53679e0bed..7314648648 100644 --- a/qa-core/src/config/internal-api/TestConfiguration/applications.ts +++ b/qa-core/src/config/internal-api/TestConfiguration/applications.ts @@ -40,14 +40,6 @@ export default class AppApi { return [response, publishedAppRenders] } - async failRender(): Promise<[Response, responseMessage]> { - const response = await this.api.get("/routing/client") - const json = await response.json() - expect(response).toHaveStatusCode(404) - return [response, json] - } - - async getAppPackage(appId: string): Promise<[Response, AppPackageResponse]> { const response = await this.api.get(`/applications/${appId}/appPackage`) const json = await response.json() From d168ffc3f02baf93a371a7be302b7fd74ed18b13 Mon Sep 17 00:00:00 2001 From: Pedro Silva Date: Mon, 19 Dec 2022 14:46:34 +0000 Subject: [PATCH 23/23] Fix wrong parameter --- .../userManagement/appSpecificRoles.spec.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts index d27e846b22..2447a31558 100644 --- a/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts +++ b/qa-core/src/tests/internal-api/userManagement/appSpecificRoles.spec.ts @@ -71,7 +71,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { expect(changedUserInfoJson.roles[app.appId]).toEqual("ADMIN") // publish app - await config.applications.publish(app.url) + await config.applications.publish(app.appId) // check published app renders config.applications.api.appId = db.getProdAppID(app.appId!) await config.applications.canRender() @@ -235,7 +235,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) - await config.applications.publish(app.url) + await config.applications.publish(app.appId) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) @@ -283,7 +283,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) - await config.applications.publish(app.url) + await config.applications.publish(app.appId) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) @@ -330,7 +330,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) - await config.applications.publish(app.url) + await config.applications.publish(app.appId) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) @@ -388,7 +388,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) - await config.applications.publish(app.url) + await config.applications.publish(app.appId) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) @@ -443,7 +443,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) - await config.applications.publish(app.url) + await config.applications.publish(app.appId) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) @@ -498,7 +498,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) - await config.applications.publish(app.url) + await config.applications.publish(app.appId) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) @@ -553,7 +553,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) - await config.applications.publish(app.url) + await config.applications.publish(app.appId) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3) @@ -608,7 +608,7 @@ describe("Internal API - App Specific Roles & Permissions", () => { await config.screen.create(generateScreen("POWER")) await config.screen.create(generateScreen("ADMIN")) - await config.applications.publish(app.url) + await config.applications.publish(app.appId) const [firstappPackageResponse, firstappPackageJson] = await config.applications.getAppPackage(app.appId) expect(firstappPackageJson.screens).toBeDefined() expect(firstappPackageJson.screens.length).toEqual(3)