mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-12-04 15:39:34 +01:00
Add CLI tests and improve coding style and i18n
The CLI module was lacking unit test coverage and showed some severe coding style violations, which this patch addresses. In addition, all uses of qCritical() with untranslatble raw char* sequences were removed in favor of proper locale strings. These are written to STDERR through QTextStreams and support output redirection for testing purposes. With this change, error messages don't depend on the global Qt logging settings and targets anymore and go directly to the terminal or into a file if needed. This patch also fixes a bug discovered during unit test development, where the extract command would just dump the raw XML contents without decrypting embedded Salsa20-protected values first, making the XML export mostly useless, since passwords are scrambled. Lastly, all CLI commands received a dedicated -h/--help option.
This commit is contained in:
@@ -358,10 +358,10 @@ void KdbxXmlWriter::writeEntry(const Entry* entry)
|
||||
|
||||
bool protect =
|
||||
(((key == "Title") && m_meta->protectTitle()) || ((key == "UserName") && m_meta->protectUsername())
|
||||
|| ((key == "Password") && m_meta->protectPassword())
|
||||
|| ((key == "URL") && m_meta->protectUrl())
|
||||
|| ((key == "Notes") && m_meta->protectNotes())
|
||||
|| entry->attributes()->isProtected(key));
|
||||
|| ((key == "Password") && m_meta->protectPassword())
|
||||
|| ((key == "URL") && m_meta->protectUrl())
|
||||
|| ((key == "Notes") && m_meta->protectNotes())
|
||||
|| entry->attributes()->isProtected(key));
|
||||
|
||||
writeString("Key", key);
|
||||
|
||||
@@ -369,7 +369,7 @@ void KdbxXmlWriter::writeEntry(const Entry* entry)
|
||||
QString value;
|
||||
|
||||
if (protect) {
|
||||
if (m_randomStream) {
|
||||
if (!m_innerStreamProtectionDisabled && m_randomStream) {
|
||||
m_xml.writeAttribute("Protected", "True");
|
||||
bool ok;
|
||||
QByteArray rawData = m_randomStream->process(entry->attributes()->value(key).toUtf8(), &ok);
|
||||
@@ -596,3 +596,24 @@ void KdbxXmlWriter::raiseError(const QString& errorMessage)
|
||||
m_error = true;
|
||||
m_errorStr = errorMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable inner stream protection and write protected fields
|
||||
* in plaintext instead. This is useful for plaintext XML exports
|
||||
* where the inner stream key is not available.
|
||||
*
|
||||
* @param disable true to disable protection
|
||||
*/
|
||||
void KdbxXmlWriter::disableInnerStreamProtection(bool disable)
|
||||
{
|
||||
m_innerStreamProtectionDisabled = disable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if inner stream protection is disabled and protected
|
||||
* fields will be saved in plaintext
|
||||
*/
|
||||
bool KdbxXmlWriter::innerStreamProtectionDisabled() const
|
||||
{
|
||||
return m_innerStreamProtectionDisabled;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user