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

Fixed REST status codes for RBAC and provisioning #842

Merged
merged 5 commits into from
Mar 25, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Fixed Aggregation schemas ([#801](https://github.com/opensearch-project/opensearch-api-specification/pull/801))
- Fixed FilterQueryRequestProcessor to use correct query type ([#821](https://github.com/opensearch-project/opensearch-api-specification/pull/821))
- 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))
- Fixed REST status codes for RBAC and provisioning for Flow Framework plugin ([#842](https://github.com/opensearch-project/opensearch-api-specification/pull/842))

### Changed
- 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))
Expand Down
14 changes: 10 additions & 4 deletions json_schemas/test_story.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,21 @@ definitions:
type: object
properties:
status:
type: integer
description: The expected HTTP status code. Default to 200.
default: 200
oneOf:
- type: integer
description: The expected HTTP status code. Default to 200.
default: 200
- type: array
items:
type: integer
description: Array of success HTTP status codes.
content_type:
type: string
default: application/json
payload:
$ref: '#/definitions/Payload'
required: [status]
required:
- status
additionalProperties: false

ActualResponse:
Expand Down
3 changes: 2 additions & 1 deletion tests/default/flow_framework/workflow/provision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ chapters:
payload:
openai_key: '1234556'
response:
status: 200
status: [200, 202]
content_type: application/json
3 changes: 2 additions & 1 deletion tests/default/flow_framework/workflow/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ chapters:
parameters:
workflow_id: ${workflow.workflow_id}
response:
status: 200
status: [200, 202]
content_type: application/json
- synopsis: Update workflow fail with `provision` and `update_fields` set to `true`.
path: /_plugins/_flow_framework/workflow/{workflow_id}
method: PUT
Expand Down
11 changes: 8 additions & 3 deletions tools/src/tester/ChapterEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,19 @@ export default class ChapterEvaluator {

#evaluate_status(chapter: ParsedChapter, response: ActualResponse): Evaluation {
const expected_status = chapter.response?.status ?? 200
if (response.status === expected_status && response.error === undefined) return { result: Result.PASSED }

const is_status_match = Array.isArray(expected_status)
? expected_status.includes(response.status)
: response.status === expected_status

if (is_status_match && response.error === undefined) return { result: Result.PASSED }

let result: Evaluation = {
result: Result.ERROR,
message: _.join(_.compact([
expected_status == response.status ?
is_status_match ?
`Received ${response.status ?? 'none'}: ${response.content_type ?? 'unknown'}.` :
`Expected status ${expected_status}, but received ${response.status ?? 'none'}: ${response.content_type ?? 'unknown'}.`,
`Expected status ${Array.isArray(expected_status) ? expected_status.join(' or ') : expected_status}, but received ${response.status ?? 'none'}: ${response.content_type ?? 'unknown'}.`,
response.message
]), ' ')
}
Expand Down
5 changes: 1 addition & 4 deletions tools/src/tester/types/story.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ export interface Retry {
* via the `definition` "ExpectedResponse".
*/
export interface ExpectedResponse {
/**
* The expected HTTP status code. Default to 200.
*/
status: number;
status: number | number[];
content_type?: string;
payload?: Payload;
}
Expand Down
31 changes: 31 additions & 0 deletions tools/tests/tester/ChapterEvaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,37 @@ describe('ChapterEvaluator', () => {
)
})

test('a successful response for array of status codes', async () => {
mock.onAny().reply(200, '{"acknowledged":true}', { "content-type": "application/json" })

expect(
await chapter_evaluator.evaluate({
synopsis: 'Perform a PUT /{index} with multiple possible status codes.',
path: '/{index}',
method: 'PUT',
parameters: {
index: 'test'
},
request: {
payload: {}
},
response: {
status: [200, 202] // Expecting either 200 or 202
}
}, false, story_outputs)).toEqual(
{
title: 'Perform a PUT /{index} with multiple possible status codes.',
path: 'PUT /{index}',
operation: { method: 'PUT', path: '/{index}' },
request: { parameters: { index: { result: 'PASSED' } }, request: { result: 'PASSED' } },
response: { output_values: { result: 'SKIPPED' }, payload_body: { result: 'PASSED' }, payload_schema: { result: 'PASSED' }, status: { result: 'PASSED' } },
overall: {
result: Result.PASSED
}
}
)
})

test('retries', async () => {
var count = 0

Expand Down