Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: created_at in totp devices #169

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/supertokens/storage/postgresql/Start.java
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ public void addInfoToNonAuthRecipesBasedOnUserId(TenantIdentifier tenantIdentifi
}
} else if (className.equals(TOTPStorage.class.getName())) {
try {
TOTPDevice device = new TOTPDevice(userId, "testDevice", "secret", 0, 30, false);
TOTPDevice device = new TOTPDevice(userId, "testDevice", "secret", 0, 30, false, System.currentTimeMillis());
this.startTransaction(con -> {
try {
long now = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static String getQueryToCreateUserDevicesTable(Start start) {
+ "period INTEGER NOT NULL,"
+ "skew INTEGER NOT NULL,"
+ "verified BOOLEAN NOT NULL,"
+ "created_at BIGINT,"
+ "CONSTRAINT " + Utils.getConstraintName(schema, tableName, null, "pkey")
+ " PRIMARY KEY (app_id, user_id, device_name),"
+ "CONSTRAINT " + Utils.getConstraintName(schema, tableName, "user_id", "fkey")
Expand Down Expand Up @@ -121,7 +122,7 @@ private static int insertUser_Transaction(Start start, Connection con, AppIdenti
private static int insertDevice_Transaction(Start start, Connection con, AppIdentifier appIdentifier, TOTPDevice device)
throws SQLException, StorageQueryException {
String QUERY = "INSERT INTO " + Config.getConfig(start).getTotpUserDevicesTable()
+ " (app_id, user_id, device_name, secret_key, period, skew, verified) VALUES (?, ?, ?, ?, ?, ?, ?)";
+ " (app_id, user_id, device_name, secret_key, period, skew, verified, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";

return update(con, QUERY, pst -> {
pst.setString(1, appIdentifier.getAppId());
Expand All @@ -131,6 +132,7 @@ private static int insertDevice_Transaction(Start start, Connection con, AppIden
pst.setInt(5, device.period);
pst.setInt(6, device.skew);
pst.setBoolean(7, device.verified);
pst.setLong(8, device.createdAt);
});
}

Expand Down Expand Up @@ -326,7 +328,8 @@ public TOTPDevice map(ResultSet result) throws SQLException {
result.getString("secret_key"),
result.getInt("period"),
result.getInt("skew"),
result.getBoolean("verified"));
result.getBoolean("verified"),
result.getLong("created_at"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public void testConcurrentDeleteAndUpdate() throws Exception {

// Create a device as well as a user:
TOTPSQLStorage totpStorage = (TOTPSQLStorage) StorageLayer.getStorage(process.getProcess());
TOTPDevice device = new TOTPDevice("user", "d1", "secret", 30, 1, false);
TOTPDevice device = new TOTPDevice("user", "d1", "secret", 30, 1, false, System.currentTimeMillis());
totpStorage.createDevice(new AppIdentifier(null, null), device);

long now = System.currentTimeMillis();
Expand Down Expand Up @@ -446,7 +446,7 @@ public void testConcurrentDeleteAndInsert() throws Exception {

// Create a device as well as a user:
TOTPSQLStorage totpStorage = (TOTPSQLStorage) StorageLayer.getStorage(process.getProcess());
TOTPDevice device = new TOTPDevice("user", "d1", "secret", 30, 1, false);
TOTPDevice device = new TOTPDevice("user", "d1", "secret", 30, 1, false, System.currentTimeMillis());
totpStorage.createDevice(new AppIdentifier(null, null), device);

long now = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void totpCodeLengthTest() throws Exception {
long now = System.currentTimeMillis();
long nextDay = now + 1000 * 60 * 60 * 24; // 1 day from now

TOTPDevice d1 = new TOTPDevice("user", "d1", "secret", 30, 1, false);
TOTPDevice d1 = new TOTPDevice("user", "d1", "secret", 30, 1, false, System.currentTimeMillis());
storage.createDevice(new AppIdentifier(null, null), d1);

// Try code with length > 8
Expand Down
Loading