#1141 Add TOTP key field to database and PlayerAuth
- Add new field for storing TOTP key - Implement data source methods for manipulation of its value
This commit is contained in:
@@ -103,12 +103,14 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
assertThat(bobbyAuth, hasRegistrationInfo("127.0.4.22", 1436778723L));
|
||||
assertThat(bobbyAuth.getLastLogin(), equalTo(1449136800L));
|
||||
assertThat(bobbyAuth.getPassword(), equalToHash("$SHA$11aa0706173d7272$dbba966"));
|
||||
assertThat(bobbyAuth.getTotpKey(), equalTo("JBSWY3DPEHPK3PXP"));
|
||||
|
||||
assertThat(userAuth, hasAuthBasicData("user", "user", "user@example.org", "34.56.78.90"));
|
||||
assertThat(userAuth, hasAuthLocation(124.1, 76.3, -127.8, "nether", 0.23f, 4.88f));
|
||||
assertThat(userAuth, hasRegistrationInfo(null, 0));
|
||||
assertThat(userAuth.getLastLogin(), equalTo(1453242857L));
|
||||
assertThat(userAuth.getPassword(), equalToHash("b28c32f624a4eb161d6adc9acb5bfc5b", "f750ba32"));
|
||||
assertThat(userAuth.getTotpKey(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -494,4 +496,33 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
contains("user24", "user20", "user22", "user29", "user28",
|
||||
"user16", "user18", "user12", "user14", "user11"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetTotpKey() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
String newTotpKey = "My new TOTP key";
|
||||
|
||||
// when
|
||||
dataSource.setTotpKey("BObBy", newTotpKey);
|
||||
dataSource.setTotpKey("does-not-exist", "bogus");
|
||||
|
||||
// then
|
||||
assertThat(dataSource.getAuth("bobby").getTotpKey(), equalTo(newTotpKey));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveTotpKey() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
// when
|
||||
dataSource.removeTotpKey("BoBBy");
|
||||
dataSource.removeTotpKey("user");
|
||||
dataSource.removeTotpKey("does-not-exist");
|
||||
|
||||
// then
|
||||
assertThat(dataSource.getAuth("bobby").getTotpKey(), nullValue());
|
||||
assertThat(dataSource.getAuth("user").getTotpKey(), nullValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ CREATE TABLE authme (
|
||||
id INTEGER AUTO_INCREMENT,
|
||||
username VARCHAR(255) NOT NULL UNIQUE,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
totp VARCHAR(16),
|
||||
ip VARCHAR(40),
|
||||
lastlogin BIGINT,
|
||||
regdate BIGINT NOT NULL,
|
||||
@@ -22,7 +23,7 @@ CREATE TABLE authme (
|
||||
CONSTRAINT table_const_prim PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt, regdate, regip)
|
||||
VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world',-0.44,2.77,'your@email.com',0,'Bobby',NULL,1436778723,'127.0.4.22');
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt, regdate, regip, totp)
|
||||
VALUES (1,'bobby','$SHA$11aa0706173d7272$dbba966','123.45.67.89',1449136800,1.05,2.1,4.2,'world',-0.44,2.77,'your@email.com',0,'Bobby',NULL,1436778723,'127.0.4.22','JBSWY3DPEHPK3PXP');
|
||||
INSERT INTO authme (id, username, password, ip, lastlogin, x, y, z, world, yaw, pitch, email, isLogged, realname, salt, regdate)
|
||||
VALUES (NULL,'user','b28c32f624a4eb161d6adc9acb5bfc5b','34.56.78.90',1453242857,124.1,76.3,-127.8,'nether',0.23,4.88,'user@example.org',0,'user','f750ba32',0);
|
||||
|
||||
Reference in New Issue
Block a user