Commit 7146d36b authored by Carlo Vanini's avatar Carlo Vanini Committed by Ingo Klöcker
Browse files

File name extension can be longer than 3 character

When verifying a detached signature, the length of the file name
extension was assumed to be 3 characters.
Instead of a fixed length, remove anything after (and including) the
last dot in the file name.
parent c93c3dfb
Pipeline #174487 passed with stage
in 1 minute and 57 seconds
......@@ -10,3 +10,10 @@ add_executable(kuniqueservicetest ${kuniqueservicetest_src})
add_test(NAME kuniqueservicetest COMMAND kuniqueservicetest)
ecm_mark_as_test(kuniqueservicetest)
target_link_libraries(kuniqueservicetest Qt${QT_MAJOR_VERSION}::Test ${_kleopatra_dbusaddons_libs})
set(stripsuffixtest_src stripsuffixtest.cpp ${CMAKE_SOURCE_DIR}/src/utils/path-helper.cpp)
ecm_qt_declare_logging_category(stripsuffixtest_src HEADER kleopatra_debug.h IDENTIFIER KLEOPATRA_LOG CATEGORY_NAME org.kde.pim.kleopatra)
add_executable(stripsuffixtest ${stripsuffixtest_src})
add_test(NAME stripsuffixtest COMMAND stripsuffixtest)
ecm_mark_as_test(stripsuffixtest)
target_link_libraries(stripsuffixtest Qt${QT_MAJOR_VERSION}::Test KF5::Libkleo KF5::I18n)
/* -*- mode: c++; c-basic-offset:4 -*-
autotests/stripsuffixtest.cpp
This file is part of Kleopatra's test suite.
SPDX-FileCopyrightText: 2022 Carlo Vanini <silhusk@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QDebug>
#include <QTest>
#include "utils/path-helper.h"
class StripSuffixTest: public QObject
{
Q_OBJECT
private Q_SLOTS:
void testStripSuffix_data();
void testStripSuffix();
};
void StripSuffixTest::testStripSuffix_data()
{
QTest::addColumn<QString>("fileName");
QTest::addColumn<QString>("baseName");
QTest::newRow("absolute path")
<< QString::fromLatin1("/home/user/test.sig")
<< QString::fromLatin1("/home/user/test");
QTest::newRow("relative path")
<< QString::fromLatin1("home/user.name/test.sig")
<< QString::fromLatin1("home/user.name/test");
QTest::newRow("file name")
<< QString::fromLatin1("t.sig")
<< QString::fromLatin1("./t");
QTest::newRow("short extension")
<< QString::fromLatin1("/path/to/test.s")
<< QString::fromLatin1("/path/to/test");
QTest::newRow("long extension")
<< QString::fromLatin1("/test.sign")
<< QString::fromLatin1("/test");
QTest::newRow("multiple extension")
<< QString::fromLatin1("some/test.tar.gz.asc")
<< QString::fromLatin1("some/test.tar.gz");
}
void StripSuffixTest::testStripSuffix()
{
QFETCH(QString, fileName);
QFETCH(QString, baseName);
QCOMPARE(Kleo::stripSuffix(fileName), baseName);
}
QTEST_MAIN(StripSuffixTest)
#include "stripsuffixtest.moc"
......@@ -238,7 +238,7 @@ QVector<AutoDecryptVerifyFilesController::Private::CryptoFile> AutoDecryptVerify
for (const auto &file : files) {
CryptoFile cFile;
cFile.fileName = file;
cFile.baseName = file.left(file.length() - 4);
cFile.baseName = stripSuffix(file);
cFile.classification = classify(file);
cFile.protocol = findProtocol(cFile.classification);
......
......@@ -91,6 +91,12 @@ QStringList Kleo::makeRelativeTo(const QDir &baseDir, const QStringList &fileNam
return rv;
}
QString Kleo::stripSuffix(const QString &fileName)
{
const QFileInfo fi(fileName);
return fi.dir().filePath(fi.completeBaseName());
}
void Kleo::recursivelyRemovePath(const QString &path)
{
const QFileInfo fi(path);
......
......@@ -19,6 +19,7 @@ namespace Kleo
QString heuristicBaseDirectory(const QStringList &files);
QStringList makeRelativeTo(const QDir &dir, const QStringList &files);
QStringList makeRelativeTo(const QString &dir, const QStringList &files);
QString stripSuffix(const QString &fileName);
void recursivelyRemovePath(const QString &path);
bool recursivelyCopy(const QString &src, const QString &dest);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment