mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-22 00:08:07 +01:00
Use java.time classes for stored verification code expiration; add tests.
This commit is contained in:
committed by
Jon Chambers
parent
ce3fb7fa99
commit
111f5ba024
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2013-2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.auth;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class StoredVerificationCodeTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void isValid(final StoredVerificationCode storedVerificationCode, final String code, final Instant currentTime, final boolean expectValid) {
|
||||
assertEquals(expectValid, storedVerificationCode.isValid(code, currentTime));
|
||||
}
|
||||
|
||||
private static Stream<Arguments> isValid() {
|
||||
final Instant now = Instant.now();
|
||||
|
||||
return Stream.of(
|
||||
Arguments.of(new StoredVerificationCode("code", now.toEpochMilli(), null, null), "code", now, true),
|
||||
Arguments.of(new StoredVerificationCode("code", now.toEpochMilli(), null, null), "incorrect", now, false),
|
||||
Arguments.of(new StoredVerificationCode("code", now.toEpochMilli(), null, null), "code", now.plus(Duration.ofHours(1)), false),
|
||||
Arguments.of(new StoredVerificationCode("", now.toEpochMilli(), null, null), "", now, false)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user