-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Manual][Backport 2.x] Backport 7884 and 7954 to 2.x (#7984)
* [Workspace]Validate features parameter in workspace create and update API (#7884) * Add validate for features field in workspace create and update API Signed-off-by: Lin Wang <wonglam@amazon.com> * Changeset file for PR #7884 created/updated * Changeset file for PR #7884 created/updated * Move router outside align with other plugins Signed-off-by: Lin Wang <wonglam@amazon.com> * Add ut and fix integration tests Signed-off-by: Lin Wang <wonglam@amazon.com> * Import use case id from default nav groups Signed-off-by: Lin Wang <wonglam@amazon.com> * Fix workspace routes UT Signed-off-by: Lin Wang <wonglam@amazon.com> * Share feature config generator between publicn and server Signed-off-by: Lin Wang <wonglam@amazon.com> * Fix osd server crashed due to import from public Signed-off-by: Lin Wang <wonglam@amazon.com> --------- Signed-off-by: Lin Wang <wonglam@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> * [Workspace]Fix dynamicConfigServiceMock import path in workspace routes UT (#7954) * Fix dynamicConfigServiceMock import path in workspace routes UT Signed-off-by: Lin Wang <wonglam@amazon.com> * Changeset file for PR #7954 created/updated --------- Signed-off-by: Lin Wang <wonglam@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> --------- Signed-off-by: Lin Wang <wonglam@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> (cherry picked from commit d3ce40f) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
263cf25
commit 7ec7fbe
Showing
17 changed files
with
200 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- [Workspace]Validate features parameter in workspace create and update API ([#7884](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7884)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fix: | ||
- [Workspace]dynamicConfigServiceMock not found in workspace routes UT ([#7954](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7954)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import supertest from 'supertest'; | ||
import { UnwrapPromise } from '@osd/utility-types'; | ||
|
||
import { setupServer } from '../../../../core/server/test_utils'; | ||
import { loggingSystemMock, dynamicConfigServiceMock } from '../../../../core/server/mocks'; | ||
|
||
import { workspaceClientMock } from '../workspace_client.mock'; | ||
|
||
import { registerRoutes, WORKSPACES_API_BASE_URL } from './index'; | ||
|
||
type SetupServerReturn = UnwrapPromise<ReturnType<typeof setupServer>>; | ||
const mockDynamicConfigService = dynamicConfigServiceMock.createInternalStartContract(); | ||
|
||
describe(`Workspace routes`, () => { | ||
let server: SetupServerReturn['server']; | ||
let httpSetup: SetupServerReturn['httpSetup']; | ||
|
||
beforeEach(async () => { | ||
({ server, httpSetup } = await setupServer()); | ||
|
||
const router = httpSetup.createRouter(''); | ||
|
||
registerRoutes({ | ||
router, | ||
client: workspaceClientMock, | ||
logger: loggingSystemMock.create().get(), | ||
maxImportExportSize: Number.MAX_SAFE_INTEGER, | ||
isPermissionControlEnabled: false, | ||
}); | ||
|
||
await server.start({ dynamicConfigService: mockDynamicConfigService }); | ||
}); | ||
|
||
afterEach(async () => { | ||
await server.stop(); | ||
}); | ||
|
||
it('creates a workspace successfully', async () => { | ||
const result = await supertest(httpSetup.server.listener) | ||
.post(WORKSPACES_API_BASE_URL) | ||
.send({ | ||
attributes: { | ||
name: 'Observability', | ||
features: ['use-case-observability'], | ||
}, | ||
}) | ||
.expect(200); | ||
expect(result.body).toEqual({ id: expect.any(String) }); | ||
expect(workspaceClientMock.create).toHaveBeenCalledWith( | ||
expect.any(Object), | ||
expect.objectContaining({ | ||
name: 'Observability', | ||
features: ['use-case-observability'], | ||
}) | ||
); | ||
}); | ||
|
||
describe('feature validation', () => { | ||
it('returns 400 when no features is provided during workspace creation', async () => { | ||
await supertest(httpSetup.server.listener) | ||
.post(WORKSPACES_API_BASE_URL) | ||
.send({ | ||
attributes: { | ||
name: 'Observability', | ||
}, | ||
}) | ||
.expect(400); | ||
}); | ||
it('returns 400 when no valid use case is provided during workspace creation', async () => { | ||
const result = await supertest(httpSetup.server.listener) | ||
.post(WORKSPACES_API_BASE_URL) | ||
.send({ | ||
attributes: { | ||
name: 'Observability', | ||
features: ['use-case-valid'], | ||
}, | ||
}) | ||
.expect(400); | ||
expect(result.body.message).toEqual( | ||
'[request body.attributes.features]: At least one use case is required. Valid options: use-case-all, use-case-observability, use-case-security-analytics, use-case-essentials, use-case-search' | ||
); | ||
}); | ||
it('returns 400 when multiple use cases are provided during workspace creation', async () => { | ||
const result = await supertest(httpSetup.server.listener) | ||
.post(WORKSPACES_API_BASE_URL) | ||
.send({ | ||
attributes: { | ||
name: 'Observability', | ||
features: ['use-case-observability', 'use-case-all'], | ||
}, | ||
}) | ||
.expect(400); | ||
expect(result.body.message).toEqual( | ||
'[request body.attributes.features]: Only one use case is allowed per workspace.' | ||
); | ||
}); | ||
it('returns 400 when no valid use case is provided during workspace update', async () => { | ||
const result = await supertest(httpSetup.server.listener) | ||
.put(`${WORKSPACES_API_BASE_URL}/mock-workspace-id`) | ||
.send({ | ||
attributes: { | ||
name: 'Observability', | ||
features: ['feature1', 'feature2'], | ||
}, | ||
}) | ||
.expect(400); | ||
expect(result.body.message).toEqual( | ||
'[request body.attributes.features]: At least one use case is required. Valid options: use-case-all, use-case-observability, use-case-security-analytics, use-case-essentials, use-case-search' | ||
); | ||
}); | ||
it('updates workspace name successfully without modifying features', async () => { | ||
await supertest(httpSetup.server.listener) | ||
.put(`${WORKSPACES_API_BASE_URL}/mock-workspace-id`) | ||
.send({ | ||
attributes: { | ||
name: 'Observability', | ||
}, | ||
}) | ||
.expect(200); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export const workspaceClientMock = { | ||
setup: jest.fn(), | ||
setSavedObjects: jest.fn(), | ||
setUiSettings: jest.fn(), | ||
create: jest.fn().mockResolvedValue({ id: 'mock-workspace-id' }), | ||
list: jest.fn(), | ||
get: jest.fn(), | ||
update: jest.fn(), | ||
delete: jest.fn(), | ||
destroy: jest.fn(), | ||
}; |