2 #ifndef _ZYPP_KEYRING_TEST_RECEIVER_H
3 #define _ZYPP_KEYRING_TEST_RECEIVER_H
5 #include "zypp/Callback.h"
6 #include "zypp/KeyRing.h"
7 #include "zypp/PublicKey.h"
8 #include "zypp/KeyContext.h"
11 * Keyring Callback Receiver with some features
12 * Allows to simulate and configure user answer
13 * Can record which callbacks were called
15 struct KeyRingTestReceiver : public zypp::callback::ReceiveReport<zypp::KeyRingReport>
25 _answer_accept_unknown_key = false;
26 _answer_accept_key = KeyRingReport::KEY_DONT_TRUST;
27 _answer_ver_failed = false;
28 _answer_accept_unsigned_file = false;
29 _asked_user_to_accept_unknown_key = false;
30 _asked_user_to_accept_key = false;
31 _asked_user_to_accept_ver_failed = false;
32 _asked_user_to_accept_unsigned_file = false;
35 ~KeyRingTestReceiver()
40 void answerAcceptVerFailed( bool answer )
41 { _answer_ver_failed = answer; }
43 bool askedAcceptVerFailed() const
44 { return _asked_user_to_accept_ver_failed; }
46 void answerAcceptUnknownKey( bool answer )
47 { _answer_accept_unknown_key = answer; }
49 bool askedAcceptUnknownKey() const
50 { return _asked_user_to_accept_unknown_key; }
52 void answerAcceptKey( KeyRingReport::KeyTrust answer )
53 { _answer_accept_key = answer; }
55 bool askedAcceptKey() const
56 { return _asked_user_to_accept_key; }
58 void answerAcceptUnsignedFile( bool answer )
59 { _answer_accept_unsigned_file = answer; }
61 bool askedAcceptUnsignedFile() const
62 { return _asked_user_to_accept_unsigned_file; }
64 virtual bool askUserToAcceptUnsignedFile( const std::string &file, const zypp::KeyContext &keycontext )
67 _asked_user_to_accept_unsigned_file = true;
68 return _answer_accept_unsigned_file;
71 virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const zypp::KeyContext &keycontext )
74 _asked_user_to_accept_unknown_key = true;
75 return _answer_accept_unknown_key;
78 virtual KeyRingReport::KeyTrust askUserToAcceptKey( const zypp::PublicKey &key, const zypp::KeyContext &keycontext )
81 _asked_user_to_accept_key = true;
82 return _answer_accept_key;
85 virtual bool askUserToAcceptVerificationFailed( const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext )
88 _asked_user_to_accept_ver_failed = true;
89 return _answer_ver_failed;
93 bool _answer_accept_unknown_key;
94 KeyRingReport::KeyTrust _answer_accept_key;
95 bool _answer_ver_failed;
96 bool _answer_accept_unsigned_file;
98 // we use this variables to check that the
99 // callbacks were called
100 bool _asked_user_to_accept_unknown_key;
101 bool _asked_user_to_accept_key;
102 bool _asked_user_to_accept_ver_failed;
103 bool _asked_user_to_accept_unsigned_file;
107 * Keyring Signal Receiver with some features
108 * Allows to simulate and configure user answer
109 * Can record which callbacks were called
111 struct KeyRingTestSignalReceiver : zypp::callback::ReceiveReport<zypp::KeyRingSignals>
113 KeyRingTestSignalReceiver(/*RpmDb &rpmdb*/)
114 : _trusted_key_added_called(false)
116 MIL << "KeyRing signals enabled" << std::endl;
120 ~KeyRingTestSignalReceiver()
125 virtual void trustedKeyAdded( const zypp::PublicKey &key )
127 MIL << "TEST: trusted key added to zypp Keyring. Synchronizing keys with fake rpm keyring" << std::endl;
128 _trusted_key_added_called = true;
129 //std::cout << "trusted key added to zypp Keyring. Synchronizing keys with rpm keyring" << std::endl;
130 //_rpmdb.importZyppKeyRingTrustedKeys();
131 //_rpmdb.exportTrustedKeysInZyppKeyRing();
134 virtual void trustedKeyRemoved( const zypp::PublicKey &key )
138 bool _trusted_key_added_called;