/* * Copyright (C) 2024 KeePassXC Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 or (at your option) * version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "TestAuthenticationFactorParsing.h" #include QTEST_GUILESS_MAIN(TestAuthenticationFactorParsing) void TestAuthenticationFactorParsing::testNotXML() { m_reader.readAuthenticationFactors(nullptr, "blargh"); QVERIFY(m_reader.hasError()); } void TestAuthenticationFactorParsing::testMalformedXML() { m_reader.readAuthenticationFactors(nullptr, ""); QVERIFY(m_reader.hasError()); } void TestAuthenticationFactorParsing::testMissingFactorInfo() { m_reader.readAuthenticationFactors(nullptr, ""); QVERIFY(m_reader.hasError()); } void TestAuthenticationFactorParsing::testNoCompatVersion() { m_reader.readAuthenticationFactors(nullptr, ""); QVERIFY(m_reader.hasError()); } void TestAuthenticationFactorParsing::testUnsupportedCompatVersion() { m_reader.readAuthenticationFactors(nullptr, "2"); QVERIFY(m_reader.hasError()); } void TestAuthenticationFactorParsing::testNoGroups() { auto res = m_reader.readAuthenticationFactors(nullptr, "1"); QVERIFY(!m_reader.hasError()); QCOMPARE(res->getGroups().size(), 0); } void TestAuthenticationFactorParsing::testGroupWithNoFactors() { m_reader.readAuthenticationFactors(nullptr, "1"); QVERIFY(m_reader.hasError()); } void TestAuthenticationFactorParsing::testUnsupportedFactorTypeAlone() { m_reader.readAuthenticationFactors(nullptr, "1" "AES-CBCbogus" "B4pHAoQomD8728UKeST2HOxglrjzwyq2M/IPEOV4xo8=" ""); QVERIFY(m_reader.hasError()); } void TestAuthenticationFactorParsing::testUnsupportedFactorTypeAndSupportedTogether() { auto res = m_reader.readAuthenticationFactors( nullptr, "1" "AES-CBCbogus" "B4pHAoQomD8728UKeST2HOxglrjzwyq2M/IPEOV4xo8=" "AES-CBC" FACTOR_TYPE_PASSWORD_SHA256 "" "B4pHAoQomD8728UKeST2HOxglrjzwyq2M/IPEOV4xo8=" ""); QVERIFY(!m_reader.hasError()); QCOMPARE(res->getGroups().first()->getFactors().size(), 2); } void TestAuthenticationFactorParsing::testUnsupportedVerificationMethod() { auto res = m_reader.readAuthenticationFactors( nullptr, "1" "bogus" "AES-CBC" FACTOR_TYPE_PASSWORD_SHA256 "" "B4pHAoQomD8728UKeST2HOxglrjzwyq2M/IPEOV4xo8=" ""); QVERIFY(!m_reader.hasError()); QCOMPARE(res->getGroups().first()->getValidationType(), AuthenticationFactorGroupValidationType::NONE); } void TestAuthenticationFactorParsing::testOmittedVerification() { m_reader.readAuthenticationFactors(nullptr, "1" "AES-CBC" FACTOR_TYPE_PASSWORD_SHA256 "" "B4pHAoQomD8728UKeST2HOxglrjzwyq2M/IPEOV4xo8=" ""); QVERIFY(!m_reader.hasError()); } void TestAuthenticationFactorParsing::testInvalidBase64() { m_reader.readAuthenticationFactors(nullptr, "1" "AES-CBC" FACTOR_TYPE_PASSWORD_SHA256 "" "_" ""); QVERIFY(m_reader.hasError()); } void TestAuthenticationFactorParsing::testMissingRequiredFields() { m_reader.readAuthenticationFactors(nullptr, "1" "" FACTOR_TYPE_PASSWORD_SHA256 "" "B4pHAoQomD8728UKeST2HOxglrjzwyq2M/IPEOV4xo8=" ""); QVERIFY(m_reader.hasError()); }