Skip to content

Commit 3c22a3e

Browse files
authored
Fixed REST status codes for RBAC and provisioning (#842)
* Fixed REST status codes for RBAC and provisioning Signed-off-by: Owais <[email protected]>
1 parent 7be2584 commit 3c22a3e

File tree

7 files changed

+55
-13
lines changed

7 files changed

+55
-13
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
122122
- Fixed Aggregation schemas ([#801](https://github.com/opensearch-project/opensearch-api-specification/pull/801))
123123
- Fixed FilterQueryRequestProcessor to use correct query type ([#821](https://github.com/opensearch-project/opensearch-api-specification/pull/821))
124124
- Fixed `knn.train_model`'s request body `method` field to accept an object rather than a string ([#814](https://github.com/opensearch-project/opensearch-api-specification/pull/814))
125+
- Fixed REST status codes for RBAC and provisioning for Flow Framework plugin ([#842](https://github.com/opensearch-project/opensearch-api-specification/pull/842))
125126

126127
### Changed
127128
- Changed `tasks._common:TaskInfo` and `tasks._common:TaskGroup` to be composed of a `tasks._common:TaskInfoBase` ([#683](https://github.com/opensearch-project/opensearch-api-specification/pull/683))

json_schemas/test_story.schema.yaml

+10-4
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,21 @@ definitions:
190190
type: object
191191
properties:
192192
status:
193-
type: integer
194-
description: The expected HTTP status code. Default to 200.
195-
default: 200
193+
oneOf:
194+
- type: integer
195+
description: The expected HTTP status code. Default to 200.
196+
default: 200
197+
- type: array
198+
items:
199+
type: integer
200+
description: Array of success HTTP status codes.
196201
content_type:
197202
type: string
198203
default: application/json
199204
payload:
200205
$ref: '#/definitions/Payload'
201-
required: [status]
206+
required:
207+
- status
202208
additionalProperties: false
203209

204210
ActualResponse:

tests/default/flow_framework/workflow/provision.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ chapters:
3232
payload:
3333
openai_key: '1234556'
3434
response:
35-
status: 200
35+
status: [200, 202]
36+
content_type: application/json

tests/default/flow_framework/workflow/template.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ chapters:
135135
parameters:
136136
workflow_id: ${workflow.workflow_id}
137137
response:
138-
status: 200
138+
status: [200, 202]
139+
content_type: application/json
139140
- synopsis: Update workflow fail with `provision` and `update_fields` set to `true`.
140141
path: /_plugins/_flow_framework/workflow/{workflow_id}
141142
method: PUT

tools/src/tester/ChapterEvaluator.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,19 @@ export default class ChapterEvaluator {
132132

133133
#evaluate_status(chapter: ParsedChapter, response: ActualResponse): Evaluation {
134134
const expected_status = chapter.response?.status ?? 200
135-
if (response.status === expected_status && response.error === undefined) return { result: Result.PASSED }
135+
136+
const is_status_match = Array.isArray(expected_status)
137+
? expected_status.includes(response.status)
138+
: response.status === expected_status
139+
140+
if (is_status_match && response.error === undefined) return { result: Result.PASSED }
136141

137142
let result: Evaluation = {
138143
result: Result.ERROR,
139144
message: _.join(_.compact([
140-
expected_status == response.status ?
145+
is_status_match ?
141146
`Received ${response.status ?? 'none'}: ${response.content_type ?? 'unknown'}.` :
142-
`Expected status ${expected_status}, but received ${response.status ?? 'none'}: ${response.content_type ?? 'unknown'}.`,
147+
`Expected status ${Array.isArray(expected_status) ? expected_status.join(' or ') : expected_status}, but received ${response.status ?? 'none'}: ${response.content_type ?? 'unknown'}.`,
143148
response.message
144149
]), ' ')
145150
}

tools/src/tester/types/story.types.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@ export interface Retry {
186186
* via the `definition` "ExpectedResponse".
187187
*/
188188
export interface ExpectedResponse {
189-
/**
190-
* The expected HTTP status code. Default to 200.
191-
*/
192-
status: number;
189+
status: number | number[];
193190
content_type?: string;
194191
payload?: Payload;
195192
}

tools/tests/tester/ChapterEvaluator.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,37 @@ describe('ChapterEvaluator', () => {
7373
)
7474
})
7575

76+
test('a successful response for array of status codes', async () => {
77+
mock.onAny().reply(200, '{"acknowledged":true}', { "content-type": "application/json" })
78+
79+
expect(
80+
await chapter_evaluator.evaluate({
81+
synopsis: 'Perform a PUT /{index} with multiple possible status codes.',
82+
path: '/{index}',
83+
method: 'PUT',
84+
parameters: {
85+
index: 'test'
86+
},
87+
request: {
88+
payload: {}
89+
},
90+
response: {
91+
status: [200, 202] // Expecting either 200 or 202
92+
}
93+
}, false, story_outputs)).toEqual(
94+
{
95+
title: 'Perform a PUT /{index} with multiple possible status codes.',
96+
path: 'PUT /{index}',
97+
operation: { method: 'PUT', path: '/{index}' },
98+
request: { parameters: { index: { result: 'PASSED' } }, request: { result: 'PASSED' } },
99+
response: { output_values: { result: 'SKIPPED' }, payload_body: { result: 'PASSED' }, payload_schema: { result: 'PASSED' }, status: { result: 'PASSED' } },
100+
overall: {
101+
result: Result.PASSED
102+
}
103+
}
104+
)
105+
})
106+
76107
test('retries', async () => {
77108
var count = 0
78109

0 commit comments

Comments
 (0)