Skip to content

Commit 2488b5f

Browse files
authored
Merge pull request #1443 from CVEProject/cb_1406_uuid_errors
Resolves issue #1406 - fixed error handling when UUID provided for registry org/user creation
2 parents ef86ef4 + 4ca2fa6 commit 2488b5f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/controller/registry-org.controller/registry-org.controller.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,14 @@ async function createOrg (req, res, next) {
9292
const registryOrgRepo = req.ctx.repositories.getRegistryOrgRepository()
9393
const body = req.ctx.body
9494

95+
// Short circuit if UUID provided
96+
const bodyKeys = Object.keys(body).map(k => k.toLowerCase())
97+
if (bodyKeys.includes('uuid')) {
98+
return res.status(400).json(error.uuidProvided('org'))
99+
}
100+
95101
const newOrg = new RegistryOrg()
96-
Object.keys(body).map(k => k.toLowerCase()).forEach(k => {
102+
bodyKeys.forEach(k => {
97103
if (k === 'long_name') {
98104
newOrg.long_name = body[k]
99105
} else if (k === 'short_name') {
@@ -136,8 +142,6 @@ async function createOrg (req, res, next) {
136142
website: '',
137143
...contactInfo
138144
}
139-
} else if (k === 'uuid') {
140-
return res.status(400).json(error.uuidProvided('org'))
141145
}
142146
})
143147

src/controller/registry-user.controller/registry-user.controller.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ async function createUser (req, res, next) {
7171
const registryUserRepo = req.ctx.repositories.getRegistryUserRepository()
7272
const body = req.ctx.body
7373

74+
// Short circuit if UUID provided
75+
const bodyKeys = Object.keys(body).map((k) => k.toLowerCase())
76+
if (bodyKeys.includes('uuid')) {
77+
return res.status(400).json(error.uuidProvided('user'))
78+
}
79+
7480
// TODO: check if affiliated orgs and program orgs exist, and if their membership limit is reached
7581

7682
const newUser = new RegistryUser()
@@ -89,8 +95,6 @@ async function createUser (req, res, next) {
8995
// TODO: dedupe
9096
} else if (k === 'cve_program_org_membership') {
9197
// TODO: dedupe
92-
} else if (k === 'uuid') {
93-
return res.status(400).json(error.uuidProvided('user'))
9498
}
9599
})
96100

0 commit comments

Comments
 (0)