[Fleet] Fix output form validation for trusted fingerprint (#125662) (#125681)

(cherry picked from commit 181d04c2e1)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
This commit is contained in:
Kibana Machine 2022-02-15 12:25:22 -05:00 committed by GitHub
parent bc031b47df
commit b1ad06ab6b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -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', () => {
@ -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']);
});
});
});

View file

@ -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',