Skip to content

Commit

Permalink
[Fleet] Fix output form validation for trusted fingerprint (#125662)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Feb 15, 2022
1 parent 35f4ba5 commit 181d04c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { validateHosts, validateYamlConfig } from './output_form_validators';
import {
validateHosts,
validateYamlConfig,
validateCATrustedFingerPrint,
} from './output_form_validators';

describe('Output form validation', () => {
describe('validateHosts', () => {
Expand Down Expand Up @@ -72,4 +76,21 @@ describe('Output form validation', () => {
}
});
});
describe('validate', () => {
it('should work with a valid fingerprint', () => {
const res = validateCATrustedFingerPrint(
'9f0a10411457adde3982ef01df20d2e7aa53a8ef29c50bcbfa3f3e93aebf631b'
);

expect(res).toBeUndefined();
});

it('should return an error with a invalid formatted fingerprint', () => {
const res = validateCATrustedFingerPrint(
'9F:0A:10:41:14:57:AD:DE:39:82:EF:01:DF:20:D2:E7:AA:53:A8:EF:29:C5:0B:CB:FA:3F:3E:93:AE:BF:63:1B'
);

expect(res).toEqual(['CA trusted fingerprint should be a base64 CA sha256 fingerprint']);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function validateName(value: string) {
}

export function validateCATrustedFingerPrint(value: string) {
if (value !== '' && !value.match(/^[a-zA-Z0-9]$/)) {
if (value !== '' && !value.match(/^[a-zA-Z0-9]+$/)) {
return [
i18n.translate('xpack.fleet.settings.outputForm.caTrusterdFingerprintInvalidErrorMessage', {
defaultMessage: 'CA trusted fingerprint should be a base64 CA sha256 fingerprint',
Expand Down

0 comments on commit 181d04c

Please sign in to comment.