From 80e40aaa336b08af4180f42df6a2dc0ec4506b21 Mon Sep 17 00:00:00 2001 From: Frank Merkel <138444693+frankmer@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:09:45 +0100 Subject: [PATCH] fixed TTL_MINUTES handling --- lib/model/token_container.dart | 6 +++--- lib/model/tokens/push_token.dart | 9 ++------- lib/utils/object_validator.dart | 6 ++++++ test/unit_test/model/processor_result_test.dart | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/model/token_container.dart b/lib/model/token_container.dart index 702af1f1..7a4be7d0 100644 --- a/lib/model/token_container.dart +++ b/lib/model/token_container.dart @@ -70,7 +70,7 @@ class TokenContainer with _$TokenContainer { // Container registration: static const String ISSUER = 'issuer'; - static const String TTL = 'ttl'; + static const String TTL_MINUTES = 'ttl'; static const String NONCE = 'nonce'; static const String TIMESTAMP = 'time'; static const String FINALIZATION_URL = 'url'; @@ -109,7 +109,7 @@ class TokenContainer with _$TokenContainer { map: uriMap, validators: { ISSUER: const ObjectValidator(), - TTL: ObjectValidator(transformer: (value) => Duration(minutes: value)), + TTL_MINUTES: durationValidator.withDefault(const Duration(minutes: 10)), NONCE: const ObjectValidator(), TIMESTAMP: ObjectValidator(transformer: (v) => DateTime.parse(v)), FINALIZATION_URL: stringToUrivalidator, @@ -124,7 +124,7 @@ class TokenContainer with _$TokenContainer { ); return TokenContainer.unfinalized( issuer: uriMap[ISSUER], - ttl: uriMap[TTL], + ttl: uriMap[TTL_MINUTES], nonce: uriMap[NONCE], timestamp: uriMap[TIMESTAMP], serverUrl: uriMap[FINALIZATION_URL], diff --git a/lib/model/tokens/push_token.dart b/lib/model/tokens/push_token.dart index 982aaf89..e4ccfe3d 100644 --- a/lib/model/tokens/push_token.dart +++ b/lib/model/tokens/push_token.dart @@ -219,10 +219,7 @@ class PushToken extends Token { Token.ISSUER: const ObjectValidatorNullable(defaultValue: ''), Token.SERIAL: const ObjectValidator(), SSL_VERIFY: boolValidator.withDefault(true), - TTL_MINUTES: ObjectValidator( - transformer: (v) => Duration(minutes: v is int ? v : int.parse(v)), - defaultValue: const Duration(minutes: 10), - ), + TTL_MINUTES: durationValidator.withDefault(const Duration(minutes: 3)), ENROLLMENT_CREDENTIAL: const ObjectValidatorNullable(), ROLLOUT_URL: stringToUrivalidator, Token.IMAGE: stringToUriValidatorNullable, @@ -287,9 +284,7 @@ class PushToken extends Token { Token.ISSUER: const ObjectValidatorNullable(), Token.SERIAL: const ObjectValidatorNullable(), SSL_VERIFY: boolValidatorNullable, - TTL_MINUTES: ObjectValidatorNullable( - transformer: (v) => Duration(minutes: int.parse(v)), - ), + TTL_MINUTES: durationValidator.withDefault(const Duration(minutes: 3)), ENROLLMENT_CREDENTIAL: const ObjectValidatorNullable(), ROLLOUT_URL: stringToUriValidatorNullable, Token.IMAGE: stringToUriValidatorNullable, diff --git a/lib/utils/object_validator.dart b/lib/utils/object_validator.dart index 356946ee..06f6c3d7 100644 --- a/lib/utils/object_validator.dart +++ b/lib/utils/object_validator.dart @@ -24,6 +24,12 @@ import '../model/enums/encodings.dart'; import '../model/exception_errors/localized_argument_error.dart'; import 'logger.dart'; +final durationValidatorNullable = durationValidator.nullable(); +final durationValidator = ObjectValidator( + transformer: (v) => Duration(seconds: v is int ? v : int.parse(v)), + allowedValues: (v) => v.inSeconds > 0, +); + final otpAutjPeriodSecondsValidatorNullable = otpAuthPeriodSecondsValidator.nullable(); final otpAuthPeriodSecondsValidator = ObjectValidator( transformer: (v) { diff --git a/test/unit_test/model/processor_result_test.dart b/test/unit_test/model/processor_result_test.dart index 1094bd35..c38abdbc 100644 --- a/test/unit_test/model/processor_result_test.dart +++ b/test/unit_test/model/processor_result_test.dart @@ -20,12 +20,12 @@ void _testProcessorResult() { }); group('factories', () { test('success', () { - const ProcessorResult result = ProcessorResult.success('data'); + final ProcessorResult result = ProcessorResult.success('data'); expect(result, isA()); expect((result as ProcessorResultSuccess).resultData, 'data'); }); test('error', () { - const ProcessorResult result = ProcessorResult.failed('error'); + final ProcessorResult result = ProcessorResult.failed('error'); expect(result, isA()); expect((result as ProcessorResultFailed).message, 'error'); });