From 4ebe13508770252ac5fab7dbbdc5228d313397c3 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 5 Feb 2024 11:05:18 +0800 Subject: [PATCH 01/10] feat: update agent id into config index Signed-off-by: SuZhou-Joe --- .github/workflows/assistant-release-e2e-workflow.yml | 2 +- cypress/utils/plugins/dashboards-assistant/commands.js | 10 ++++++++++ .../utils/plugins/dashboards-assistant/constants.js | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/assistant-release-e2e-workflow.yml b/.github/workflows/assistant-release-e2e-workflow.yml index 952fd4cdd..3afca290f 100644 --- a/.github/workflows/assistant-release-e2e-workflow.yml +++ b/.github/workflows/assistant-release-e2e-workflow.yml @@ -22,4 +22,4 @@ jobs: with: test-name: dashboards assistant test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*' - osd-serve-args: --assistant.chat.enabled=true --assistant.chat.rootAgentName="Cypress test agent" + osd-serve-args: --assistant.chat.enabled=true diff --git a/cypress/utils/plugins/dashboards-assistant/commands.js b/cypress/utils/plugins/dashboards-assistant/commands.js index 8197c9d80..9028bd6a0 100644 --- a/cypress/utils/plugins/dashboards-assistant/commands.js +++ b/cypress/utils/plugins/dashboards-assistant/commands.js @@ -112,6 +112,16 @@ Cypress.Commands.add('registerRootAgent', () => { }) .then((resp) => { agentParameters.rootAgentId = resp.body.agent_id; + return cy.request( + 'POST', + `${BACKEND_BASE_PATH}${ML_COMMONS_API.UPDATE_ROOT_AGENT_CONFIG}`, + { + type: 'os_chat_root_agent', + configuration: { + agent_id: agentParameters.rootAgentId, + }, + } + ); }); }); diff --git a/cypress/utils/plugins/dashboards-assistant/constants.js b/cypress/utils/plugins/dashboards-assistant/constants.js index c8340b5ed..2e941cf93 100644 --- a/cypress/utils/plugins/dashboards-assistant/constants.js +++ b/cypress/utils/plugins/dashboards-assistant/constants.js @@ -14,6 +14,7 @@ export const ML_COMMONS_API = { CREATE_CONNECTOR: `${ML_COMMONS_API_PREFIX}/connectors/_create`, CREATE_MODEL: `${ML_COMMONS_API_PREFIX}/models/_register`, CREATE_AGENT: `${ML_COMMONS_API_PREFIX}/agents/_register`, + UPDATE_ROOT_AGENT_CONFIG: `.plugins-ml-config/_doc/os_chat`, }; export const ASSISTANT_API_BASE = '/api/assistant'; From 395be2e80b0bcae2bca3b08d5bb05a61d90b4ac1 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 5 Feb 2024 11:29:17 +0800 Subject: [PATCH 02/10] feat: enable agent framework Signed-off-by: SuZhou-Joe --- .../fixtures/plugins/dashboards-assistant/cluster_settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cypress/fixtures/plugins/dashboards-assistant/cluster_settings.json b/cypress/fixtures/plugins/dashboards-assistant/cluster_settings.json index 29e65ef6f..3ce0026db 100644 --- a/cypress/fixtures/plugins/dashboards-assistant/cluster_settings.json +++ b/cypress/fixtures/plugins/dashboards-assistant/cluster_settings.json @@ -2,6 +2,7 @@ "persistent": { "plugins.ml_commons.only_run_on_ml_node": false, "plugins.ml_commons.memory_feature_enabled": true, + "plugins.ml_commons.agent_framework_enabled": true, "plugins.ml_commons.trusted_connector_endpoints_regex": [ "^http://127.0.0.1:3000$" ] From e24290c30670602dd96f842101701db6ee33e160 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 5 Feb 2024 11:36:31 +0800 Subject: [PATCH 03/10] feat: update url Signed-off-by: SuZhou-Joe --- cypress/utils/plugins/dashboards-assistant/constants.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/utils/plugins/dashboards-assistant/constants.js b/cypress/utils/plugins/dashboards-assistant/constants.js index 2e941cf93..8b26f257a 100644 --- a/cypress/utils/plugins/dashboards-assistant/constants.js +++ b/cypress/utils/plugins/dashboards-assistant/constants.js @@ -14,7 +14,7 @@ export const ML_COMMONS_API = { CREATE_CONNECTOR: `${ML_COMMONS_API_PREFIX}/connectors/_create`, CREATE_MODEL: `${ML_COMMONS_API_PREFIX}/models/_register`, CREATE_AGENT: `${ML_COMMONS_API_PREFIX}/agents/_register`, - UPDATE_ROOT_AGENT_CONFIG: `.plugins-ml-config/_doc/os_chat`, + UPDATE_ROOT_AGENT_CONFIG: `/.plugins-ml-config/_doc/os_chat`, }; export const ASSISTANT_API_BASE = '/api/assistant'; From d5a851979b4a03563d3c93e459a8f15ea24c1aed Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 5 Feb 2024 11:51:28 +0800 Subject: [PATCH 04/10] feat: update settings Signed-off-by: SuZhou-Joe --- .../utils/plugins/dashboards-assistant/commands.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cypress/utils/plugins/dashboards-assistant/commands.js b/cypress/utils/plugins/dashboards-assistant/commands.js index 9028bd6a0..6ad471644 100644 --- a/cypress/utils/plugins/dashboards-assistant/commands.js +++ b/cypress/utils/plugins/dashboards-assistant/commands.js @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { merge } from 'lodash'; import FlowTemplateJSON from '../../../fixtures/plugins/dashboards-assistant/flow-template.json'; import { BACKEND_BASE_PATH, BASE_PATH } from '../../constants'; import { ML_COMMONS_API, ASSISTANT_API } from './constants'; @@ -10,7 +11,15 @@ import clusterSettings from '../../../fixtures/plugins/dashboards-assistant/clus import { apiRequest } from '../../helpers'; Cypress.Commands.add('addAssistantRequiredSettings', () => { - cy.request('PUT', `${BACKEND_BASE_PATH}/_cluster/settings`, clusterSettings); + let mergedSettings = clusterSettings; + if (Cypress.env('SECURITY_ENABLED')) { + mergedSettings = merge({}, clusterSettings, { + persistent: { + 'plugins.security.system_indices.enabled': false, + }, + }); + } + cy.request('PUT', `${BACKEND_BASE_PATH}/_cluster/settings`, mergedSettings); }); const agentParameters = { From c4e271662840571b83dd7f4a06f77be824ee3185 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 5 Feb 2024 12:09:13 +0800 Subject: [PATCH 05/10] feat: test in security disabled Signed-off-by: SuZhou-Joe --- .github/workflows/assistant-release-e2e-workflow.yml | 1 + .../utils/plugins/dashboards-assistant/commands.js | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/assistant-release-e2e-workflow.yml b/.github/workflows/assistant-release-e2e-workflow.yml index 3afca290f..e82908770 100644 --- a/.github/workflows/assistant-release-e2e-workflow.yml +++ b/.github/workflows/assistant-release-e2e-workflow.yml @@ -23,3 +23,4 @@ jobs: test-name: dashboards assistant test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*' osd-serve-args: --assistant.chat.enabled=true + security-enabled: false diff --git a/cypress/utils/plugins/dashboards-assistant/commands.js b/cypress/utils/plugins/dashboards-assistant/commands.js index 6ad471644..9028bd6a0 100644 --- a/cypress/utils/plugins/dashboards-assistant/commands.js +++ b/cypress/utils/plugins/dashboards-assistant/commands.js @@ -3,7 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { merge } from 'lodash'; import FlowTemplateJSON from '../../../fixtures/plugins/dashboards-assistant/flow-template.json'; import { BACKEND_BASE_PATH, BASE_PATH } from '../../constants'; import { ML_COMMONS_API, ASSISTANT_API } from './constants'; @@ -11,15 +10,7 @@ import clusterSettings from '../../../fixtures/plugins/dashboards-assistant/clus import { apiRequest } from '../../helpers'; Cypress.Commands.add('addAssistantRequiredSettings', () => { - let mergedSettings = clusterSettings; - if (Cypress.env('SECURITY_ENABLED')) { - mergedSettings = merge({}, clusterSettings, { - persistent: { - 'plugins.security.system_indices.enabled': false, - }, - }); - } - cy.request('PUT', `${BACKEND_BASE_PATH}/_cluster/settings`, mergedSettings); + cy.request('PUT', `${BACKEND_BASE_PATH}/_cluster/settings`, clusterSettings); }); const agentParameters = { From a119630a3370cf10c57ed7d58e0934d6c0b40cd1 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 5 Feb 2024 12:14:40 +0800 Subject: [PATCH 06/10] feat: run without security Signed-off-by: SuZhou-Joe --- .github/workflows/assistant-release-e2e-workflow.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/assistant-release-e2e-workflow.yml b/.github/workflows/assistant-release-e2e-workflow.yml index e82908770..4fcc4d6c3 100644 --- a/.github/workflows/assistant-release-e2e-workflow.yml +++ b/.github/workflows/assistant-release-e2e-workflow.yml @@ -15,12 +15,12 @@ jobs: tests: - 'cypress/**/dashboards-assistant/**' - tests: + tests-without-security: needs: changes if: ${{ needs.changes.outputs.tests == 'true' }} uses: ./.github/workflows/release-e2e-workflow-template.yml with: test-name: dashboards assistant - test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*' + test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*' osd-serve-args: --assistant.chat.enabled=true security-enabled: false From 01b1794da5c48e44a69d1caaf93beeb8d4705a47 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Mon, 5 Feb 2024 18:48:15 +0800 Subject: [PATCH 07/10] feat: optimize config retrieve logic Signed-off-by: SuZhou-Joe --- .../chatbot_agent_framework_spec.js | 4 +++- cypress/support/index.js | 2 +- .../plugins/dashboards-assistant/commands.js | 20 ++++++++++++++++--- .../plugins/dashboards-assistant/constants.js | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cypress/integration/plugins/dashboards-assistant/chatbot_agent_framework_spec.js b/cypress/integration/plugins/dashboards-assistant/chatbot_agent_framework_spec.js index 6e24d1b69..0092c13ce 100644 --- a/cypress/integration/plugins/dashboards-assistant/chatbot_agent_framework_spec.js +++ b/cypress/integration/plugins/dashboards-assistant/chatbot_agent_framework_spec.js @@ -27,7 +27,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { describe('Interact with Agent framework', () => { it('toggle Chatbot and enable to interact', () => { // The header may render multiple times, wait for UI to be stable - cy.wait(10000); + cy.wait(5000); // enable to toggle and show Chatbot cy.get(`img[aria-label="toggle chat flyout icon"]`).click(); @@ -42,6 +42,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { // should have a suggestion section cy.get(`[aria-label="chat suggestions"]`).should('be.length', 1); + cy.contains('suggestion1'); // Click regenerate button cy.get(`button[title="regenerate message"]`).click(); @@ -59,6 +60,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { // should have a suggestion section cy.get(`[aria-label="chat suggestions"]`).should('be.length', 1); + cy.contains('suggestion2'); }); }); }); diff --git a/cypress/support/index.js b/cypress/support/index.js index 56efee283..ef28be2d7 100644 --- a/cypress/support/index.js +++ b/cypress/support/index.js @@ -65,7 +65,7 @@ if (Cypress.env('ENDPOINT_WITH_PROXY')) { if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) { before(() => { cy.addAssistantRequiredSettings(); - cy.registerRootAgent(); + cy.readOrRegisterRootAgent(); cy.startDummyServer(); }); after(() => { diff --git a/cypress/utils/plugins/dashboards-assistant/commands.js b/cypress/utils/plugins/dashboards-assistant/commands.js index 9028bd6a0..07fc08b66 100644 --- a/cypress/utils/plugins/dashboards-assistant/commands.js +++ b/cypress/utils/plugins/dashboards-assistant/commands.js @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { get } from 'lodash'; import FlowTemplateJSON from '../../../fixtures/plugins/dashboards-assistant/flow-template.json'; import { BACKEND_BASE_PATH, BASE_PATH } from '../../constants'; import { ML_COMMONS_API, ASSISTANT_API } from './constants'; @@ -20,10 +21,23 @@ const agentParameters = { rootAgentId: '', }; +Cypress.Commands.add('readOrRegisterRootAgent', () => { + cy.request({ + url: `${BACKEND_BASE_PATH}${ML_COMMONS_API.AGENT_CONFIG}`, + method: 'GET', + failOnStatusCode: false, + }).then((resp) => { + const agentId = get(resp, 'body.configuration.agent_id'); + if (agentId) { + cy.log(`Already initialized agent: ${agentId}, skip the initialize step`); + } else { + cy.log(`Agent id not initialized yet, set up agent`); + return cy.registerRootAgent(); + } + }); +}); + Cypress.Commands.add('registerRootAgent', () => { - // ML needs 10 seconds to initialize its master key - // The ML encryption master key has not been initialized yet. Please retry after waiting for 10 seconds. - cy.wait(10000); /** * TODO use flow framework if the plugin get integrate in the future. */ diff --git a/cypress/utils/plugins/dashboards-assistant/constants.js b/cypress/utils/plugins/dashboards-assistant/constants.js index 8b26f257a..b9e45f285 100644 --- a/cypress/utils/plugins/dashboards-assistant/constants.js +++ b/cypress/utils/plugins/dashboards-assistant/constants.js @@ -15,6 +15,7 @@ export const ML_COMMONS_API = { CREATE_MODEL: `${ML_COMMONS_API_PREFIX}/models/_register`, CREATE_AGENT: `${ML_COMMONS_API_PREFIX}/agents/_register`, UPDATE_ROOT_AGENT_CONFIG: `/.plugins-ml-config/_doc/os_chat`, + AGENT_CONFIG: `${ML_COMMONS_API_PREFIX}/config/os_chat`, }; export const ASSISTANT_API_BASE = '/api/assistant'; From 248e174bd678158aeb79e4746afd60ade8fb5620 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Tue, 6 Feb 2024 11:34:09 +0800 Subject: [PATCH 08/10] feat: enable run when security enabled Signed-off-by: SuZhou-Joe --- .../assistant-release-e2e-workflow.yml | 9 +++ .../dashboards-assistant/security-cert.js | 65 +++++++++++++++++++ .../plugins/dashboards-assistant/commands.js | 35 +++++++--- 3 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 cypress/fixtures/plugins/dashboards-assistant/security-cert.js diff --git a/.github/workflows/assistant-release-e2e-workflow.yml b/.github/workflows/assistant-release-e2e-workflow.yml index 4fcc4d6c3..d17d60889 100644 --- a/.github/workflows/assistant-release-e2e-workflow.yml +++ b/.github/workflows/assistant-release-e2e-workflow.yml @@ -15,6 +15,15 @@ jobs: tests: - 'cypress/**/dashboards-assistant/**' + tests-with-security: + needs: changes + if: ${{ needs.changes.outputs.tests == 'true' }} + uses: ./.github/workflows/release-e2e-workflow-template.yml + with: + test-name: dashboards assistant + test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*' + osd-serve-args: --assistant.chat.enabled=true + tests-without-security: needs: changes if: ${{ needs.changes.outputs.tests == 'true' }} diff --git a/cypress/fixtures/plugins/dashboards-assistant/security-cert.js b/cypress/fixtures/plugins/dashboards-assistant/security-cert.js new file mode 100644 index 000000000..5b54ec3c7 --- /dev/null +++ b/cypress/fixtures/plugins/dashboards-assistant/security-cert.js @@ -0,0 +1,65 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export const certPublicKeyContent = ` +-----BEGIN CERTIFICATE----- +MIIEmDCCA4CgAwIBAgIUZjrlDPP8azRDPZchA/XEsx0X2iYwDQYJKoZIhvcNAQEL +BQAwgY8xEzARBgoJkiaJk/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFt +cGxlMRkwFwYDVQQKDBBFeGFtcGxlIENvbSBJbmMuMSEwHwYDVQQLDBhFeGFtcGxl +IENvbSBJbmMuIFJvb3QgQ0ExITAfBgNVBAMMGEV4YW1wbGUgQ29tIEluYy4gUm9v +dCBDQTAeFw0yMzA4MjkyMDA2MzdaFw0zMzA4MjYyMDA2MzdaME0xCzAJBgNVBAYT +AmRlMQ0wCwYDVQQHDAR0ZXN0MQ8wDQYDVQQKDAZjbGllbnQxDzANBgNVBAsMBmNs +aWVudDENMAsGA1UEAwwEa2lyazCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAJVcOAQlCiuB9emCljROAXnlsPbG7PE3kNz2sN+BbGuw686Wgyl3uToVHvVs +paMmLUqm1KYz9wMSWTIBZgpJ9hYaIbGxD4RBb7qTAJ8Q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Mkww8/F5d7YYH77gIhGo+RITkKI3+5BxeBaUnrGvmHrpmpgRXWmINqr0 +0jsnN3u0OQKBgCf45vIgItSjQb8zonLz2SpZjTFy4XQ7I92gxnq8X0Q5z3B+o7tQ +K/4rNwTju/sGFHyXAJlX+nfcK4vZ4OBUJjP+C8CTjEotX4yTNbo3S6zjMyGQqDI5 +9aIOUY4pb+TzeUFJX7If5gR+DfGyQubvvtcg1K3GHu9u2l8FwLj87sRzAoGAflQF +RHuRiG+/AngTPnZAhc0Zq0kwLkpH2Rid6IrFZhGLy8AUL/O6aa0IGoaMDLpSWUJp +nBY2S57MSM11/MVslrEgGmYNnI4r1K25xlaqV6K6ztEJv6n69327MS4NG8L/gCU5 +3pEm38hkUi8pVYU7in7rx4TCkrq94OkzWJYurAkCgYATQCL/rJLQAlJIGulp8s6h +mQGwy8vIqMjAdHGLrCS35sVYBXG13knS52LJHvbVee39AbD5/LlWvjJGlQMzCLrw +F7oILW5kXxhb8S73GWcuMbuQMFVHFONbZAZgn+C9FW4l7XyRdkrbR1MRZ2km8YMs +/AHmo368d4PSNRMMzLHw8Q== +-----END PRIVATE KEY----- +`; diff --git a/cypress/utils/plugins/dashboards-assistant/commands.js b/cypress/utils/plugins/dashboards-assistant/commands.js index 07fc08b66..e6ae7d827 100644 --- a/cypress/utils/plugins/dashboards-assistant/commands.js +++ b/cypress/utils/plugins/dashboards-assistant/commands.js @@ -9,6 +9,10 @@ import { BACKEND_BASE_PATH, BASE_PATH } from '../../constants'; import { ML_COMMONS_API, ASSISTANT_API } from './constants'; import clusterSettings from '../../../fixtures/plugins/dashboards-assistant/cluster_settings.json'; import { apiRequest } from '../../helpers'; +import { + certPrivateKeyContent, + certPublicKeyContent, +} from '../../../fixtures/plugins/dashboards-assistant/security-cert'; Cypress.Commands.add('addAssistantRequiredSettings', () => { cy.request('PUT', `${BACKEND_BASE_PATH}/_cluster/settings`, clusterSettings); @@ -126,19 +130,30 @@ Cypress.Commands.add('registerRootAgent', () => { }) .then((resp) => { agentParameters.rootAgentId = resp.body.agent_id; - return cy.request( - 'POST', - `${BACKEND_BASE_PATH}${ML_COMMONS_API.UPDATE_ROOT_AGENT_CONFIG}`, - { - type: 'os_chat_root_agent', - configuration: { - agent_id: agentParameters.rootAgentId, - }, - } - ); + return cy.putRootAgentId(agentParameters.rootAgentId); }); }); +Cypress.Commands.add('putRootAgentId', (agentId) => { + if (Cypress.env('SECURITY_ENABLED')) { + // The .plugins-ml-config index is a system index and need to call the API by using certificate file + return cy.exec( + `curl -k --cert <(cat < { return; /** From e364d8472f56131086f8288888b25f5e98abd535 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Tue, 6 Feb 2024 11:47:54 +0800 Subject: [PATCH 09/10] feat: enable run when security enabled Signed-off-by: SuZhou-Joe --- cypress/utils/plugins/dashboards-assistant/commands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/utils/plugins/dashboards-assistant/commands.js b/cypress/utils/plugins/dashboards-assistant/commands.js index e6ae7d827..10a9d7e90 100644 --- a/cypress/utils/plugins/dashboards-assistant/commands.js +++ b/cypress/utils/plugins/dashboards-assistant/commands.js @@ -142,7 +142,7 @@ Cypress.Commands.add('putRootAgentId', (agentId) => { ); } else { return cy.request( - 'POST', + 'PUT', `${BACKEND_BASE_PATH}${ML_COMMONS_API.UPDATE_ROOT_AGENT_CONFIG}`, { type: 'os_chat_root_agent', From 8ac3a7e1ff308db6afce4faeb55ffe8a95949cb5 Mon Sep 17 00:00:00 2001 From: SuZhou-Joe Date: Tue, 6 Feb 2024 12:01:58 +0800 Subject: [PATCH 10/10] feat: add some comment Signed-off-by: SuZhou-Joe --- .../fixtures/plugins/dashboards-assistant/security-cert.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cypress/fixtures/plugins/dashboards-assistant/security-cert.js b/cypress/fixtures/plugins/dashboards-assistant/security-cert.js index 5b54ec3c7..7120b6606 100644 --- a/cypress/fixtures/plugins/dashboards-assistant/security-cert.js +++ b/cypress/fixtures/plugins/dashboards-assistant/security-cert.js @@ -3,6 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +/** + * This file should be somewhere else like plugins/security but as assistant is the only consumer of the content + * Would be better to keep within the directory of dashboards-assistant. + */ + export const certPublicKeyContent = ` -----BEGIN CERTIFICATE----- MIIEmDCCA4CgAwIBAgIUZjrlDPP8azRDPZchA/XEsx0X2iYwDQYJKoZIhvcNAQEL