Skip to content

Commit

Permalink
Add test that check TOTP codes
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Feb 10, 2024
1 parent ee9392b commit 5a9f38f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/test/java/dev/medzik/otp/TOTPGeneratorTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

public class TOTPGeneratorTests {
Expand All @@ -11,11 +12,23 @@ public void testGenerateTOTP() {
.type(OneTimePasswordType.TOTP)
.secret(OneTimePasswordParameters.Secret.generate())
.label(new OneTimePasswordParameters.Label("test"))
.issuer(new OneTimePasswordParameters.Issuer("test"))
.build();

String code = TOTPGenerator.now(params);

assertNotNull(code);
}

@Test
public void testTOTP() {
OneTimePasswordParameters params = OneTimePasswordParameters.builder()
.type(OneTimePasswordType.TOTP)
.secret(new OneTimePasswordParameters.Secret("JBSWY3DPEHPK3PXP"))
.label(new OneTimePasswordParameters.Label("test"))
.build();

assertEquals(TOTPGenerator.at(params, 1707566984), "785021");
assertEquals(TOTPGenerator.at(params, 1707567150), "342204");
assertEquals(TOTPGenerator.at(params, 1707567162), "342204");
}
}

0 comments on commit 5a9f38f

Please sign in to comment.