Skip to content

Commit

Permalink
UI: add info banner for not parsable certs (hashicorp#20518)
Browse files Browse the repository at this point in the history
* remove undefined payload.issuer_id

* add info banner to parsed display view

* add tests

* clean up conditional, add specific banner test selector

* check for undefined length
  • Loading branch information
hellobontempo authored May 4, 2023
1 parent fd26fd5 commit 570a33b
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
1 change: 0 additions & 1 deletion ui/app/serializers/pki/issuer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default class PkiIssuerSerializer extends ApplicationSerializer {
// Parse certificate back from the API and add to payload
const parsedCert = parseCertificate(payload.data.certificate);
const data = {
issuer_ref: payload.issuer_id,
...payload.data,
parsed_certificate: parsedCert,
common_name: parsedCert.common_name,
Expand Down
15 changes: 14 additions & 1 deletion ui/lib/pki/addon/components/parsed-certificate-info-rows.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,17 @@
@formatDate={{field.formatDate}}
/>
{{/let}}
{{/each}}
{{/each}}
{{#if (or (eq @model.can_parse false) this.parsingErrors)}}
<AlertBanner
data-test-parsing-error-alert-banner
class="has-top-margin-m"
@type="info"
@title="There was an error parsing certificate metadata"
>
Vault cannot display unparsed values, but this will not interfere with the certificate's functionality.
{{#if this.parsingErrors}}
<p class="sub-text is-font-mono">Parsing error(s): {{this.parsingErrors}} </p>
{{/if}}
</AlertBanner>
{{/if}}
7 changes: 7 additions & 0 deletions ui/lib/pki/addon/components/parsed-certificate-info-rows.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ export default class ParsedCertificateInfoRowsComponent extends Component {
};
});
}

get parsingErrors() {
if (this.args.model?.parsing_errors?.length) {
return this.args.model.parsing_errors.map((e) => e.message).join(', ');
}
return '';
}
}
1 change: 1 addition & 0 deletions ui/tests/helpers/pki/values.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { setupRenderingTest } from 'vault/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { setupEngine } from 'ember-engines/test-support';
import { parseCertificate } from 'vault/utils/parse-pki-cert';
import { unsupportedOids } from 'vault/tests/helpers/pki/values';

module('Integration | Component | parsed-certificate-info-rows', function (hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -36,5 +38,56 @@ module('Integration | Component | parsed-certificate-info-rows', function (hooks
assert.dom('[data-test-row-value="Subject Alternative Names (SANs)"]').hasText('something,here');
assert.dom('[data-test-value-div="Use PSS"]').hasText('No', 'Booleans are rendered');
assert.dom('[data-test-value-div="ttl"]').doesNotExist('ttl is not rendered because value undefined');
assert
.dom('[data-test-parsing-error-alert-banner]')
.doesNotExist('does not render parsing error info banner');
});

test('it renders info banner when parsing fails and no parsing errors', async function (assert) {
this.set('parsedCertificate', {
can_parse: false,
});
await render(hbs`<ParsedCertificateInfoRows @model={{this.parsedCertificate}} />`, {
owner: this.engine,
});

assert
.dom('[data-test-parsing-error-alert-banner]')
.hasText(
"There was an error parsing certificate metadata Vault cannot display unparsed values, but this will not interfere with the certificate's functionality."
);
});

test('it renders info banner when parsing fails and parsing errors exist', async function (assert) {
this.set('parsedCertificate', {
can_parse: false,
parsing_errors: [new Error('some parsing error')],
});
await render(hbs`<ParsedCertificateInfoRows @model={{this.parsedCertificate}} />`, {
owner: this.engine,
});

assert
.dom('[data-test-parsing-error-alert-banner]')
.hasText(
"There was an error parsing certificate metadata Vault cannot display unparsed values, but this will not interfere with the certificate's functionality. Parsing error(s): some parsing error"
);
});

test('it renders info banner when parsing is successful but unsupported OIDs return parsing errors', async function (assert) {
const { parsing_errors } = parseCertificate(unsupportedOids);
this.set('parsedCertificate', {
can_parse: true,
parsing_errors,
});
await render(hbs`<ParsedCertificateInfoRows @model={{this.parsedCertificate}} />`, {
owner: this.engine,
});

assert
.dom('[data-test-parsing-error-alert-banner]')
.hasText(
"There was an error parsing certificate metadata Vault cannot display unparsed values, but this will not interfere with the certificate's functionality. Parsing error(s): certificate contains unsupported subject OIDs: 1.2.840.113549.1.9.1, certificate contains unsupported extension OIDs: 2.5.29.37"
);
});
});

0 comments on commit 570a33b

Please sign in to comment.