#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:
ljacqu
2018-03-05 19:50:58 +01:00
parent 930f5609bf
commit 9954c82cb6
10 changed files with 126 additions and 2 deletions
@@ -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());
}
}