Closed Bug 1651490 Opened 4 years ago Closed 4 years ago

add xpcshell tests for opengpg messages

Categories

(MailNews Core :: Security: OpenPGP, task)

Tracking

(thunderbird_esr78+ fixed)

RESOLVED FIXED
84 Branch
Tracking Status
thunderbird_esr78 + fixed

People

(Reporter: mkmelin, Assigned: lasana)

Details

Attachments

(1 file, 2 obsolete files)

In bug 1011625 we added tests for S/MIME. We should add similar tests for OpenPGP.
See https://hg.mozilla.org/comm-central/rev/5d7419c95b2b

Summary: add xpschell tests for opengpg messages → add xpcshell tests for opengpg messages
Status: NEW → ASSIGNED
Attached patch bug1651490.patch (obsolete) — Splinter Review

Attaching this for feedback.

I think I finally adapted the test enough to test with openpgp. There is some clean up and additional assertions to add but I wanted to get some feedback before I continue.

Attachment #9185321 - Flags: feedback?(mkmelin+mozilla)
Attachment #9185321 - Flags: feedback?(kaie)
Comment on attachment 9185321 [details] [diff] [review]
bug1651490.patch

Review of attachment 9185321 [details] [diff] [review]:
-----------------------------------------------------------------

::: mailnews/mime/test/unit/head_mime.js
@@ +98,5 @@
>      }
>    }
>  
> +  msgWindow =
> +    msgWindow != null

only check falsy/truthy

if (!msgWindow) {
  msgWindow = .....
}

::: mailnews/mime/test/unit/test_openpgp_decrypt.js
@@ +49,5 @@
> +
> +let gInbox;
> +let openPGPEmailDir = "../../../data/openpgp/";
> +
> +let headerSink = {

So this is simulating Enigmail.hdrView.headerPane? Please add a code comment of what it is. 
Could be useful to put this functionality in  OpenPGPTestUtils?

@@ +165,5 @@
> +  },
> +];
> +
> +let gCopyWaiter = PromiseUtils.defer();
> +

I think you don't need this. 
You have two "tasks" now, but they are just async helper functions

@@ +299,5 @@
> +function run_test() {
> +  gInbox = configure_message_injection({
> +    mode: "local",
> +  });
> +  run_next_test();

I think it's easier to not use the run_test() version, but just add_task as you go, from top as needed
Attachment #9185321 - Flags: feedback?(mkmelin+mozilla)
Attached patch bug1651490v2.patch (obsolete) — Splinter Review

Updated the tests to use the status flags since I was more or less using them anyway and there are so many. Also included a test for the keyId though it's not always available. In future I'd like to also test the email but looks like that isn't passed to updateSecurityStatus(). I'll file a bug for that.

These need the patch from bug 1675325 to work.

Attachment #9185321 - Attachment is obsolete: true
Attachment #9185321 - Flags: feedback?(kaie)
Attachment #9186318 - Flags: review?(mkmelin+mozilla)
Comment on attachment 9186318 [details] [diff] [review]
bug1651490v2.patch

Review of attachment 9186318 [details] [diff] [review]:
-----------------------------------------------------------------

::: mailnews/mime/test/unit/head_mime.js
@@ +97,5 @@
>        );
>      }
>    }
>  
> +  msgWindow = msgWindow

would just do 
if (!msgWindow)  {
  msgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(Ci.nsIMsgWindow);
}

or 

msgWindow = msgWIndow || Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(Ci.nsIMsgWindow);

::: mailnews/mime/test/unit/test_openpgp_decrypt.js
@@ +34,5 @@
> +  "EnigmailCore"
> +);
> +
> +/* import-globals-from ../../../test/resources/asyncTestUtils.js */
> +load("../../../resources/asyncTestUtils.js");

This is an old framework you should not use... it predates async and promises which is the new way.
I don't see you using it directly... but maybe I didn't check closely enough.

