keepassxc

Форк
0
/
TestFdoSecrets.cpp 
126 строк · 4.4 Кб
1
/*
2
 *  Copyright (C) 2019 Aetf <aetf@unlimitedcodeworks.xyz>
3
 *
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation, either version 2 or (at your option)
7
 *  version 3 of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
#include "TestFdoSecrets.h"
19

20
#include "core/EntrySearcher.h"
21
#include "core/Group.h"
22
#include "crypto/Random.h"
23
#include "fdosecrets/objects/Collection.h"
24
#include "fdosecrets/objects/SessionCipher.h"
25

26
#include <QTest>
27

28
QTEST_GUILESS_MAIN(TestFdoSecrets)
29

30
void TestFdoSecrets::testDhIetf1024Sha256Aes128CbcPkcs7()
31
{
32
    FdoSecrets::DhIetf1024Sha256Aes128CbcPkcs7 cipher(randomGen()->randomArray(128));
33
    QVERIFY(cipher.isValid());
34
}
35

36
void TestFdoSecrets::testCrazyAttributeKey()
37
{
38
    using FdoSecrets::Collection;
39
    using FdoSecrets::Item;
40

41
    const QScopedPointer<Group> root(new Group());
42
    const QScopedPointer<Entry> e1(new Entry());
43
    e1->setGroup(root.data());
44

45
    const QString key = "_a:bc&-+'-e%12df_d";
46
    const QString value = "value";
47
    e1->attributes()->set(key, value);
48

49
    // search for custom entries
50
    const auto term = Collection::attributeToTerm(key, value);
51
    const auto res = EntrySearcher().search({term}, root.data());
52
    QCOMPARE(res.count(), 1);
53
}
54

55
void TestFdoSecrets::testSpecialCharsInAttributeValue()
56
{
57
    using FdoSecrets::Collection;
58
    using FdoSecrets::Item;
59

60
    const QScopedPointer<Group> root(new Group());
61
    QScopedPointer<Entry> e1(new Entry());
62
    e1->setGroup(root.data());
63

64
    e1->setTitle("titleA");
65
    e1->attributes()->set("testAttribute", "OAuth::[test.name@gmail.com]");
66

67
    QScopedPointer<Entry> e2(new Entry());
68
    e2->setGroup(root.data());
69
    e2->setTitle("titleB");
70
    e2->attributes()->set("testAttribute", "Abc:*+.-");
71

72
    // search for custom entries via programmatic API
73
    {
74
        const auto term = Collection::attributeToTerm("testAttribute", "OAuth::[test.name@gmail.com]");
75
        const auto res = EntrySearcher().search({term}, root.data());
76
        QCOMPARE(res.count(), 1);
77
        QCOMPARE(res[0]->title(), QStringLiteral("titleA"));
78
    }
79
    {
80
        const auto term = Collection::attributeToTerm("testAttribute", "Abc:*+.-");
81
        const auto res = EntrySearcher().search({term}, root.data());
82
        QCOMPARE(res.count(), 1);
83
        QCOMPARE(res[0]->title(), QStringLiteral("titleB"));
84
    }
85
    {
86
        const auto term = Collection::attributeToTerm("testAttribute", "v|");
87
        const auto res = EntrySearcher().search({term}, root.data());
88
        QCOMPARE(res.count(), 0);
89
    }
90
}
91

92
void TestFdoSecrets::testDBusPathParse()
93
{
94
    using FdoSecrets::DBusMgr;
95
    using PathType = FdoSecrets::DBusMgr::PathType;
96

97
    auto parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets"));
98
    QCOMPARE(parsed.type, PathType::Service);
99

100
    parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/collection/xxx"));
101
    QCOMPARE(parsed.type, PathType::Collection);
102
    QCOMPARE(parsed.id, QStringLiteral("xxx"));
103

104
    parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/collection/xxx/yyy"));
105
    QCOMPARE(parsed.type, PathType::Item);
106
    QCOMPARE(parsed.id, QStringLiteral("yyy"));
107
    QCOMPARE(parsed.parentId, QStringLiteral("xxx"));
108

109
    parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/aliases/xxx"));
110
    QCOMPARE(parsed.type, PathType::Aliases);
111
    QCOMPARE(parsed.id, QStringLiteral("xxx"));
112

113
    parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/session/xxx"));
114
    QCOMPARE(parsed.type, PathType::Session);
115
    QCOMPARE(parsed.id, QStringLiteral("xxx"));
116

117
    parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/prompt/xxx"));
118
    QCOMPARE(parsed.type, PathType::Prompt);
119
    QCOMPARE(parsed.id, QStringLiteral("xxx"));
120

121
    parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/other/prompt/xxx"));
122
    QCOMPARE(parsed.type, PathType::Unknown);
123

124
    parsed = DBusMgr::parsePath(QStringLiteral("/org"));
125
    QCOMPARE(parsed.type, PathType::Unknown);
126
}
127

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.