Repository: hashicorp/vault
File: ui/tests/acceptance/secrets/backend/kv/kv-v2-workflow-edge-cases-test.js (JavaScript)

Code before:
      assert
        .dom(PAGE.error.message)
        .hasText(
          `Sorry, we were unable to find any content at /v1/${backend}/metadata/${root}/${subdirectory}.`
        );

      assert.dom(PAGE.breadcrumbAtIdx(0)).hasText('Secrets');
      assert.dom(PAGE.breadcrumbAtIdx(1)).hasText(backend);
      assert.dom(PAGE.secretTab('Secrets')).doesNotHaveClass('is-active');
      assert.dom(PAGE.secretTab('Configuration')).doesNotHaveClass('is-active');
    });

    // it's rare for a policy check to fail, but if it does we default to "true" and let the API handle gating.
    // there was an issue with the new capabilities service incorrectly mapping permissions for secrets with underscores which surfaced this bug.
    // The user logged in here does NOT have access to the subkeys endpoint, but we're stubbing capabilities to return true
    // to simulate the capabilities map failing and returning a false positive.
    test('it navigates to secret if policy check fails for the subkeys endpoint', async function (assert) {
      assert.expect(2);
      this.server.post(
        '/sys/capabilities-self',
        capabilitiesStub(`${this.backend}/subkeys/my_secret`, ['read'])
      );

      await visit(`/vault/secrets/${this.backend}/kv/list`);
      await typeIn(PAGE.list.overviewInput, 'my_secret');
      await click(GENERAL.submitButton);
      assert.strictEqual(
        currentURL(),
        `/vault/secrets/${this.backend}/kv/my_secret`,
        'it navigates to secret overview'
      );
      assert.dom(GENERAL.overviewCard.container('Paths')).exists();
    });
  });

  module('destruction without read', function (hooks) {
    hooks.beforeEach(async function () {
      const backend = this.backend;
      const testSecrets = [
        'data-delete-only',
        'delete-version-only',
        'destroy-version-only',
        'destroy-metadata-only',
      ];

      // user has different permissions for each secret path
      const token = await runCmd([
        createPolicyCmd(
          `destruction-no-read-${this.backend}`,
          dataPolicy({ backend, secretPath: 'data-delete-only', capabilities: ['delete'] }) +
            deleteVersionsPolicy({ backend, secretPath: 'delete-version-only' }) +

Review comment (suggestion):
```suggestion
      await click(PAGE.list.overviewButton);
```

Code after:
      assert
        .dom(PAGE.error.message)
        .hasText(
          `Sorry, we were unable to find any content at /v1/${backend}/metadata/${root}/${subdirectory}.`
        );

      assert.dom(PAGE.breadcrumbAtIdx(0)).hasText('Secrets');
      assert.dom(PAGE.breadcrumbAtIdx(1)).hasText(backend);
      assert.dom(PAGE.secretTab('Secrets')).doesNotHaveClass('is-active');
      assert.dom(PAGE.secretTab('Configuration')).doesNotHaveClass('is-active');
    });

    // it's rare for a policy check to fail, but if it does we default to "true" and let the API handle gating.
    // there was an issue with the new capabilities service incorrectly mapping permissions for secrets with underscores which surfaced this bug.
    // The user logged in here does NOT have access to the subkeys endpoint, but we're stubbing capabilities to return true
    // to simulate the capabilities map failing and returning a false positive.
    test('it navigates to secret if policy check fails for the subkeys endpoint', async function (assert) {
      assert.expect(2);
      this.server.post(
        '/sys/capabilities-self',
        capabilitiesStub(`${this.backend}/subkeys/my_secret`, ['read'])
      );

      await visit(`/vault/secrets/${this.backend}/kv/list`);
      await typeIn(PAGE.list.overviewInput, 'my_secret');
      await click(PAGE.list.overviewButton);
      assert.strictEqual(
        currentURL(),
        `/vault/secrets/${this.backend}/kv/my_secret`,
        'it navigates to secret overview'
      );
      assert.dom(GENERAL.overviewCard.container('Paths')).exists();
    });
  });

  module('destruction without read', function (hooks) {
    hooks.beforeEach(async function () {
      const backend = this.backend;
      const testSecrets = [
        'data-delete-only',
        'delete-version-only',
        'destroy-version-only',
        'destroy-metadata-only',
      ];

      // user has different permissions for each secret path
      const token = await runCmd([
        createPolicyCmd(
          `destruction-no-read-${this.backend}`,
          dataPolicy({ backend, secretPath: 'data-delete-only', capabilities: ['delete'] }) +
            deleteVersionsPolicy({ backend, secretPath: 'delete-version-only' }) +