From 855743fef0aafbf94fa725741afd472cad91de36 Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Wed, 11 Sep 2024 08:29:19 -0500 Subject: [PATCH 01/44] UI: Fix sanitization and add tests (#28347) --- ui/lib/core/addon/utils/client-count-utils.ts | 5 +- .../utils/client-count-utils-test.js | 72 +++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/ui/lib/core/addon/utils/client-count-utils.ts b/ui/lib/core/addon/utils/client-count-utils.ts index 91c6d08662e0..eb2024d2525b 100644 --- a/ui/lib/core/addon/utils/client-count-utils.ts +++ b/ui/lib/core/addon/utils/client-count-utils.ts @@ -85,8 +85,9 @@ export const filteredTotalForMount = ( if (!nsPath || !mountPath || isEmpty(byNamespace)) return emptyCounts(); return ( byNamespace - .find((namespace) => namespace.label === nsPath) - ?.mounts.find((mount: MountClients) => mount.label === mountPath) || emptyCounts() + .find((namespace) => sanitizePath(namespace.label) === sanitizePath(nsPath)) + ?.mounts.find((mount: MountClients) => sanitizePath(mount.label) === sanitizePath(mountPath)) || + emptyCounts() ); }; diff --git a/ui/tests/integration/utils/client-count-utils-test.js b/ui/tests/integration/utils/client-count-utils-test.js index 68aa399cc6cb..137fee715596 100644 --- a/ui/tests/integration/utils/client-count-utils-test.js +++ b/ui/tests/integration/utils/client-count-utils-test.js @@ -13,6 +13,7 @@ import { destructureClientCounts, sortMonthsByTimestamp, filterByMonthDataForMount, + filteredTotalForMount, } from 'core/utils/client-count-utils'; import clientsHandler from 'vault/mirage/handlers/clients'; import { @@ -481,4 +482,75 @@ module('Integration | Util | client count utils', function (hooks) { assert.deepEqual(result[0], this.getExpected('some-mount', 0), 'works when namespace is not found'); }); }); + + module('filteredTotalForMount', function (hooks) { + hooks.beforeEach(function () { + this.byNamespace = SERIALIZED_ACTIVITY_RESPONSE.by_namespace; + }); + + const emptyCounts = { + acme_clients: 0, + clients: 0, + entity_clients: 0, + non_entity_clients: 0, + secret_syncs: 0, + }; + + [ + { + when: 'no namespace filter passed', + result: 'it returns empty counts', + ns: '', + mount: 'auth/authid/0', + expected: emptyCounts, + }, + { + when: 'no mount filter passed', + result: 'it returns empty counts', + ns: 'ns1', + mount: '', + expected: emptyCounts, + }, + { + when: 'no matching ns/mount exists', + result: 'it returns empty counts', + ns: 'ns1', + mount: 'auth/authid/1', + expected: emptyCounts, + }, + { + when: 'mount and label have extra slashes', + result: 'it returns the data sanitized', + ns: 'ns1/', + mount: 'auth/authid/0/', + expected: { + label: 'auth/authid/0', + acme_clients: 0, + clients: 8394, + entity_clients: 4256, + non_entity_clients: 4138, + secret_syncs: 0, + }, + }, + { + when: 'mount within root', + result: 'it returns the data', + ns: 'root', + mount: 'kvv2-engine-0', + expected: { + label: 'kvv2-engine-0', + acme_clients: 0, + clients: 4290, + entity_clients: 0, + non_entity_clients: 0, + secret_syncs: 4290, + }, + }, + ].forEach((testCase) => { + test(`it returns correct values when ${testCase.when}`, async function (assert) { + const actual = filteredTotalForMount(this.byNamespace, testCase.ns, testCase.mount); + assert.deepEqual(actual, testCase.expected); + }); + }); + }); }); From abdeda43ca0f04342123e5fd0c908da9fdacbd64 Mon Sep 17 00:00:00 2001 From: Chelsea Shaw <82459713+hashishaw@users.noreply.github.com> Date: Wed, 11 Sep 2024 08:29:33 -0500 Subject: [PATCH 02/44] UI: hide client count nav link when chrooted listener (#28346) --- ui/app/components/sidebar/nav/cluster.hbs | 6 +++-- ui/app/components/sidebar/nav/cluster.js | 6 ++++- .../components/sidebar/nav/cluster-test.js | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ui/app/components/sidebar/nav/cluster.hbs b/ui/app/components/sidebar/nav/cluster.hbs index 76012058daa7..30f295d3c2df 100644 --- a/ui/app/components/sidebar/nav/cluster.hbs +++ b/ui/app/components/sidebar/nav/cluster.hbs @@ -53,7 +53,7 @@ {{#if (or (and this.isRootNamespace (has-permission "status" routeParams=(array "replication" "raft" "license" "seal"))) - (has-permission "clients" routeParams="activity") + (and (has-permission "clients" routeParams="activity") (not this.hasChrootNamespace)) ) }} Monitoring @@ -81,7 +81,9 @@ data-test-sidebar-nav-link="Raft Storage" /> {{/if}} - {{#if (and (has-permission "clients" routeParams="activity") (not this.cluster.dr.isSecondary))}} + {{#if + (and (has-permission "clients" routeParams="activity") (not this.cluster.dr.isSecondary) (not this.hasChrootNamespace)) + }}