|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +import expect from '@kbn/expect'; |
| 9 | +import { CustomIntegration } from '../../../services/package_api'; |
| 10 | +import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context'; |
| 11 | +import { RoleCredentials, SupertestWithRoleScopeType } from '../../../services'; |
| 12 | + |
| 13 | +export default function ({ getService }: DeploymentAgnosticFtrProviderContext) { |
| 14 | + const samlAuth = getService('samlAuth'); |
| 15 | + const roleScopedSupertest = getService('roleScopedSupertest'); |
| 16 | + const packageApi = getService('packageApi'); |
| 17 | + |
| 18 | + const integrationPackages = ['nginx', 'apache']; |
| 19 | + const customIntegrations: CustomIntegration[] = [ |
| 20 | + { |
| 21 | + integrationName: 'my.custom.integration', |
| 22 | + datasets: [ |
| 23 | + { |
| 24 | + name: 'my.custom.integration', |
| 25 | + type: 'logs', |
| 26 | + }, |
| 27 | + ], |
| 28 | + }, |
| 29 | + ]; |
| 30 | + |
| 31 | + async function callApiAs( |
| 32 | + roleScopedSupertestWithCookieCredentials: SupertestWithRoleScopeType, |
| 33 | + integration: string |
| 34 | + ) { |
| 35 | + return roleScopedSupertestWithCookieCredentials.get( |
| 36 | + `/internal/dataset_quality/integrations/${integration}/dashboards` |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + describe('Integration dashboards', () => { |
| 41 | + let adminRoleAuthc: RoleCredentials; |
| 42 | + before(async () => { |
| 43 | + adminRoleAuthc = await samlAuth.createM2mApiKeyWithRoleScope('admin'); |
| 44 | + await Promise.all( |
| 45 | + integrationPackages.map((pkg) => |
| 46 | + packageApi.installPackage({ |
| 47 | + roleAuthc: adminRoleAuthc, |
| 48 | + pkg, |
| 49 | + }) |
| 50 | + ) |
| 51 | + ); |
| 52 | + |
| 53 | + await Promise.all( |
| 54 | + customIntegrations.map((customIntegration) => |
| 55 | + packageApi.installCustomIntegration({ |
| 56 | + roleAuthc: adminRoleAuthc, |
| 57 | + customIntegration, |
| 58 | + }) |
| 59 | + ) |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + after(async () => { |
| 64 | + await Promise.all( |
| 65 | + integrationPackages.map((pkg) => |
| 66 | + packageApi.uninstallPackage({ roleAuthc: adminRoleAuthc, pkg }) |
| 67 | + ) |
| 68 | + ); |
| 69 | + |
| 70 | + await Promise.all( |
| 71 | + customIntegrations.map((customIntegration) => |
| 72 | + packageApi.uninstallPackage({ |
| 73 | + roleAuthc: adminRoleAuthc, |
| 74 | + pkg: customIntegration.integrationName, |
| 75 | + }) |
| 76 | + ) |
| 77 | + ); |
| 78 | + |
| 79 | + await samlAuth.invalidateM2mApiKeyWithRoleScope(adminRoleAuthc); |
| 80 | + }); |
| 81 | + |
| 82 | + describe('gets the installed integration dashboards', () => { |
| 83 | + let supertestViewerWithCookieCredentials: SupertestWithRoleScopeType; |
| 84 | + before(async () => { |
| 85 | + supertestViewerWithCookieCredentials = await roleScopedSupertest.getSupertestWithRoleScope( |
| 86 | + 'viewer', |
| 87 | + { |
| 88 | + useCookieHeader: true, |
| 89 | + withInternalHeaders: true, |
| 90 | + } |
| 91 | + ); |
| 92 | + }); |
| 93 | + |
| 94 | + it('returns a non-empty body', async () => { |
| 95 | + const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[0]); |
| 96 | + expect(resp.body).not.empty(); |
| 97 | + }); |
| 98 | + |
| 99 | + it('returns correct number of dashboard', async () => { |
| 100 | + const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[1]); |
| 101 | + expect(resp.body.dashboards.length).to.eql(2); |
| 102 | + }); |
| 103 | + |
| 104 | + it('returns a list of dashboards in the correct format', async () => { |
| 105 | + const expectedResult = { |
| 106 | + dashboards: [ |
| 107 | + { |
| 108 | + id: 'nginx-023d2930-f1a5-11e7-a9ef-93c69af7b129', |
| 109 | + title: '[Metrics Nginx] Overview', |
| 110 | + }, |
| 111 | + { |
| 112 | + id: 'nginx-046212a0-a2a1-11e7-928f-5dbe6f6f5519', |
| 113 | + title: '[Logs Nginx] Access and error logs', |
| 114 | + }, |
| 115 | + { |
| 116 | + id: 'nginx-55a9e6e0-a29e-11e7-928f-5dbe6f6f5519', |
| 117 | + title: '[Logs Nginx] Overview', |
| 118 | + }, |
| 119 | + ], |
| 120 | + }; |
| 121 | + const resp = await callApiAs(supertestViewerWithCookieCredentials, integrationPackages[0]); |
| 122 | + expect(resp.body).to.eql(expectedResult); |
| 123 | + }); |
| 124 | + |
| 125 | + it('returns an empty array for an integration without dashboards', async () => { |
| 126 | + const expectedResult = { |
| 127 | + dashboards: [], |
| 128 | + }; |
| 129 | + const resp = await callApiAs( |
| 130 | + supertestViewerWithCookieCredentials, |
| 131 | + customIntegrations[0].integrationName |
| 132 | + ); |
| 133 | + expect(resp.body).to.eql(expectedResult); |
| 134 | + }); |
| 135 | + |
| 136 | + it('returns an empty array for an invalid integration', async () => { |
| 137 | + const expectedResult = { |
| 138 | + dashboards: [], |
| 139 | + }; |
| 140 | + const resp = await callApiAs(supertestViewerWithCookieCredentials, 'invalid'); |
| 141 | + expect(resp.body).to.eql(expectedResult); |
| 142 | + }); |
| 143 | + }); |
| 144 | + }); |
| 145 | +} |
0 commit comments