From 0609a7d9f02aadb055444b1a0ffd809575d556ad Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 14 Apr 2024 22:04:34 +0000 Subject: [PATCH] Validation succeed as long as status code in response is 200 (#6399) Signed-off-by: cliu123 (cherry picked from commit 476cffc2f793b424d68981aaaee9aa1f9fd958be) Signed-off-by: github-actions[bot] # Conflicts: # CHANGELOG.md --- .../data_source_connection_validator.test.ts | 30 ++++++++----------- .../data_source_connection_validator.ts | 2 +- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/plugins/data_source/server/routes/data_source_connection_validator.test.ts b/src/plugins/data_source/server/routes/data_source_connection_validator.test.ts index 0a2b39c15f45..129234d16ddc 100644 --- a/src/plugins/data_source/server/routes/data_source_connection_validator.test.ts +++ b/src/plugins/data_source/server/routes/data_source_connection_validator.test.ts @@ -165,24 +165,20 @@ describe('DataSourceManagement: data_source_connection_validator.ts', () => { expect(validateDataSourcesResponse.statusCode).toBe(200); }); - test('failure: opensearch client response code is 200 and response body is empty', async () => { - try { - const opensearchClient = opensearchServiceMock.createOpenSearchClient(); - opensearchClient.cat.indices.mockResolvedValue(opensearchServiceMock.createApiResponse()); - const dataSourceValidator = new DataSourceConnectionValidator(opensearchClient, { - auth: { - statusCode: 200, - body: '', - credentials: { - service: SigV4ServiceName.OpenSearchServerless, - }, + test('Success: opensearch client response code is 200 and response body is empty', async () => { + const opensearchClient = opensearchServiceMock.createOpenSearchClient(); + opensearchClient.cat.indices.mockResolvedValue(opensearchServiceMock.createApiResponse()); + const dataSourceValidator = new DataSourceConnectionValidator(opensearchClient, { + auth: { + statusCode: 200, + body: '', + credentials: { + service: SigV4ServiceName.OpenSearchServerless, }, - }); - const validateDataSourcesResponse = await dataSourceValidator.validate(); - expect(validateDataSourcesResponse.statusCode).toBe(200); - } catch (e) { - expect(e).toBeTruthy(); - } + }, + }); + const validateDataSourcesResponse = await dataSourceValidator.validate(); + expect(validateDataSourcesResponse.statusCode).toBe(200); }); test('failure: opensearch client response code is other than 200', async () => { diff --git a/src/plugins/data_source/server/routes/data_source_connection_validator.ts b/src/plugins/data_source/server/routes/data_source_connection_validator.ts index 0d94eaa9bb56..8e2e34014595 100644 --- a/src/plugins/data_source/server/routes/data_source_connection_validator.ts +++ b/src/plugins/data_source/server/routes/data_source_connection_validator.ts @@ -20,7 +20,7 @@ export class DataSourceConnectionValidator { this.dataSourceAttr.auth?.credentials?.service === SigV4ServiceName.OpenSearchServerless ) { validationResponse = await this.callDataCluster.cat.indices(); - if (validationResponse?.statusCode === 200 && validationResponse?.body) { + if (validationResponse?.statusCode === 200) { return validationResponse; } } else {