Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into exact-name-search
Browse files Browse the repository at this point in the history
  • Loading branch information
cianfoley-nearform committed May 22, 2018
2 parents d0fe7a7 + 765669c commit c8c7337
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/swagger/swagger-json.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/udaru-core/lib/ops/organizationOps.js
Expand Up @@ -656,6 +656,7 @@ function buildOrganizationOps (db, config) {
newPolicies.slice(1).forEach((policy) => {
sqlQuery.append(SQL`, (${policy.id}, ${id}, ${policy.variables})`)
})
sqlQuery.append(SQL` ON CONFLICT ON CONSTRAINT org_policy_link DO NOTHING`)

client.query(sqlQuery, (err, result) => {
if (utils.isUniqueViolationError(err)) return cb(Boom.conflict(err.detail))
Expand Down
1 change: 1 addition & 0 deletions packages/udaru-core/lib/ops/teamOps.js
Expand Up @@ -150,6 +150,7 @@ function buildTeamOps (db, config) {
newPolicies.slice(1).forEach((policy) => {
sql.append(SQL`, (${policy.id},${teamId}, ${policy.variables})`)
})
sql.append(SQL` ON CONFLICT ON CONSTRAINT team_policy_link DO NOTHING`)
job.client.query(sql, (err, result) => {
if (utils.isUniqueViolationError(err)) return next(Boom.conflict(err.detail))
if (err) return next(Boom.badImplementation(err))
Expand Down
2 changes: 1 addition & 1 deletion packages/udaru-core/lib/ops/userOps.js
Expand Up @@ -654,11 +654,11 @@ function buildUserOps (db, config) {
policy_id, user_id, variables
) VALUES
`

sqlQuery.append(SQL`(${newPolicies[0].id}, ${id}, ${newPolicies[0].variables})`)
newPolicies.slice(1).forEach((policy) => {
sqlQuery.append(SQL`, (${policy.id}, ${id}, ${policy.variables})`)
})
sqlQuery.append(SQL` ON CONFLICT ON CONSTRAINT user_policy_link DO NOTHING`)

client.query(sqlQuery, (err, result) => {
if (utils.isUniqueViolationError(err)) return cb(Boom.conflict(err.detail))
Expand Down
6 changes: 3 additions & 3 deletions packages/udaru-core/lib/ops/validation.js
Expand Up @@ -25,9 +25,9 @@ const ResourceBatch = Joi.array().min(1).items(Joi.object({
action: action
}).label('ResourceAccess')).required().description('A batch of resources and actions to check').label('ResourceBatch')

const PolicyIdsArray = Joi.array().required().items(PolicyIdObject).description('Array of Policies/Policy Templates to associate with this entity (with optional Policy Instance variables)').label('PolicyIdsArray')
const UsersArray = Joi.array().required().items(requiredString).description('User IDs').label('UsersArray')
const TeamsArray = Joi.array().required().items(requiredString).description('Teams IDs').label('TeamsArray')
const PolicyIdsArray = Joi.array().required().min(0).items(PolicyIdObject).description('Array of Policies/Policy Templates to associate with this entity (with optional Policy Instance variables)').label('PolicyIdsArray')
const UsersArray = Joi.array().required().min(0).items(requiredStringId.optional()).description('User IDs').label('UsersArray')
const TeamsArray = Joi.array().required().min(0).items(requiredStringId.optional()).description('Teams IDs').label('TeamsArray')
const ResourcesArray = Joi.array().items(resource.description('A single resource')).single().required().description('A list of Resources').label('ResourcesArray')

const StatementObject = Joi.object({
Expand Down
8 changes: 3 additions & 5 deletions packages/udaru-core/test/integration/organizationOps.test.js
Expand Up @@ -921,7 +921,7 @@ lab.experiment('OrganizationOps', () => {
})

lab.experiment('multiple policies - ', () => {
lab.test('add same policy without variables twice 409 conflict', (done) => {
lab.test('add same policy without variables twice no conflict', (done) => {
const tasks = []

tasks.push((next) => {
Expand Down Expand Up @@ -965,8 +965,7 @@ lab.experiment('OrganizationOps', () => {
})
tasks.push((next) => {
udaru.organizations.addPolicies({id: organizationId, policies: [{id: testPolicy.id}]}, (err, res) => {
expect(err).to.exist()
expect(err.output.statusCode).to.equal(409)
expect(err).to.not.exist()
next()
})
})
Expand Down Expand Up @@ -1563,8 +1562,7 @@ lab.experiment('OrganizationOps', () => {
variables: {var1: 'value1'}
}]
udaru.organizations.addPolicies({id: organizationId, policies}, (err, res) => {
expect(err).to.exist()
expect(err.output.statusCode).to.equal(409)
expect(err).to.not.exist()
next()
})
})
Expand Down
10 changes: 4 additions & 6 deletions packages/udaru-core/test/integration/teamOps.test.js
Expand Up @@ -895,7 +895,7 @@ lab.experiment('TeamOps', () => {
})

lab.experiment('multiple policy tests - ', () => {
lab.test('same policy instances without variables 409 conflict', (done) => {
lab.test('same policy instances without variables no conflict', (done) => {
udaru.teams.addPolicies({ id: testTeam.id, policies: [{id: policies[0].id}, {id: policies[1].id}], organizationId: 'WONKA' }, (err, team) => {
expect(err).to.not.exist()
expect(team).to.exist()
Expand All @@ -913,8 +913,7 @@ lab.experiment('TeamOps', () => {
}])

udaru.teams.addPolicies({ id: team.id, policies: [{id: policies[1].id}], organizationId: 'WONKA' }, (err, team) => {
expect(err).to.exist()
expect(err.output.statusCode).to.equal(409)
expect(err).to.not.exist()
done()
})
})
Expand Down Expand Up @@ -1245,7 +1244,7 @@ lab.experiment('TeamOps', () => {
})
})

lab.test('with same variables 409 conflict', (done) => {
lab.test('with same variables - no conflict', (done) => {
const policiesParam = [{
id: policies[0].id,
variables: { var1: 'value1' }
Expand Down Expand Up @@ -1276,8 +1275,7 @@ lab.experiment('TeamOps', () => {
}]

udaru.teams.addPolicies({ id: team.id, policies: policiesParam, organizationId: 'WONKA' }, (err, team) => {
expect(err).to.exist()
expect(err.output.statusCode).to.equal(409)
expect(err).to.not.exist()
done()
})
})
Expand Down
10 changes: 4 additions & 6 deletions packages/udaru-core/test/integration/userOps.test.js
Expand Up @@ -728,7 +728,7 @@ lab.experiment('UserOps', () => {
})

lab.experiment('multiple instance tests', () => {
lab.test('same policy without variables should 409 conflict', (done) => {
lab.test('same policy without variables should not conflict', (done) => {
let accountantPolicy = u.findPick(wonkaPolicies, {name: 'Accountant'}, ['id', 'name', 'version'])
let directorPolicy = u.findPick(wonkaPolicies, {name: 'Director'}, ['id', 'name', 'version'])
let sysadminPolicy = u.findPick(wonkaPolicies, {name: 'Sys admin'}, ['id', 'name', 'version'])
Expand All @@ -752,8 +752,7 @@ lab.experiment('UserOps', () => {
],
organizationId: 'WONKA'
}, (err, user) => {
expect(err).to.exist()
expect(err.output.statusCode).to.equal(409)
expect(err).to.not.exist()

udaru.users.replacePolicies({ id: 'VerucaId', policies: [{id: accountantPolicy.id}], organizationId: 'WONKA' }, (err, user) => {
expect(err).to.not.exist()
Expand Down Expand Up @@ -1016,7 +1015,7 @@ lab.experiment('UserOps', () => {
})
})

lab.test('with same variables should 409 conflict', (done) => {
lab.test('with same variables should be no conflict', (done) => {
const accountantPolicy = u.findPick(wonkaPolicies, {name: 'Accountant'}, ['id', 'name', 'version'])

udaru.users.read({ id: 'VerucaId', organizationId: 'WONKA' }, (err, user) => {
Expand Down Expand Up @@ -1059,8 +1058,7 @@ lab.experiment('UserOps', () => {
policies,
organizationId: 'WONKA'
}, (err, user) => {
expect(err).to.exist()
expect(err.output.statusCode).to.equal(409)
expect(err).to.not.exist()

udaru.users.replacePolicies({ id: 'VerucaId', policies: [{id: accountantPolicy.id}], organizationId: 'WONKA' }, (err, user) => {
expect(err).to.not.exist()
Expand Down

0 comments on commit c8c7337

Please sign in to comment.