IDEA-200849 Password Safe: incorrect reaction on custom location setting for the (not existing) KeePass database

This commit is contained in:
Vladimir Krivosheev
2018-10-22 11:28:20 +02:00
parent b543cc8f18
commit 9621ea78cb
2 changed files with 4 additions and 6 deletions
@@ -126,7 +126,7 @@ internal open class KeePassFileManager(private val file: Path,
return true
}
fun askAndSetMasterKey(event: AnActionEvent?): Boolean {
fun askAndSetMasterKey(event: AnActionEvent?, topNote: String? = null): Boolean {
val contextComponent = event?.getData(PlatformDataKeys.CONTEXT_COMPONENT)
// to open old database, key can be required, so, to avoid showing 2 dialogs, check it before
@@ -138,7 +138,7 @@ internal open class KeePassFileManager(private val file: Path,
return requestCurrentAndNewKeys(contextComponent)
}
return requestMasterPassword("Set Master Password", contextComponent = contextComponent) {
return requestMasterPassword("Set Master Password", topNote = topNote, contextComponent = contextComponent) {
saveDatabase(file, db, createMasterKey(it), masterKeyFileStorage, secureRandom.value)
null
}
@@ -242,9 +242,6 @@ internal open class KeePassFileManager(private val file: Path,
return
}
requestMasterPassword("Set Master Password", topNote = "Database file located in custom location,\ntherefore custom master password is required.") {
masterKeyFileStorage.save(createMasterKey(it))
null
}
askAndSetMasterKey(null, topNote = "Database file located in custom location,\ntherefore custom master password is required.")
}
}
@@ -255,6 +255,7 @@ internal class KeePassFileManagerTest {
@Test
fun `require custom master password if need - not custom`() {
val store = createStore()
store.save(defaultEncryptionSpec)
TestKeePassFileManager(store, masterPasswordRequestAnswer = "bar42").setCustomMasterPasswordIfNeed(fsRule.fs.getPath("/someDefault"))
assertThat(MasterKeyFileStorage(store.masterKeyFile).load()!!.toString(Charsets.UTF_8)).isEqualTo("bar42")
assertThat(createTestStoreWithCustomMasterKey().get(testCredentialAttributes)!!.password!!.toString()).isEqualTo("p")