influxdata / influxdata/influxdb

Create stack with bad/inexistant OrgID is returning inconsistent error codes

Open
#23,358 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

__Steps to reproduce:__
List the minimal actions needed to reproduce the behavior.

I'm writing Grace tests for stacks. I've attempted the following test cases

```javascript
it.only(`StacksApi: createStack: returns error on bad orgID`, async () => {
// invalid ID
testStack.orgID = 'invalidID'
await request(url)
.post('/stacks')
.set('Authorization', `Token ${localAuth.token}`)
.set('Content-Type', 'application/json')
.send(JSON.stringify(testStack))
.then(async ({status, body}) => {
assert(status,
422,
`\n failure: ${url}/stacks\n` +
`\n request body: \n${JSON.stringify(testStack, null, 3)}\n` +
`\n response body: \n${JSON.stringify(body, null, 3)}\n\n`)
expect(body.code).to.equal(helpers.errorCodeMap.get('422'))
expect(body.message).to.equal(`provided org id["${testStack.orgID}"] is invalid`)
})
// inexistant ID
testStack.orgID = helpers.genSafeIDHexString(16)
await request(url)
.post('/stacks')
.set('Authorization', `Token ${localAuth.token}`)
.set('Content-Type', 'application/json')
.send(JSON.stringify(testStack))
.then(async ({status, body}) => {
assert(status,
422,
`\n failure: ${url}/stacks\n` +
`\n request body: \n${JSON.stringify(testStack, null, 3)}\n` +
`\n response body: \n${JSON.stringify(body, null, 3)}\n\n`)
expect(body.code).to.equal(helpers.errorCodeMap.get('422'))
expect(body.message).to.equal(`organization dependency does not exist for id["${testStack.orgID}"]`)
})
})

```

__Expected behavior:__
Describe what you expected to happen.

That the code field in the body of the error report should be consistent with the status number and with HTTP standards or with HTTP code value mappings used elsewhere in Influx.

Elsewhere in Grace tests I've seen that an invalid orgID field in a resource object, is returning HTTP Error code 400, not 422, along with a code string of 'invalid' as defined in the `helpers.errorCodeMap` in the Grace tests. I expect the `/stacks` API to use the same default behavior, unless specified otherwise in OpenAPI.

__Actual behavior:__
Describe What actually happened.

In these two cases the `status` value returned is 422 - Unprocessable Entity https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/422

However the text description in the body (`body.code`) the values are either 'invalid' (first case) which has been mapped elsewhere in Influx to HTTP 400, or to 'conflict' which is normally reported using the HTTP status value of 409.

first case - test run
```
...
1) StacksApi - Cloud2
createStack
StacksApi: createStack: returns error on bad orgID:

AssertionError: expected 'invalid' to equal 'unprocessable entity'
+ expected - actual

-invalid
+unprocessable entity
```
second case - test run
```
1) StacksApi - Cloud2
createStack
StacksApi: createStack: returns error on bad orgID:

AssertionError: expected 'conflict' to equal 'unprocessable entity'
+ expected - actual

-conflict
+unprocessable entity

```

__Environment info:__

Testing against K8S-IDPE remocal
last commit
```
commit 363cfd22c5b1d81621e74d79a4df9c4ccf46cbb5 (HEAD -> master, origin/master, origin/alchemy/automatic, origin/HEAD)
Author: Hercules Mango Churchill
Date: Thu May 19 00:52:07 2022 +0000
```

Contributor guide

Open the contributing guide

Research direction

Start with the Grace test for StacksApi createStack and the POST /stacks entry point described in the issue. Compare the invalid and nonexistent orgID paths with helpers.errorCodeMap and the OpenAPI behavior; done means both responses use a consistent HTTP status and body code, with the relevant tests passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, openapi
Domain
api, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.