Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
libkleo
Commits
5166325c
Commit
5166325c
authored
Apr 20, 2021
by
Ingo Klöcker
Browse files
Fill the key cache with test keys and use those keys in the tests
GnuPG-bug-id: 5283
parent
03bdbbec
Changes
1
Hide whitespace changes
Inline
Side-by-side
autotests/newkeyapprovaldialogtest.cpp
View file @
5166325c
...
...
@@ -8,6 +8,7 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <Libkleo/KeyCache>
#include <Libkleo/KeySelectionCombo>
#include <Libkleo/NewKeyApprovalDialog>
...
...
@@ -63,6 +64,17 @@ GpgME::Key createTestKey(const char *uid, GpgME::Protocol protocol = GpgME::Unkn
return
GpgME
::
Key
(
key
,
false
);
}
auto
testKey
(
const
char
*
email
,
GpgME
::
Protocol
protocol
=
GpgME
::
UnknownProtocol
)
{
const
auto
keys
=
KeyCache
::
instance
()
->
findByEMailAddress
(
email
);
for
(
const
auto
&
key
:
keys
)
{
if
(
protocol
==
GpgME
::
UnknownProtocol
||
key
.
protocol
()
==
protocol
)
{
return
key
;
}
}
return
GpgME
::
Key
();
}
template
<
typename
T
>
struct
Widgets
{
...
...
@@ -119,6 +131,26 @@ class NewKeyApprovalDialogTest: public QObject
{
Q_OBJECT
private
Q_SLOTS
:
void
init
()
{
// hold a reference to the key cache to avoid rebuilding while the test is running
mKeyCache
=
KeyCache
::
instance
();
KeyCache
::
mutableInstance
()
->
setKeys
({
createTestKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createTestKey
(
"sender@example.net"
,
GpgME
::
CMS
),
createTestKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
),
createTestKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
),
});
}
void
cleanup
()
{
// verify that nobody else holds a reference to the key cache
QVERIFY
(
mKeyCache
.
use_count
()
==
1
);
mKeyCache
.
reset
();
}
void
test__both_protocols_allowed__mixed_not_allowed__openpgp_preferred
()
{
const
GpgME
::
Protocol
forcedProtocol
=
GpgME
::
UnknownProtocol
;
...
...
@@ -126,20 +158,20 @@ private Q_SLOTS:
const
QString
sender
=
QStringLiteral
(
"sender@example.net"
);
const
KeyResolver
::
Solution
preferredSolution
=
{
GpgME
::
OpenPGP
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
createT
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
t
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)}}
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)}}
}
};
const
KeyResolver
::
Solution
alternativeSolution
=
{
GpgME
::
CMS
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
createT
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
t
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
}
};
...
...
@@ -194,20 +226,20 @@ private Q_SLOTS:
const
QString
sender
=
QStringLiteral
(
"sender@example.net"
);
const
KeyResolver
::
Solution
preferredSolution
=
{
GpgME
::
CMS
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
createT
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
t
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
}
};
const
KeyResolver
::
Solution
alternativeSolution
=
{
GpgME
::
OpenPGP
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
createT
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
t
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)}}
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)}}
}
};
...
...
@@ -262,11 +294,11 @@ private Q_SLOTS:
const
QString
sender
=
QStringLiteral
(
"sender@example.net"
);
const
KeyResolver
::
Solution
preferredSolution
=
{
GpgME
::
OpenPGP
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
createT
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
t
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)}}
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
)}}
}
};
const
KeyResolver
::
Solution
alternativeSolution
=
{};
...
...
@@ -312,11 +344,11 @@ private Q_SLOTS:
const
QString
sender
=
QStringLiteral
(
"sender@example.net"
);
const
KeyResolver
::
Solution
preferredSolution
=
{
GpgME
::
CMS
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
createT
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
t
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
}
};
const
KeyResolver
::
Solution
alternativeSolution
=
{};
...
...
@@ -362,12 +394,12 @@ private Q_SLOTS:
const
QString
sender
=
QStringLiteral
(
"sender@example.net"
);
const
KeyResolver
::
Solution
preferredSolution
=
{
GpgME
::
UnknownProtocol
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
createT
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
createT
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
t
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
t
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"unknown@example.net"
),
{}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
}
};
const
KeyResolver
::
Solution
alternativeSolution
=
{};
...
...
@@ -422,11 +454,11 @@ private Q_SLOTS:
const
QString
sender
=
QStringLiteral
(
"sender@example.net"
);
const
KeyResolver
::
Solution
preferredSolution
=
{
GpgME
::
OpenPGP
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
createT
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
t
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"unknown@example.net"
),
{}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
}
};
const
KeyResolver
::
Solution
alternativeSolution
=
{};
...
...
@@ -478,11 +510,11 @@ private Q_SLOTS:
const
QString
sender
=
QStringLiteral
(
"sender@example.net"
);
const
KeyResolver
::
Solution
preferredSolution
=
{
GpgME
::
CMS
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
createT
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
t
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"unknown@example.net"
),
{}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
}
};
const
KeyResolver
::
Solution
alternativeSolution
=
{};
...
...
@@ -536,8 +568,8 @@ private Q_SLOTS:
GpgME
::
UnknownProtocol
,
{},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
createT
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
createT
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
t
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
t
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"unknown@example.net"
),
{}},
{
QStringLiteral
(
"sender@example.net"
),
{}}
}
...
...
@@ -583,12 +615,12 @@ private Q_SLOTS:
const
QString
sender
=
QStringLiteral
(
"sender@example.net"
);
const
KeyResolver
::
Solution
preferredSolution
=
{
GpgME
::
UnknownProtocol
,
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)},
{
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
createT
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
createT
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"prefer-openpgp@example.net"
),
{
t
estKey
(
"Full Trust <prefer-openpgp@example.net>"
,
GpgME
::
OpenPGP
)}},
{
QStringLiteral
(
"prefer-smime@example.net"
),
{
t
estKey
(
"Trusted S/MIME <prefer-smime@example.net>"
,
GpgME
::
CMS
)}},
{
QStringLiteral
(
"unknown@example.net"
),
{}},
{
QStringLiteral
(
"sender@example.net"
),
{
createT
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
createT
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
{
QStringLiteral
(
"sender@example.net"
),
{
t
estKey
(
"sender@example.net"
,
GpgME
::
OpenPGP
),
t
estKey
(
"sender@example.net"
,
GpgME
::
CMS
)}}
}
};
const
KeyResolver
::
Solution
alternativeSolution
=
{};
...
...
@@ -610,6 +642,9 @@ private Q_SLOTS:
QCOMPARE
(
encryptionKeyWidgets
.
visible
.
size
(),
5
);
QCOMPARE
(
encryptionKeyWidgets
.
hidden
.
size
(),
0
);
}
private:
std
::
shared_ptr
<
const
KeyCache
>
mKeyCache
;
};
QTEST_MAIN
(
NewKeyApprovalDialogTest
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment