mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
CredentialStore: fix empty-string username removal
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user