Skip to content

Commit

Permalink
fixed TTL_MINUTES handling
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Dec 9, 2024
1 parent be601cc commit 80e40aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/model/token_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -109,7 +109,7 @@ class TokenContainer with _$TokenContainer {
map: uriMap,
validators: {
ISSUER: const ObjectValidator<String>(),
TTL: ObjectValidator<Duration>(transformer: (value) => Duration(minutes: value)),
TTL_MINUTES: durationValidator.withDefault(const Duration(minutes: 10)),
NONCE: const ObjectValidator<String>(),
TIMESTAMP: ObjectValidator<DateTime>(transformer: (v) => DateTime.parse(v)),
FINALIZATION_URL: stringToUrivalidator,
Expand All @@ -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],
Expand Down
9 changes: 2 additions & 7 deletions lib/model/tokens/push_token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,7 @@ class PushToken extends Token {
Token.ISSUER: const ObjectValidatorNullable<String>(defaultValue: ''),
Token.SERIAL: const ObjectValidator<String>(),
SSL_VERIFY: boolValidator.withDefault(true),
TTL_MINUTES: ObjectValidator<Duration>(
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<String>(),
ROLLOUT_URL: stringToUrivalidator,
Token.IMAGE: stringToUriValidatorNullable,
Expand Down Expand Up @@ -287,9 +284,7 @@ class PushToken extends Token {
Token.ISSUER: const ObjectValidatorNullable<String>(),
Token.SERIAL: const ObjectValidatorNullable<String>(),
SSL_VERIFY: boolValidatorNullable,
TTL_MINUTES: ObjectValidatorNullable<Duration>(
transformer: (v) => Duration(minutes: int.parse(v)),
),
TTL_MINUTES: durationValidator.withDefault(const Duration(minutes: 3)),
ENROLLMENT_CREDENTIAL: const ObjectValidatorNullable<String>(),
ROLLOUT_URL: stringToUriValidatorNullable,
Token.IMAGE: stringToUriValidatorNullable,
Expand Down
6 changes: 6 additions & 0 deletions lib/utils/object_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>(
transformer: (v) => Duration(seconds: v is int ? v : int.parse(v)),
allowedValues: (v) => v.inSeconds > 0,
);

final otpAutjPeriodSecondsValidatorNullable = otpAuthPeriodSecondsValidator.nullable();
final otpAuthPeriodSecondsValidator = ObjectValidator<int>(
transformer: (v) {
Expand Down
4 changes: 2 additions & 2 deletions test/unit_test/model/processor_result_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ void _testProcessorResult() {
});
group('factories', () {
test('success', () {
const ProcessorResult<String> result = ProcessorResult.success('data');
final ProcessorResult<String> result = ProcessorResult.success('data');
expect(result, isA<ProcessorResultSuccess>());
expect((result as ProcessorResultSuccess).resultData, 'data');
});
test('error', () {
const ProcessorResult<String> result = ProcessorResult.failed('error');
final ProcessorResult<String> result = ProcessorResult.failed('error');
expect(result, isA<ProcessorResultFailed>());
expect((result as ProcessorResultFailed).message, 'error');
});
Expand Down

0 comments on commit 80e40aa

Please sign in to comment.