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);
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);
void populateCategoryGroups(Group* rootGroup);

View File

@ -53,12 +53,11 @@ namespace
void OpVaultReader::fillFromSection(Entry* entry, const QJsonObject& section)
{
const auto uuid = entry->uuid();
QString sectionName = section["name"].toString();
auto sectionTitle = section["title"].toString();
if (!section.contains("fields")) {
auto sectionNameLC = sectionName.toLower();
auto sectionTitleLC = section["title"].toString("").toLower();
if (!(sectionNameLC == "linked items" && sectionTitleLC == "related items")) {
auto sectionName = section["name"].toString();
if (!(sectionName.toLower() == "linked items" && sectionTitle.toLower() == "related items")) {
qWarning() << R"(Skipping "fields"-less Section in UUID ")" << uuid << "\": <<" << section << ">>";
}
return;
@ -67,23 +66,17 @@ void OpVaultReader::fillFromSection(Entry* entry, const QJsonObject& section)
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();
for (const QJsonValue sectionField : sectionFields) {
if (!sectionField.isObject()) {
qWarning() << R"(Skipping non-Object "fields" in UUID ")" << uuid << "\": << " << sectionField << ">>";
continue;
}
QJsonObject field = sectionField.toObject();
fillFromSectionField(entry, sectionName, field);
fillFromSectionField(entry, sectionTitle, sectionField.toObject());
}
}
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")) {
// 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") {
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");
QVERIFY(entry);
auto attr = entry->attributes();
QCOMPARE(attr->value("cardholder"), QStringLiteral("Team KeePassXC"));
QVERIFY(!attr->value("validFrom").isEmpty());
QCOMPARE(attr->value("details_pin"), QStringLiteral("1234"));
QVERIFY(attr->isProtected("details_pin"));
QCOMPARE(attr->value("cardholder name"), QStringLiteral("Team KeePassXC"));
QVERIFY(!attr->value("valid from").isEmpty());
QCOMPARE(attr->value("Additional Details_PIN"), QStringLiteral("1234"));
QVERIFY(attr->isProtected("Additional Details_PIN"));
// Confirm address fields
entry = db->rootGroup()->findEntryByPath("/Identity/Team KeePassXC");