Skip to content

Commit 760c5c2

Browse files
committed
Implement delete-entry request
1 parent 026852e commit 760c5c2

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/main/java/org/keepassxc/Connection.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,23 @@ public JSONObject getTotp(String uuid) throws IOException, KeepassProxyAccessExc
451451

452452
}
453453

454+
/**
455+
* Request to delete an entry, identified by its uuid.
456+
*
457+
* @param uuid The uuid of the entry.
458+
* @return An object that contains the key "success" with the value "true" in case the request was successful.
459+
* @throws IOException The request to delete the entry failed due to technical reasons.
460+
* @throws KeepassProxyAccessException The entry could not be deleted.
461+
*/
462+
public JSONObject deleteEntry(String uuid) throws IOException, KeepassProxyAccessException {
463+
// Send delete-entry request
464+
sendEncryptedMessage(Map.of(
465+
"action", "delete-entry",
466+
"uuid", ensureNotNull(uuid)
467+
));
468+
return getEncryptedResponseAndDecrypt("delete-entry");
469+
}
470+
454471
/**
455472
* Get a String representation of the JSON object.
456473
*

src/main/java/org/purejava/KeepassProxyAccess.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,22 @@ public String getTotp(String uuid) {
376376
}
377377
}
378378

379+
/**
380+
* Request to delete an entry, identified by its uuid.
381+
*
382+
* @param uuid The uuid of the entry.
383+
* @return True, in case the entry could be deleted, false otherwise.
384+
*/
385+
public boolean deleteEntry(String uuid) {
386+
try {
387+
var response = connection.deleteEntry(uuid);
388+
return response.has("success") && response.getString("success").equals("true");
389+
} catch (IOException | IllegalStateException | KeepassProxyAccessException | JSONException e) {
390+
log.info(e.toString(), e.getCause());
391+
return false;
392+
}
393+
}
394+
379395
/**
380396
* Extract the groupUuid for the newly created group.
381397
* Note: in case a group with the following path was created: level1/level2, only level2 gets returned as name.

src/test/java/org/purejava/UnlockedDatabaseTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public void shouldHaveNoErrors() {
4040
log.info("Please allow to create new group");
4141
assertEquals(kpa.createNewGroup("Testgroup").get("name"), "Testgroup");
4242
assertTrue(null != kpa.getTotp("2aafee1a89fd435c8bad7df12bbaaa3e") && !kpa.getTotp("2aafee1a89fd435c8bad7df12bbaaa3e").isEmpty());
43+
log.info("Please allow to delete entry");
44+
assertTrue(kpa.deleteEntry("2aafee1a89fd435c8bad7df12bbaaa3e"));
4345
log.info("Please deny to save changes");
4446
assertTrue(kpa.lockDatabase());
4547
}

0 commit comments

Comments
 (0)