Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit acls #407

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import {SciLogDbApplication} from '../..';
import {
clearDatabase,
createAdminToken,
createAUser,
createToken,
createUserToken,
setupApplication,
} from './test-helper';
import _ from 'lodash';
import {arrayOfUniqueFrom} from '../../utils/misc';

describe('Basesnippet', function (this: Suite) {
this.timeout(5000);
Expand All @@ -16,7 +19,6 @@ describe('Basesnippet', function (this: Suite) {
let token: string;
let adminToken: string;
let baseSnippetId: string;
let nonVisibleSnippetId: string;
const baseSnippet = {
ownerGroup: 'basesnippetAcceptance',
createACL: ['basesnippetAcceptance'],
Expand Down Expand Up @@ -60,11 +62,14 @@ describe('Basesnippet', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(baseSnippet),
expect(result.body).to.containEql(_.omit(baseSnippet, 'updateACL')),
expect(result.body.snippetType).to.be.eql('base'),
expect(result.body.readACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.createACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.adminACL).to.be.eql(['admin']),
(baseSnippetId = result.body.id)
Expand Down Expand Up @@ -110,7 +115,13 @@ describe('Basesnippet', function (this: Suite) {
.then(
result => (
expect(result.body.length).to.be.eql(1),
expect(result.body[0]).to.containEql(baseSnippet)
expect(result.body[0]).to.containEql(
_.omit(baseSnippet, 'updateACL'),
),
expect(result.body[0].updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
])
),
)
.catch(err => {
Expand All @@ -131,7 +142,15 @@ describe('Basesnippet', function (this: Suite) {
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.expect(200)
.then(result => expect(result.body).to.containEql(baseSnippet))
.then(
result => (
expect(result.body).to.containEql(_.omit(baseSnippet, 'updateACL')),
expect(result.body.updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
])
),
)
.catch(err => {
throw err;
});
Expand Down Expand Up @@ -461,11 +480,16 @@ describe('Basesnippet', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(_.omit(baseSnippet, 'ownerGroup')),
expect(result.body).to.containEql(
_.omit(baseSnippet, ['ownerGroup', 'updateACL']),
),
expect(result.body.snippetType).to.be.eql('base'),
expect(result.body.readACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.createACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.shareACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.adminACL).to.be.eql(['admin'])
Expand Down Expand Up @@ -494,7 +518,7 @@ describe('Basesnippet', function (this: Suite) {
.expect(404);
});

it('post a basesnippet with authentication and parentId from existing snippet should return 200 and have ownergroup with priority on parent ACLS', async () => {
it('post a basesnippet with authentication and parentId from existing snippet should return 200 and append to parentACL', async () => {
await client
.post('/basesnippets')
.set('Authorization', 'Bearer ' + token)
Expand All @@ -503,11 +527,19 @@ describe('Basesnippet', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(baseSnippet),
expect(result.body).to.containEql(
_.omit(baseSnippet, ['createACL', 'updateACL']),
),
expect(result.body.snippetType).to.be.eql('base'),
expect(result.body.readACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.createACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.createACL).to.be.eql([
'basesnippetAcceptance',
'aNewCreateACL',
]),
expect(result.body.updateACL).to.be.eql([
'basesnippetAcceptance',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.shareACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.adminACL).to.be.eql(['admin'])
Expand All @@ -518,7 +550,7 @@ describe('Basesnippet', function (this: Suite) {
});
});

it('post a basesnippet with authentication and parentId from existing snippet setting explict ACLS should return 200 and have set ACLS with priority on ownergroup and parentACLs', async () => {
it('post a basesnippet with authentication and parentId from existing snippet setting explict ACLS should return 200 and have set ACLS merging parent and child', async () => {
await client
.post('/basesnippets')
.set('Authorization', 'Bearer ' + token)
Expand All @@ -533,17 +565,31 @@ describe('Basesnippet', function (this: Suite) {
.then(
result => (
expect(result.body).to.containEql({
..._.omit(baseSnippet, ['ownerGroup', 'readACL', 'updateACL']),
..._.omit(baseSnippet, [
'ownerGroup',
'readACL',
'updateACL',
'createACL',
]),
ownerGroup: 'aReadACL',
}),
expect(result.body.snippetType).to.be.eql('base'),
expect(result.body.readACL).to.be.eql(['aReadACL']),
expect(result.body.createACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.updateACL).to.be.eql(['anUpdateACL']),
expect(result.body.readACL).to.be.eql([
'aReadACL',
'basesnippetAcceptance',
]),
expect(result.body.createACL).to.be.eql([
'basesnippetAcceptance',
'aNewCreateACL',
]),
expect(result.body.updateACL).to.be.eql([
'anUpdateACL',
'basesnippetAcceptance',
'[email protected]',
]),
expect(result.body.deleteACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.shareACL).to.be.eql(['basesnippetAcceptance']),
expect(result.body.adminACL).to.be.eql(['admin']),
(nonVisibleSnippetId = result.body.id)
expect(result.body.adminACL).to.be.eql(['admin'])
),
)
.catch(err => {
Expand All @@ -552,11 +598,18 @@ describe('Basesnippet', function (this: Suite) {
});

it('get snippet with ID with token having changed readACL should return 404', async () => {
const unAuthUser = await createAUser(app, ['unAuthorised'], {
email: 'unauth.com',
firstName: 'un',
lastName: 'Auth',
roles: [],
});
const unAuthToken = await createToken(client, unAuthUser);
await client
.get(`/basesnippets/${nonVisibleSnippetId}`)
.set('Authorization', 'Bearer ' + token)
.get(`/basesnippets/${baseSnippetId}`)
.set('Authorization', 'Bearer ' + unAuthToken)
.set('Content-Type', 'application/json')
.expect(404);
.expect(403);
});

it('get snippet with token and ownerGroup filter should be greater than one', async () => {
Expand Down Expand Up @@ -750,14 +803,20 @@ describe('Basesnippet', function (this: Suite) {
.then(
result => (
expect(result.body.ownerGroup).to.be.eql('basesnippetAcceptance'),
expect(result.body.accessGroups).to.be.eql([
'basesnippetAcceptance',
'someNew',
]),
expect(result.body.readACL).to.be.eql([
'basesnippetAcceptance',
'someNew',
])
expect(result.body.accessGroups).to.be.eql(
arrayOfUniqueFrom(
'basesnippetAcceptance',
'someNew',
t.input.accessGroups,
),
),
expect(result.body.readACL).to.be.eql(
arrayOfUniqueFrom(
'basesnippetAcceptance',
'someNew',
t.input.accessGroups,
),
)
),
)
.catch(err => {
Expand Down Expand Up @@ -823,26 +882,6 @@ describe('Basesnippet', function (this: Suite) {
});
});

it(`patch snippet by id with non-authorised user should return 404`, async () => {
const bs = await client
.post('/basesnippets')
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.send({
..._.omit(baseSnippet, 'updateACL'),
updateACL: ['nonAuthorised'],
});
await client
.patch(`/basesnippets/${bs.body.id}`)
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.send({name: 'something'})
.expect(404)
.catch(err => {
throw err;
});
});

[404, 204].forEach(t => {
it(`delete snippet should return ${t}`, async () => {
await client
Expand Down
25 changes: 22 additions & 3 deletions sci-log-db/src/__tests__/acceptance/file.controller.acceptance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Client, expect} from '@loopback/testlab';
import {Suite} from 'mocha';
import {SciLogDbApplication} from '../..';
import {clearDatabase, createUserToken, setupApplication} from './test-helper';
import _ from 'lodash';

describe('File controller services', function (this: Suite) {
this.timeout(1000);
Expand Down Expand Up @@ -50,8 +51,12 @@ describe('File controller services', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(fileSnippet),
expect(result.body).to.containEql(_.omit(fileSnippet, 'updateACL')),
expect(result.body.snippetType).to.be.eql('image'),
expect(result.body.updateACL).to.be.eql([
'filesnippetAcceptance',
'[email protected]',
]),
(fileSnippetId = result.body.id)
),
)
Expand Down Expand Up @@ -95,7 +100,13 @@ describe('File controller services', function (this: Suite) {
.then(
result => (
expect(result.body.length).to.be.eql(1),
expect(result.body[0]).to.containEql(fileSnippet)
expect(result.body[0]).to.containEql(
_.omit(fileSnippet, 'updateACL'),
),
expect(result.body[0].updateACL).to.be.eql([
'filesnippetAcceptance',
'[email protected]',
])
),
)
.catch(err => {
Expand All @@ -116,7 +127,15 @@ describe('File controller services', function (this: Suite) {
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.expect(200)
.then(result => expect(result.body).to.containEql(fileSnippet))
.then(
result => (
expect(result.body).to.containEql(_.omit(fileSnippet, 'updateACL')),
expect(result.body.updateACL).to.be.eql([
'filesnippetAcceptance',
'[email protected]',
])
),
)
.catch(err => {
throw err;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ describe('Location', function (this: Suite) {
.expect(200)
.then(
result => (
expect(result.body).to.containEql(locationSnippet),
expect(result.body.readACL).to.be.eql([locationSnippet.ownerGroup]),
expect(result.body).to.containEql(
_.omit(locationSnippet, ['readACL', 'deleteACL']),
),
expect(result.body.readACL).to.be.eql([
locationSnippet.ownerGroup,
'any-authenticated-user',
]),
expect(result.body.deleteACL).to.be.eql([
locationSnippet.ownerGroup,
'admin',
]),
(locationSnippetId = result.body.id)
),
)
Expand Down Expand Up @@ -106,7 +115,17 @@ describe('Location', function (this: Suite) {
.then(
result => (
expect(result.body.length).to.be.eql(1),
expect(result.body[0]).to.containEql(locationSnippet)
expect(result.body[0]).to.containEql(
_.omit(locationSnippet, ['readACL', 'deleteACL']),
),
expect(result.body[0].readACL).to.be.eql([
locationSnippet.ownerGroup,
'any-authenticated-user',
]),
expect(result.body[0].deleteACL).to.be.eql([
locationSnippet.ownerGroup,
'admin',
])
),
)
.catch(err => {
Expand All @@ -127,7 +146,21 @@ describe('Location', function (this: Suite) {
.set('Authorization', 'Bearer ' + token)
.set('Content-Type', 'application/json')
.expect(200)
.then(result => expect(result.body).to.containEql(locationSnippet))
.then(
result => (
expect(result.body).to.containEql(
_.omit(locationSnippet, ['readACL', 'deleteACL']),
),
expect(result.body.readACL).to.be.eql([
locationSnippet.ownerGroup,
'any-authenticated-user',
]),
expect(result.body.deleteACL).to.be.eql([
locationSnippet.ownerGroup,
'admin',
])
),
)
.catch(err => {
throw err;
});
Expand Down
Loading
Loading