Disable some fields if Steam OTP type is selected

Also, move some magic default OTP parameters to constants
This commit is contained in:
Alexander Bakker 2021-01-30 16:41:25 +01:00
parent bc6cb35dc0
commit 2c8a64f943
15 changed files with 55 additions and 29 deletions

View file

@ -8,6 +8,7 @@ import androidx.test.core.app.ApplicationProvider;
import com.beemdevelopment.aegis.encoding.Base32;
import com.beemdevelopment.aegis.encoding.EncodingException;
import com.beemdevelopment.aegis.otp.HotpInfo;
import com.beemdevelopment.aegis.otp.OtpInfo;
import com.beemdevelopment.aegis.otp.OtpInfoException;
import com.beemdevelopment.aegis.otp.SteamInfo;
import com.beemdevelopment.aegis.otp.TotpInfo;
@ -178,11 +179,11 @@ public class DatabaseImporterTest {
for (VaultEntry entry : entries) {
// Google Authenticator doesn't support different hash algorithms, periods or digits, so fix those up here
VaultEntry entryVector = getEntryVectorBySecret(entry.getInfo().getSecret());
entryVector.getInfo().setDigits(6);
entryVector.getInfo().setDigits(OtpInfo.DEFAULT_DIGITS);
if (entryVector.getInfo() instanceof TotpInfo) {
((TotpInfo) entryVector.getInfo()).setPeriod(30);
((TotpInfo) entryVector.getInfo()).setPeriod(TotpInfo.DEFAULT_PERIOD);
}
entryVector.getInfo().setAlgorithm("SHA1");
entryVector.getInfo().setAlgorithm(OtpInfo.DEFAULT_ALGORITHM);
checkImportedEntry(entryVector, entry);
}
}
@ -264,7 +265,7 @@ public class DatabaseImporterTest {
for (VaultEntry entry : entries) {
// Authy doesn't support different hash algorithms or periods, so fix those up here
VaultEntry entryVector = getEntryVectorBySecret(entry.getInfo().getSecret());
entryVector.getInfo().setAlgorithm("SHA1");
entryVector.getInfo().setAlgorithm(OtpInfo.DEFAULT_ALGORITHM);
((TotpInfo) entry.getInfo()).setPeriod(((TotpInfo) entryVector.getInfo()).getPeriod());
checkImportedEntry(entryVector, entry);
}
@ -274,9 +275,9 @@ public class DatabaseImporterTest {
for (VaultEntry entry : entries) {
// TOTP Authenticator doesn't support different hash algorithms, periods or digits, so fix those up here
VaultEntry entryVector = getEntryVectorBySecret(entry.getInfo().getSecret());
entryVector.getInfo().setDigits(6);
((TotpInfo) entryVector.getInfo()).setPeriod(30);
entryVector.getInfo().setAlgorithm("SHA1");
entryVector.getInfo().setDigits(OtpInfo.DEFAULT_DIGITS);
((TotpInfo) entryVector.getInfo()).setPeriod(TotpInfo.DEFAULT_PERIOD);
entryVector.getInfo().setAlgorithm(OtpInfo.DEFAULT_ALGORITHM);
entryVector.setName(entryVector.getName().toLowerCase());
checkImportedEntry(entryVector, entry);
}

View file

@ -11,7 +11,7 @@ public class OtpTest {
@Test
public void testHotpInfoOtp() throws OtpInfoException {
for (int i = 0; i < HOTPTest.VECTORS.length; i++) {
HotpInfo info = new HotpInfo(HOTPTest.SECRET, "SHA1", 6, i);
HotpInfo info = new HotpInfo(HOTPTest.SECRET, OtpInfo.DEFAULT_ALGORITHM, OtpInfo.DEFAULT_DIGITS, i);
assertEquals(HOTPTest.VECTORS[i], info.getOtp());
}
}
@ -20,7 +20,7 @@ public class OtpTest {
public void testTotpInfoOtp() throws OtpInfoException {
for (TOTPTest.Vector vector : TOTPTest.VECTORS) {
byte[] seed = TOTPTest.getSeed(vector.Algo);
TotpInfo info = new TotpInfo(seed, vector.Algo, 8, 30);
TotpInfo info = new TotpInfo(seed, vector.Algo, 8, TotpInfo.DEFAULT_PERIOD);
assertEquals(vector.OTP, info.getOtp(vector.Time));
}
}