OPVault: Use Text instead of Name for attribute and section names

* Fix #6303 - the text attribute in 1Password contains the actual text seen in 1Password whereas the name attribute may contain a ref pointer and not a name.
This commit is contained in:
Jonathan White 2021-03-23 23:42:31 -04:00
parent ca8abecc4b
commit 871c4fffdd
3 changed files with 12 additions and 19 deletions

View file

@ -98,7 +98,7 @@ private:
bool fillAttributes(Entry* entry, const QJsonObject& bandEntry); bool fillAttributes(Entry* entry, const QJsonObject& bandEntry);
void fillFromSection(Entry* entry, const QJsonObject& section); void fillFromSection(Entry* entry, const QJsonObject& section);
void fillFromSectionField(Entry* entry, const QString& sectionName, QJsonObject& field); void fillFromSectionField(Entry* entry, const QString& sectionName, const QJsonObject& field);
QString resolveAttributeName(const QString& section, const QString& name, const QString& text); QString resolveAttributeName(const QString& section, const QString& name, const QString& text);
void populateCategoryGroups(Group* rootGroup); void populateCategoryGroups(Group* rootGroup);

View file

@ -53,12 +53,11 @@ namespace
void OpVaultReader::fillFromSection(Entry* entry, const QJsonObject& section) void OpVaultReader::fillFromSection(Entry* entry, const QJsonObject& section)
{ {
const auto uuid = entry->uuid(); const auto uuid = entry->uuid();
QString sectionName = section["name"].toString(); auto sectionTitle = section["title"].toString();
if (!section.contains("fields")) { if (!section.contains("fields")) {
auto sectionNameLC = sectionName.toLower(); auto sectionName = section["name"].toString();
auto sectionTitleLC = section["title"].toString("").toLower(); if (!(sectionName.toLower() == "linked items" && sectionTitle.toLower() == "related items")) {
if (!(sectionNameLC == "linked items" && sectionTitleLC == "related items")) {
qWarning() << R"(Skipping "fields"-less Section in UUID ")" << uuid << "\": <<" << section << ">>"; qWarning() << R"(Skipping "fields"-less Section in UUID ")" << uuid << "\": <<" << section << ">>";
} }
return; return;
@ -67,23 +66,17 @@ void OpVaultReader::fillFromSection(Entry* entry, const QJsonObject& section)
return; return;
} }
// If we have a default section name then replace with the section title if not empty
if (sectionName.startsWith("Section_") && !section["title"].toString().isEmpty()) {
sectionName = section["title"].toString();
}
QJsonArray sectionFields = section["fields"].toArray(); QJsonArray sectionFields = section["fields"].toArray();
for (const QJsonValue sectionField : sectionFields) { for (const QJsonValue sectionField : sectionFields) {
if (!sectionField.isObject()) { if (!sectionField.isObject()) {
qWarning() << R"(Skipping non-Object "fields" in UUID ")" << uuid << "\": << " << sectionField << ">>"; qWarning() << R"(Skipping non-Object "fields" in UUID ")" << uuid << "\": << " << sectionField << ">>";
continue; continue;
} }
QJsonObject field = sectionField.toObject(); fillFromSectionField(entry, sectionTitle, sectionField.toObject());
fillFromSectionField(entry, sectionName, field);
} }
} }
void OpVaultReader::fillFromSectionField(Entry* entry, const QString& sectionName, QJsonObject& field) void OpVaultReader::fillFromSectionField(Entry* entry, const QString& sectionName, const QJsonObject& field)
{ {
if (!field.contains("v")) { if (!field.contains("v")) {
// for our purposes, we don't care if there isn't a value in the field // for our purposes, we don't care if there isn't a value in the field
@ -161,8 +154,8 @@ QString OpVaultReader::resolveAttributeName(const QString& section, const QStrin
|| lowName == "website") { || lowName == "website") {
return EntryAttributes::URLKey; return EntryAttributes::URLKey;
} }
return name; return text;
} }
return QString("%1_%2").arg(section, name); return QString("%1_%2").arg(section, text);
} }

View file

@ -97,10 +97,10 @@ void TestOpVaultReader::testReadIntoDatabase()
entry = db->rootGroup()->findEntryByPath("/Credit Card/My Credit Card"); entry = db->rootGroup()->findEntryByPath("/Credit Card/My Credit Card");
QVERIFY(entry); QVERIFY(entry);
auto attr = entry->attributes(); auto attr = entry->attributes();
QCOMPARE(attr->value("cardholder"), QStringLiteral("Team KeePassXC")); QCOMPARE(attr->value("cardholder name"), QStringLiteral("Team KeePassXC"));
QVERIFY(!attr->value("validFrom").isEmpty()); QVERIFY(!attr->value("valid from").isEmpty());
QCOMPARE(attr->value("details_pin"), QStringLiteral("1234")); QCOMPARE(attr->value("Additional Details_PIN"), QStringLiteral("1234"));
QVERIFY(attr->isProtected("details_pin")); QVERIFY(attr->isProtected("Additional Details_PIN"));
// Confirm address fields // Confirm address fields
entry = db->rootGroup()->findEntryByPath("/Identity/Team KeePassXC"); entry = db->rootGroup()->findEntryByPath("/Identity/Team KeePassXC");