summaryrefslogtreecommitdiffstats
path: root/toolkit/components/url-classifier/tests/unit/test_platform_specific_threats.js
blob: 499c9e478cae790b5d29ad250c311b770f3da177 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const { AppConstants } = ChromeUtils.importESModule(
  "resource://gre/modules/AppConstants.sys.mjs"
);

let urlUtils = Cc["@mozilla.org/url-classifier/utils;1"].getService(
  Ci.nsIUrlClassifierUtils
);

function testMobileOnlyThreats() {
  // Mobile-only threat type(s):
  //   - goog-harmful-proto (POTENTIALLY_HARMFUL_APPLICATION)

  (function testUpdateRequest() {
    let requestWithPHA = urlUtils.makeUpdateRequestV4(
      ["goog-phish-proto", "goog-harmful-proto"],
      ["AAAAAA", "AAAAAA"]
    );

    let requestNoPHA = urlUtils.makeUpdateRequestV4(
      ["goog-phish-proto"],
      ["AAAAAA"]
    );

    if (AppConstants.platform === "android") {
      notEqual(
        requestWithPHA,
        requestNoPHA,
        "PHA (i.e. goog-harmful-proto) shouldn't be filtered on mobile platform."
      );
    } else {
      equal(
        requestWithPHA,
        requestNoPHA,
        "PHA (i.e. goog-harmful-proto) should be filtered on non-mobile platform."
      );
    }
  })();

  (function testFullHashRequest() {
    let requestWithPHA = urlUtils.makeFindFullHashRequestV4(
      ["goog-phish-proto", "goog-harmful-proto"],
      ["", ""], // state.
      [btoa("0123")]
    ); // prefix.

    let requestNoPHA = urlUtils.makeFindFullHashRequestV4(
      ["goog-phish-proto"],
      [""], // state.
      [btoa("0123")]
    ); // prefix.

    if (AppConstants.platform === "android") {
      notEqual(
        requestWithPHA,
        requestNoPHA,
        "PHA (i.e. goog-harmful-proto) shouldn't be filtered on mobile platform."
      );
    } else {
      equal(
        requestWithPHA,
        requestNoPHA,
        "PHA (i.e. goog-harmful-proto) should be filtered on non-mobile platform."
      );
    }
  })();
}

function testDesktopOnlyThreats() {
  // Desktop-only threats:
  //   - goog-downloadwhite-proto (CSD_WHITELIST)
  //   - goog-badbinurl-proto (MALICIOUS_BINARY)

  let requestWithDesktopOnlyThreats = urlUtils.makeUpdateRequestV4(
    ["goog-phish-proto", "goog-downloadwhite-proto", "goog-badbinurl-proto"],
    ["", "", ""]
  );

  let requestNoDesktopOnlyThreats = urlUtils.makeUpdateRequestV4(
    ["goog-phish-proto"],
    [""]
  );

  if (AppConstants.platform === "android") {
    equal(
      requestWithDesktopOnlyThreats,
      requestNoDesktopOnlyThreats,
      "Android shouldn't contain 'goog-downloadwhite-proto' and 'goog-badbinurl-proto'."
    );
  } else {
    notEqual(
      requestWithDesktopOnlyThreats,
      requestNoDesktopOnlyThreats,
      "Desktop should contain 'goog-downloadwhite-proto' and 'goog-badbinurl-proto'."
    );
  }
}

function run_test() {
  testMobileOnlyThreats();
  testDesktopOnlyThreats();
}