Help needed to fix FilterActionEncryptTest::shouldEncrypt(PGP*) unit tests

Sandro Knauß sknauss at kde.org
Thu Aug 19 11:35:38 BST 2021


Hey,

> (Sandro, Ingo, okay to just reply to kde-pim in the future? does this thread
> now have your awareness, and will so future replies? :) )

I try my best ;)

> > > Also changed code to set explicitly the GnupgHome property on the
> > > MessageComposer::EncryptJob, so it sets it on the QGpgME::Job::context,
> > > in
> > > case the env var GNUPGHOME as set by the test's GPGHelper is ignored,
> > > but
> > > also to no effect.
> > 
> > Wait - now you are talking about tests of messagelib/messagecomposer.
> 
> Nono, FilterActionEncrypt::process() (mailcommon) is using
> MessageComposer::EncryptJob (messagelb) and the very error we talk about is
> delivered from that very job class, thus I also inspected these things down
> there at the call chain :)

As I said I haven't look into the code before. My feeling was that everything 
was written without any usage of existing stuff :)

You can set the GnupgHome via EncryptJob::setGnupgHome, but in general it need 
to follow the environment variable, as the tests hopefully worked at some 
point in the past, that worked.

> (Good to see I am not the only one confused by all the distributed code,
> already had lots of times where I rebuild and installed to test something,
> only to find the file I had edited was from another repo :) )

Just didn't knew that EncryptJob is used.

> --- 8< ---
> $ LANG=C GNUPGHOME=/tmp/filteractionencrypttest-FkXyit/gpghome gpg --version
> gpg: WARNING: unsafe permissions on homedir '/tmp/filteractionencrypttest-
> FkXyit/gpghome'
> [...]
> --- 8< ---

This was not the test I wanted you to archive. I wanted that you run gpg --
version by calling the GpgHelper, to just make sure, that it does the correct 
thing.
 
> GNUPGHOME = <path> gpg -e -r kmail at test.kde -o encrypt.asc
> 
> Perhaps this one already sheds more light/shadows indicating something for
> you, as it gives us the very error message?
> 
> --- 8< ---
> $ LANG=C GNUPGHOME=/tmp/filteractionencrypttest-FkXyit/gpghome gpg -e -r
> kmail at test.kde -o encrypt.asc testfile.txt
> gpg: key 358732559B8659B2 was created 1663 days in the future (time warp or 
clock problem)
> gpg: error retrieving 'kmail at test.kde' via Local: Unusable public key
> gpg: kmail at test.kde: skipped: No data
> gpg: testfile.txt: encryption failed: No data
> --- 8< ---

I learned that the fake system time must be in the valid timeframe to make the 
key usable. (well it makes totally sense, as we want to test gpg how it act at 
an other time).

Finally you got me to test this by myself. I was wrong about the faked-system-
time setting, this needs to be done in gpg.conf.

With a good fake system time I can successfully encrypt and decrypt from the 
commandline:

% cp -r <pathto>/gpghome /tmp/gpghome2
% echo "faked-system-time 20170924T154812" > /tmp/gpghome2/gpg.conf
% GNUPGHOME=/tmp/gpghome2  gpg --list-secret-keys                                                                                                                                    
gpg: WARNING: unsafe permissions on homedir '/tmp/gpghome2'
gpg: WARNING: running with faked system time: 2017-09-24 15:48:12
/tmp/gpghome2/pubring.gpg
-------------------------
sec   rsa2048 2017-08-01 [SC] [expires: 2019-08-01]
      818AE8DA30F81B0CEA4403BA358732559B8659B2
uid           [ultimate] KMail Test <kmail at test.kde>
ssb   rsa2048 2017-08-01 [E] [expires: 2019-08-01]

% GNUPGHOME=/tmp/gpghome2 gpg -e -r kmail at test.kde -o encrypt.asc
gpg: WARNING: unsafe permissions on homedir '/tmp/gpghome2'
gpg: WARNING: running with faked system time: 2017-09-24 15:48:12
File 'encrypt.asc' exists. Overwrite? (y/N) y
qwert
<Ctrl+D>
% GNUPGHOME=/tmp/gpghome2  gpg -d encrypt.asc                   
gpg: WARNING: unsafe permissions on homedir '/tmp/gpghome2'
gpg: WARNING: running with faked system time: 2017-09-24 15:48:12
gpg: encrypted with 2048-bit RSA key, ID 7217B87A57C06716, created 2017-08-01
      "KMail Test <kmail at test.kde>"
qwert

I think when you can also encrypt/decrypt via commandline, than the test will 
pass. As this is all about gpg settings.

hefee




More information about the kde-pim mailing list