@@ +132,5 @@
> + * @type Test[]
> + */
> +const tests = [
> +  {
> +    filename:

would be good to for each test add a description property that says what it's testing

@@ +155,5 @@
> +      "unsigned-encrypted-to-0xf231550c4f47e38e-from-0xfbfcc82a015e7330-with-key.eml",
> +    contents,
> +    from: "bob@openpgp.example",
> +    // keyId: OpenPGPTestUtils.BOB_KEY_ID,
> +    // ^keyId is not passed when message is not signed, should it?

No, if it's not signed there is no key that signed.

@@ +306,5 @@
> + * status flags the test specifies.
> + */
> +add_task(async function testMimeDecryptOpenPGPMessages() {
> +  let hdrIndex = 0;
> +  for (let test of tests) {

... and here

info(``Running test: ${test.description}`)

@@ +307,5 @@
> + */
> +add_task(async function testMimeDecryptOpenPGPMessages() {
> +  let hdrIndex = 0;
> +  for (let test of tests) {
> +    if (test.skip) {

and here also output an info that the test is being skipped
Attachment #9186318 - Flags: review?(mkmelin+mozilla)
Attachment #9186318 - Flags: review+
Attachment #9186318 - Flags: feedback+

This is an old framework you should not use...

It's needed by the messageInjection.js script.

https://searchfox.org/comm-central/rev/7c87b9f5a18f5b6df13e6d06cd7d7ce8bb173c5e/mailnews/test/resources/messageInjection.js#205

I see. Let's go with this then. Filed bug 1676114.

Added description properties to tests.

Attachment #9186318 - Attachment is obsolete: true
Attachment #9186608 - Flags: review?(mkmelin+mozilla)

Try run on the way, I cleaned up the linting issues in the patch attached:
https://treeherder.mozilla.org/jobs?repo=try-comm-central&selectedTaskRun=FlQ8v1lHR8SgkXdBeBYM7A.0

Comment on attachment 9186608 [details] [diff] [review]
bug1651490v3.patch

Review of attachment 9186608 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM, r=mkmelin
Attachment #9186608 - Flags: review?(mkmelin+mozilla) → review+
Target Milestone: --- → 84 Branch

Pushed by thunderbird@calypsoblue.org:
https://hg.mozilla.org/comm-central/rev/8fd1b44855a3
Add mime xpcshell tests for openpgp. r=mkmelin

Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/9e145e871c4c
followup to make the new OpenPGP xpcshell tests work after bug 1664701. rs=bustage-fix

^ Did some thing break? Can I put that change you made in an ensureOpenPGP() function instead of executing when the module is imported?

xpcshell tests would then do:

add_task(async function(){ await OpenPGPTestUtils.ensureOpenPGP() })

Flags: needinfo?(mkmelin+mozilla)

Yes the push before yours changed module initialization for openpgp... which broke the test. https://treeherder.mozilla.org/jobs?repo=comm-central&revision=8fd1b44855a35346818ca6878759dfb3f1cccd05

I'm not sure any changes are needed. This would only ever be a problem in xpcshell tests, and there I think it will be fairly clear what needs doing. Maybe.

Flags: needinfo?(mkmelin+mozilla)

There are other things that need to be initialized before OpenPGPTestUtils can be used in an xpcshell test, probably related to the bug for that push. It wasn't really clear at first touch.

I think they can all go in a method on OpenPGPTestUtils. My opinion is that code should not be executed when a library style module is imported, takes control away from the importing module and leaves room for bugs.

Agreed.

Please request uplifts for this and related tests so 78 test coverage is improved.

Comment on attachment 9186608 [details] [diff] [review]
bug1651490v3.patch

[Approval Request Comment]
Regression caused by (bug #): None. Adds more tests for OpenPGP.
User impact if declined: None really.
Testing completed (on c-c, etc.): c-c
Risk to taking this patch (and alternatives if risky): None that I can think of. This makes testing OpenPGP support less manual.

Attachment #9186608 - Flags: approval-comm-esr78?

Comment on attachment 9186608 [details] [diff] [review]
bug1651490v3.patch

[Triage Comment]
Approved for esr78

Attachment #9186608 - Flags: approval-comm-esr78? → approval-comm-esr78+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: