From 7b9826fb28ba80b40d61d01a51496c688195ab03 Mon Sep 17 00:00:00 2001 From: Gbubemi Smith Date: Fri, 3 Jun 2022 10:26:23 +0100 Subject: [PATCH] [PS-250] Prevent timeouts less than 1 minute (#802) * Modified shouldlock functionality to handle the immediately valut timeout * Modified should lock functionality to handle the immediately valut timeout * corrected spelling * check to know when custom minutes in less than 1 * check for minimum allowed minutes * revert vault timeout service * lint fix * check moved to validate method * changed implementation * suggestion fixes * suggestion fixes * fixed comments * changed implementation * changed implementation * made method private --- .../settings/vault-timeout-input.component.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/angular/src/components/settings/vault-timeout-input.component.ts b/angular/src/components/settings/vault-timeout-input.component.ts index f2fe6d5287..eb6057f275 100644 --- a/angular/src/components/settings/vault-timeout-input.component.ts +++ b/angular/src/components/settings/vault-timeout-input.component.ts @@ -18,7 +18,14 @@ export class VaultTimeoutInputComponent implements ControlValueAccessor, Validat return this.form.get("vaultTimeout").value === VaultTimeoutInputComponent.CUSTOM_VALUE; } + get exceedsMinimumTimout(): boolean { + return ( + !this.showCustom || this.customTimeInMinutes() > VaultTimeoutInputComponent.MIN_CUSTOM_MINUTES + ); + } + static CUSTOM_VALUE = -100; + static MIN_CUSTOM_MINUTES = 0; form = this.formBuilder.group({ vaultTimeout: [null], @@ -132,10 +139,18 @@ export class VaultTimeoutInputComponent implements ControlValueAccessor, Validat return { policyError: true }; } + if (!this.exceedsMinimumTimout) { + return { minTimeoutError: true }; + } + return null; } registerOnValidatorChange(fn: () => void): void { this.validatorChange = fn; } + + private customTimeInMinutes() { + return this.form.get("custom.hours")?.value * 60 + this.form.get("custom.minutes")?.value; + } }