|
|
@ -1,12 +1,14 @@ |
|
|
const { |
|
|
const { |
|
|
createApplication, |
|
|
createApplication, |
|
|
createTable, |
|
|
createTable, |
|
|
|
|
|
createRow, |
|
|
supertest, |
|
|
supertest, |
|
|
defaultHeaders, |
|
|
defaultHeaders, |
|
|
addPermission, |
|
|
addPermission, |
|
|
} = require("./couchTestUtils") |
|
|
} = require("./couchTestUtils") |
|
|
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles") |
|
|
const { BUILTIN_ROLE_IDS } = require("../../../utilities/security/roles") |
|
|
|
|
|
|
|
|
|
|
|
const HIGHER_ROLE_ID = BUILTIN_ROLE_IDS.BASIC |
|
|
const STD_ROLE_ID = BUILTIN_ROLE_IDS.PUBLIC |
|
|
const STD_ROLE_ID = BUILTIN_ROLE_IDS.PUBLIC |
|
|
|
|
|
|
|
|
describe("/permission", () => { |
|
|
describe("/permission", () => { |
|
|
@ -15,6 +17,7 @@ describe("/permission", () => { |
|
|
let appId |
|
|
let appId |
|
|
let table |
|
|
let table |
|
|
let perms |
|
|
let perms |
|
|
|
|
|
let row |
|
|
|
|
|
|
|
|
beforeAll(async () => { |
|
|
beforeAll(async () => { |
|
|
;({ request, server } = await supertest()) |
|
|
;({ request, server } = await supertest()) |
|
|
@ -29,8 +32,17 @@ describe("/permission", () => { |
|
|
appId = app.instance._id |
|
|
appId = app.instance._id |
|
|
table = await createTable(request, appId) |
|
|
table = await createTable(request, appId) |
|
|
perms = await addPermission(request, appId, STD_ROLE_ID, table._id) |
|
|
perms = await addPermission(request, appId, STD_ROLE_ID, table._id) |
|
|
|
|
|
row = await createRow(request, appId, table._id) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
async function getTablePermissions() { |
|
|
|
|
|
return request |
|
|
|
|
|
.get(`/api/permission/${table._id}`) |
|
|
|
|
|
.set(defaultHeaders(appId)) |
|
|
|
|
|
.expect("Content-Type", /json/) |
|
|
|
|
|
.expect(200) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
describe("levels", () => { |
|
|
describe("levels", () => { |
|
|
it("should be able to get levels", async () => { |
|
|
it("should be able to get levels", async () => { |
|
|
const res = await request |
|
|
const res = await request |
|
|
@ -45,7 +57,7 @@ describe("/permission", () => { |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe("test", () => { |
|
|
describe("add", () => { |
|
|
it("should be able to add permission to a role for the table", async () => { |
|
|
it("should be able to add permission to a role for the table", async () => { |
|
|
expect(perms.length).toEqual(1) |
|
|
expect(perms.length).toEqual(1) |
|
|
expect(perms[0]._id).toEqual(`${STD_ROLE_ID}`) |
|
|
expect(perms[0]._id).toEqual(`${STD_ROLE_ID}`) |
|
|
@ -57,6 +69,40 @@ describe("/permission", () => { |
|
|
.set(defaultHeaders(appId)) |
|
|
.set(defaultHeaders(appId)) |
|
|
.expect("Content-Type", /json/) |
|
|
.expect("Content-Type", /json/) |
|
|
.expect(200) |
|
|
.expect(200) |
|
|
|
|
|
expect(res.body[STD_ROLE_ID]).toEqual("read") |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
it("should get resource permissions with multiple roles", async () => { |
|
|
|
|
|
perms = await addPermission(request, appId, HIGHER_ROLE_ID, table._id, "write") |
|
|
|
|
|
const res = await getTablePermissions() |
|
|
|
|
|
expect(res.body[HIGHER_ROLE_ID]).toEqual("write") |
|
|
|
|
|
expect(res.body[STD_ROLE_ID]).toEqual("read") |
|
|
|
|
|
const allRes = await request |
|
|
|
|
|
.get(`/api/permission`) |
|
|
|
|
|
.set(defaultHeaders(appId)) |
|
|
|
|
|
.expect("Content-Type", /json/) |
|
|
|
|
|
.expect(200) |
|
|
|
|
|
expect(allRes.body[HIGHER_ROLE_ID][table._id]).toEqual("write") |
|
|
|
|
|
expect(allRes.body[STD_ROLE_ID][table._id]).toEqual("read") |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe("remove", () => { |
|
|
|
|
|
it("should be able to remove the permission", async () => { |
|
|
|
|
|
const res = await request |
|
|
|
|
|
.delete(`/api/permission/${STD_ROLE_ID}/${table._id}/read`) |
|
|
|
|
|
.set(defaultHeaders(appId)) |
|
|
|
|
|
.expect("Content-Type", /json/) |
|
|
|
|
|
.expect(200) |
|
|
|
|
|
expect(res.body[0]._id).toEqual(STD_ROLE_ID) |
|
|
|
|
|
const permsRes = await getTablePermissions() |
|
|
|
|
|
expect(permsRes.body[STD_ROLE_ID]).toBeUndefined() |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe("check public user allowed", () => { |
|
|
|
|
|
it("should be able to read the row", async () => { |
|
|
|
|
|
// TODO
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|