2
* Copyright (C) 2019 Aetf <aetf@unlimitedcodeworks.xyz>
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.
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.
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/>.
18
#include "TestFdoSecrets.h"
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"
28
QTEST_GUILESS_MAIN(TestFdoSecrets)
30
void TestFdoSecrets::testDhIetf1024Sha256Aes128CbcPkcs7()
32
FdoSecrets::DhIetf1024Sha256Aes128CbcPkcs7 cipher(randomGen()->randomArray(128));
33
QVERIFY(cipher.isValid());
36
void TestFdoSecrets::testCrazyAttributeKey()
38
using FdoSecrets::Collection;
39
using FdoSecrets::Item;
41
const QScopedPointer<Group> root(new Group());
42
const QScopedPointer<Entry> e1(new Entry());
43
e1->setGroup(root.data());
45
const QString key = "_a:bc&-+'-e%12df_d";
46
const QString value = "value";
47
e1->attributes()->set(key, value);
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);
55
void TestFdoSecrets::testSpecialCharsInAttributeValue()
57
using FdoSecrets::Collection;
58
using FdoSecrets::Item;
60
const QScopedPointer<Group> root(new Group());
61
QScopedPointer<Entry> e1(new Entry());
62
e1->setGroup(root.data());
64
e1->setTitle("titleA");
65
e1->attributes()->set("testAttribute", "OAuth::[test.name@gmail.com]");
67
QScopedPointer<Entry> e2(new Entry());
68
e2->setGroup(root.data());
69
e2->setTitle("titleB");
70
e2->attributes()->set("testAttribute", "Abc:*+.-");
72
// search for custom entries via programmatic API
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"));
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"));
86
const auto term = Collection::attributeToTerm("testAttribute", "v|");
87
const auto res = EntrySearcher().search({term}, root.data());
88
QCOMPARE(res.count(), 0);
92
void TestFdoSecrets::testDBusPathParse()
94
using FdoSecrets::DBusMgr;
95
using PathType = FdoSecrets::DBusMgr::PathType;
97
auto parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets"));
98
QCOMPARE(parsed.type, PathType::Service);
100
parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/collection/xxx"));
101
QCOMPARE(parsed.type, PathType::Collection);
102
QCOMPARE(parsed.id, QStringLiteral("xxx"));
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"));
109
parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/aliases/xxx"));
110
QCOMPARE(parsed.type, PathType::Aliases);
111
QCOMPARE(parsed.id, QStringLiteral("xxx"));
113
parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/session/xxx"));
114
QCOMPARE(parsed.type, PathType::Session);
115
QCOMPARE(parsed.id, QStringLiteral("xxx"));
117
parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/secrets/prompt/xxx"));
118
QCOMPARE(parsed.type, PathType::Prompt);
119
QCOMPARE(parsed.id, QStringLiteral("xxx"));
121
parsed = DBusMgr::parsePath(QStringLiteral("/org/freedesktop/other/prompt/xxx"));
122
QCOMPARE(parsed.type, PathType::Unknown);
124
parsed = DBusMgr::parsePath(QStringLiteral("/org"));
125
QCOMPARE(parsed.type, PathType::Unknown);