CredentialStore: fix empty-string username removal

This commit is contained in:
Alexander Kass
2019-01-31 17:05:14 +03:00
parent 45592302ee
commit d5c0ca7425
2 changed files with 19 additions and 1 deletions
@@ -25,7 +25,7 @@ internal abstract class BaseKeePassCredentialStore : CredentialStore {
override fun set(attributes: CredentialAttributes, credentials: Credentials?) {
if (credentials == null) {
db.rootGroup.getGroup(ROOT_GROUP_NAME)?.removeEntry(attributes.serviceName, attributes.userName)
db.rootGroup.getGroup(ROOT_GROUP_NAME)?.removeEntry(attributes.serviceName, attributes.userName.nullize())
}
else {
val group = db.rootGroup.getOrCreateGroup(ROOT_GROUP_NAME)
@@ -60,6 +60,11 @@ internal class CredentialStoreTest {
testEmptyAccountName(InMemoryCredentialStore())
}
@Test
fun `KeePass - testEmptyStrAccountName`() {
testEmptyStrAccountName(InMemoryCredentialStore())
}
@Test
fun `KeePass - changedAccountName`() {
testChangedAccountName(InMemoryCredentialStore())
@@ -135,6 +140,19 @@ internal class CredentialStoreTest {
}
}
private fun testEmptyStrAccountName(store: CredentialStore) {
val attributes = CredentialAttributes("Test IJ — ${randomString()}", "")
try {
val credentials = Credentials("", "pass")
store.set(attributes, credentials)
assertThat(store.get(attributes)).isEqualTo(credentials)
}
finally {
store.set(attributes, null)
}
assertThat(store.get(attributes)).isNull()
}
private fun testChangedAccountName(store: CredentialStore) {
val serviceNameOnlyAttributes = CredentialAttributes("Test IJ — ${randomString()}")
try {