123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package com.chameth.yaotp.algos
-
- import com.natpryce.hamkrest.assertion.assert
- import com.natpryce.hamkrest.equalTo
- import org.junit.Test
-
- class TotpTest {
-
- private val rfcKey = "12345678901234567890".toByteArray()
-
- @Test
- fun testCount_withDefaultStepAndStart_andPastValues() {
- assert.that(count(0, 30, 59), equalTo(1L))
- assert.that(count(0, 30, 1111111109), equalTo(37037036L))
- assert.that(count(0, 30, 1234567890), equalTo(41152263L))
- }
-
- @Test
- fun testCount_withDefaultStepAndStart_andFutureDates() {
- assert.that(count(0, 30, 2000000000), equalTo(66666666L))
- assert.that(count(0, 30, 20000000000), equalTo(666666666L))
- }
-
- @Test
- fun testCount_withCustomStepAndStart() {
- assert.that(count(2000000000, 30, 4000000000), equalTo(66666666L))
- assert.that(count(0, 60, 4000000000), equalTo(66666666L))
- }
-
- @Test
- fun testLongToByteArray_withRfcValues() {
- assert.that(1L.toByteArray().toHexString(), equalTo("0000000000000001"))
- assert.that(37037036L.toByteArray().toHexString(), equalTo("00000000023523ec"))
- assert.that(41152263L.toByteArray().toHexString(), equalTo("000000000273ef07"))
- assert.that(666666666L.toByteArray().toHexString(), equalTo("0000000027bc86aa"))
- }
-
- @Test
- fun testTotp_withRfcValues_usingSha1() {
- assert.that(totp(rfcKey, 0, 30, 59, 8), equalTo(94287082))
- assert.that(totp(rfcKey, 0, 30, 1111111109, 8), equalTo(7081804))
- assert.that(totp(rfcKey, 0, 30, 1111111111, 8), equalTo(14050471))
- assert.that(totp(rfcKey, 0, 30, 1234567890, 8), equalTo(89005924))
- assert.that(totp(rfcKey, 0, 30, 2000000000, 8), equalTo(69279037))
- assert.that(totp(rfcKey, 0, 30, 20000000000, 8), equalTo(65353130))
- }
-
- }
|