Skip to content

Commit

Permalink
refactor: Replace totp not enabled error with unknown device error
Browse files Browse the repository at this point in the history
  • Loading branch information
KShivendu committed Jun 27, 2023
1 parent 8e1865d commit c2ac05b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

- Replace `TOTP_NOT_ENABLED_ERROR` with other TOTP exceptions.
- Support for MFA recipe

### Changes
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/supertokens/storage/postgresql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import io.supertokens.pluginInterface.totp.TOTPStorage;
import io.supertokens.pluginInterface.totp.TOTPUsedCode;
import io.supertokens.pluginInterface.totp.exception.DeviceAlreadyExistsException;
import io.supertokens.pluginInterface.totp.exception.TotpNotEnabledException;
import io.supertokens.pluginInterface.totp.exception.UnknownDeviceException;
import io.supertokens.pluginInterface.totp.exception.UsedCodeAlreadyExistsException;
import io.supertokens.pluginInterface.totp.sqlStorage.TOTPSQLStorage;
Expand Down Expand Up @@ -2725,7 +2724,7 @@ public TOTPDevice[] getDevices_Transaction(TransactionConnection con, AppIdentif
@Override
public void insertUsedCode_Transaction(TransactionConnection con, TenantIdentifier tenantIdentifier,
TOTPUsedCode usedCodeObj)
throws StorageQueryException, TotpNotEnabledException, UsedCodeAlreadyExistsException,
throws StorageQueryException, UnknownDeviceException, UsedCodeAlreadyExistsException,
TenantOrAppNotFoundException {
Connection sqlCon = (Connection) con.getConnection();
try {
Expand All @@ -2737,7 +2736,7 @@ public void insertUsedCode_Transaction(TransactionConnection con, TenantIdentifi
throw new UsedCodeAlreadyExistsException();
} else if (isForeignKeyConstraintError(err, Config.getConfig(this).getTotpUsedCodesTable(),
"user_id")) {
throw new TotpNotEnabledException();
throw new UnknownDeviceException();
} else if (isForeignKeyConstraintError(err, Config.getConfig(this).getTotpUsedCodesTable(), "tenant_id")) {
throw new TenantOrAppNotFoundException(tenantIdentifier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import io.supertokens.pluginInterface.sqlStorage.SQLStorage.TransactionIsolationLevel;
import io.supertokens.pluginInterface.totp.TOTPDevice;
import io.supertokens.pluginInterface.totp.TOTPUsedCode;
import io.supertokens.pluginInterface.totp.exception.TotpNotEnabledException;
import io.supertokens.pluginInterface.totp.exception.UnknownDeviceException;
import io.supertokens.pluginInterface.totp.exception.UsedCodeAlreadyExistsException;
import io.supertokens.pluginInterface.totp.sqlStorage.TOTPSQLStorage;
import io.supertokens.storageLayer.StorageLayer;
Expand Down Expand Up @@ -266,7 +266,7 @@ public void testConcurrentDeleteAndUpdate() throws Exception {
try {
totpStorage.insertUsedCode_Transaction(con, new TenantIdentifier(null, null, null), code);
totpStorage.commitTransaction(con);
} catch (TotpNotEnabledException | UsedCodeAlreadyExistsException e) {
} catch (UnknownDeviceException | UsedCodeAlreadyExistsException e) {
// This should not happen
throw new StorageTransactionLogicException(e);
} catch (TenantOrAppNotFoundException e) {
Expand Down Expand Up @@ -428,7 +428,7 @@ public void testConcurrentDeleteAndInsert() throws Exception {
try {
totpStorage.insertUsedCode_Transaction(con, new TenantIdentifier(null, null, null), code);
totpStorage.commitTransaction(con);
} catch (TotpNotEnabledException | UsedCodeAlreadyExistsException e) {
} catch (UnknownDeviceException | UsedCodeAlreadyExistsException e) {
// This should not happen
throw new StorageTransactionLogicException(e);
} catch (TenantOrAppNotFoundException e) {
Expand Down Expand Up @@ -531,7 +531,7 @@ public void testConcurrentDeleteAndInsert() throws Exception {
TOTPUsedCode code2 = new TOTPUsedCode("user", "1234", false, nextDay, now + 1);
try {
totpStorage.insertUsedCode_Transaction(con, new TenantIdentifier(null, null, null), code2);
} catch (TotpNotEnabledException | UsedCodeAlreadyExistsException e) {
} catch (UnknownDeviceException | UsedCodeAlreadyExistsException e) {
// This should not happen
throw new StorageTransactionLogicException(e);
} catch (TenantOrAppNotFoundException e) {
Expand All @@ -546,7 +546,7 @@ public void testConcurrentDeleteAndInsert() throws Exception {
} catch (StorageTransactionLogicException e) {
Exception e2 = e.actualException;

if (e2 instanceof TotpNotEnabledException) {
if (e2 instanceof UnknownDeviceException) {
t2Failed.set(true);
}
} catch (StorageQueryException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.totp.TOTPDevice;
import io.supertokens.pluginInterface.totp.TOTPUsedCode;
import io.supertokens.pluginInterface.totp.exception.TotpNotEnabledException;
import io.supertokens.pluginInterface.totp.exception.UnknownDeviceException;
import io.supertokens.pluginInterface.totp.exception.UsedCodeAlreadyExistsException;
import io.supertokens.pluginInterface.totp.sqlStorage.TOTPSQLStorage;
import io.supertokens.storageLayer.StorageLayer;
Expand Down Expand Up @@ -46,15 +46,15 @@ public static void insertUsedCodeUtil(TOTPSQLStorage storage, TOTPUsedCode usedC
storage.insertUsedCode_Transaction(con, new TenantIdentifier(null, null, null), usedCode);
storage.commitTransaction(con);
return null;
} catch (TotpNotEnabledException | UsedCodeAlreadyExistsException e) {
} catch (UnknownDeviceException | UsedCodeAlreadyExistsException e) {
throw new StorageTransactionLogicException(e);
} catch (TenantOrAppNotFoundException e) {
throw new IllegalStateException(e);
}
});
} catch (StorageTransactionLogicException e) {
Exception actual = e.actualException;
if (actual instanceof TotpNotEnabledException || actual instanceof UsedCodeAlreadyExistsException) {
if (actual instanceof UnknownDeviceException || actual instanceof UsedCodeAlreadyExistsException) {
throw actual;
} else {
throw e;
Expand Down

0 comments on commit c2ac05b

Please sign in to comment.