Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | const PREF_EM_HOTFIX_ID = "extensions.hotfix.id"; |
michael@0 | 6 | const PREF_EM_HOTFIX_LASTVERSION = "extensions.hotfix.lastVersion"; |
michael@0 | 7 | const PREF_EM_HOTFIX_URL = "extensions.hotfix.url"; |
michael@0 | 8 | const PREF_EM_HOTFIX_CERTS = "extensions.hotfix.certs."; |
michael@0 | 9 | const PREF_EM_CERT_CHECKATTRIBUTES = "extensions.hotfix.cert.checkAttributes"; |
michael@0 | 10 | |
michael@0 | 11 | const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts"; |
michael@0 | 12 | const PREF_UPDATE_REQUIREBUILTINCERTS = "extensions.update.requireBuiltInCerts"; |
michael@0 | 13 | |
michael@0 | 14 | const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; |
michael@0 | 15 | const PREF_APP_UPDATE_URL = "app.update.url"; |
michael@0 | 16 | |
michael@0 | 17 | const HOTFIX_ID = "hotfix@tests.mozilla.org"; |
michael@0 | 18 | |
michael@0 | 19 | var gNextTest; |
michael@0 | 20 | |
michael@0 | 21 | var SuccessfulInstallListener = { |
michael@0 | 22 | onDownloadCancelled: function(aInstall) { |
michael@0 | 23 | ok(false, "Should not have seen the download cancelled"); |
michael@0 | 24 | is(aInstall.addon.id, HOTFIX_ID, "Should have seen the right add-on"); |
michael@0 | 25 | |
michael@0 | 26 | AddonManager.removeInstallListener(this); |
michael@0 | 27 | gNextTest(); |
michael@0 | 28 | }, |
michael@0 | 29 | |
michael@0 | 30 | onInstallEnded: function(aInstall) { |
michael@0 | 31 | ok(true, "Should have seen the install complete"); |
michael@0 | 32 | is(aInstall.addon.id, HOTFIX_ID, "Should have installed the right add-on"); |
michael@0 | 33 | |
michael@0 | 34 | AddonManager.removeInstallListener(this); |
michael@0 | 35 | aInstall.addon.uninstall(); |
michael@0 | 36 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_LASTVERSION); |
michael@0 | 37 | gNextTest(); |
michael@0 | 38 | } |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | var FailedInstallListener = { |
michael@0 | 42 | onDownloadCancelled: function(aInstall) { |
michael@0 | 43 | ok(true, "Should have seen the download cancelled"); |
michael@0 | 44 | is(aInstall.addon.id, HOTFIX_ID, "Should have seen the right add-on"); |
michael@0 | 45 | |
michael@0 | 46 | AddonManager.removeInstallListener(this); |
michael@0 | 47 | gNextTest(); |
michael@0 | 48 | }, |
michael@0 | 49 | |
michael@0 | 50 | onInstallEnded: function(aInstall) { |
michael@0 | 51 | ok(false, "Should not have seen the install complete"); |
michael@0 | 52 | is(aInstall.addon.id, HOTFIX_ID, "Should have installed the right add-on"); |
michael@0 | 53 | |
michael@0 | 54 | AddonManager.removeInstallListener(this); |
michael@0 | 55 | aInstall.addon.uninstall(); |
michael@0 | 56 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_LASTVERSION); |
michael@0 | 57 | gNextTest(); |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function test() { |
michael@0 | 62 | waitForExplicitFinish(); |
michael@0 | 63 | |
michael@0 | 64 | var oldAusUrl = Services.prefs.getDefaultBranch(null).getCharPref(PREF_APP_UPDATE_URL); |
michael@0 | 65 | Services.prefs.getDefaultBranch(null).setCharPref(PREF_APP_UPDATE_URL, TESTROOT + "ausdummy.xml"); |
michael@0 | 66 | Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, true); |
michael@0 | 67 | Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false); |
michael@0 | 68 | Services.prefs.setBoolPref(PREF_UPDATE_REQUIREBUILTINCERTS, false); |
michael@0 | 69 | Services.prefs.setCharPref(PREF_EM_HOTFIX_ID, HOTFIX_ID); |
michael@0 | 70 | var oldURL = Services.prefs.getCharPref(PREF_EM_HOTFIX_URL); |
michael@0 | 71 | Services.prefs.setCharPref(PREF_EM_HOTFIX_URL, TESTROOT + "signed_hotfix.rdf"); |
michael@0 | 72 | |
michael@0 | 73 | registerCleanupFunction(function() { |
michael@0 | 74 | Services.prefs.setBoolPref(PREF_APP_UPDATE_ENABLED, false); |
michael@0 | 75 | Services.prefs.getDefaultBranch(null).setCharPref(PREF_APP_UPDATE_URL, oldAusUrl); |
michael@0 | 76 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_ID); |
michael@0 | 77 | Services.prefs.setCharPref(PREF_EM_HOTFIX_URL, oldURL); |
michael@0 | 78 | Services.prefs.clearUserPref(PREF_INSTALL_REQUIREBUILTINCERTS); |
michael@0 | 79 | Services.prefs.clearUserPref(PREF_UPDATE_REQUIREBUILTINCERTS); |
michael@0 | 80 | |
michael@0 | 81 | Services.prefs.clearUserPref(PREF_EM_CERT_CHECKATTRIBUTES); |
michael@0 | 82 | var prefs = Services.prefs.getChildList(PREF_EM_HOTFIX_CERTS); |
michael@0 | 83 | prefs.forEach(Services.prefs.clearUserPref); |
michael@0 | 84 | }); |
michael@0 | 85 | |
michael@0 | 86 | run_next_test(); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function end_test() { |
michael@0 | 90 | finish(); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | add_test(function check_no_cert_checks() { |
michael@0 | 94 | Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, false); |
michael@0 | 95 | AddonManager.addInstallListener(SuccessfulInstallListener); |
michael@0 | 96 | |
michael@0 | 97 | gNextTest = run_next_test; |
michael@0 | 98 | |
michael@0 | 99 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 100 | }); |
michael@0 | 101 | |
michael@0 | 102 | add_test(function check_wrong_cert_fingerprint() { |
michael@0 | 103 | Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true); |
michael@0 | 104 | Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "foo"); |
michael@0 | 105 | |
michael@0 | 106 | AddonManager.addInstallListener(FailedInstallListener); |
michael@0 | 107 | |
michael@0 | 108 | gNextTest = function() { |
michael@0 | 109 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint"); |
michael@0 | 110 | |
michael@0 | 111 | run_next_test(); |
michael@0 | 112 | }; |
michael@0 | 113 | |
michael@0 | 114 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 115 | }); |
michael@0 | 116 | |
michael@0 | 117 | add_test(function check_right_cert_fingerprint() { |
michael@0 | 118 | Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true); |
michael@0 | 119 | Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "3E:B9:4E:07:12:FE:3C:01:41:46:13:46:FC:84:52:1A:8C:BE:1D:A2"); |
michael@0 | 120 | |
michael@0 | 121 | AddonManager.addInstallListener(SuccessfulInstallListener); |
michael@0 | 122 | |
michael@0 | 123 | gNextTest = function() { |
michael@0 | 124 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint"); |
michael@0 | 125 | |
michael@0 | 126 | run_next_test(); |
michael@0 | 127 | }; |
michael@0 | 128 | |
michael@0 | 129 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 130 | }); |
michael@0 | 131 | |
michael@0 | 132 | add_test(function check_multi_cert_fingerprint_1() { |
michael@0 | 133 | Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true); |
michael@0 | 134 | Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "3E:B9:4E:07:12:FE:3C:01:41:46:13:46:FC:84:52:1A:8C:BE:1D:A2"); |
michael@0 | 135 | Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint", "foo"); |
michael@0 | 136 | |
michael@0 | 137 | AddonManager.addInstallListener(SuccessfulInstallListener); |
michael@0 | 138 | |
michael@0 | 139 | gNextTest = function() { |
michael@0 | 140 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint"); |
michael@0 | 141 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint"); |
michael@0 | 142 | |
michael@0 | 143 | run_next_test(); |
michael@0 | 144 | }; |
michael@0 | 145 | |
michael@0 | 146 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 147 | }); |
michael@0 | 148 | |
michael@0 | 149 | add_test(function check_multi_cert_fingerprint_2() { |
michael@0 | 150 | Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true); |
michael@0 | 151 | Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "foo"); |
michael@0 | 152 | Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint", "3E:B9:4E:07:12:FE:3C:01:41:46:13:46:FC:84:52:1A:8C:BE:1D:A2"); |
michael@0 | 153 | |
michael@0 | 154 | AddonManager.addInstallListener(SuccessfulInstallListener); |
michael@0 | 155 | |
michael@0 | 156 | gNextTest = function() { |
michael@0 | 157 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint"); |
michael@0 | 158 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "2.sha1Fingerprint"); |
michael@0 | 159 | |
michael@0 | 160 | run_next_test(); |
michael@0 | 161 | }; |
michael@0 | 162 | |
michael@0 | 163 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 164 | }); |
michael@0 | 165 | |
michael@0 | 166 | add_test(function check_no_cert_no_checks() { |
michael@0 | 167 | Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, false); |
michael@0 | 168 | Services.prefs.setCharPref(PREF_EM_HOTFIX_URL, TESTROOT + "unsigned_hotfix.rdf"); |
michael@0 | 169 | |
michael@0 | 170 | AddonManager.addInstallListener(SuccessfulInstallListener); |
michael@0 | 171 | |
michael@0 | 172 | gNextTest = run_next_test; |
michael@0 | 173 | |
michael@0 | 174 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 175 | }); |
michael@0 | 176 | |
michael@0 | 177 | add_test(function check_no_cert_cert_fingerprint_check() { |
michael@0 | 178 | Services.prefs.setBoolPref(PREF_EM_CERT_CHECKATTRIBUTES, true); |
michael@0 | 179 | Services.prefs.setCharPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint", "3E:B9:4E:07:12:FE:3C:01:41:46:13:46:FC:84:52:1A:8C:BE:1D:A2"); |
michael@0 | 180 | |
michael@0 | 181 | AddonManager.addInstallListener(FailedInstallListener); |
michael@0 | 182 | |
michael@0 | 183 | gNextTest = function() { |
michael@0 | 184 | Services.prefs.clearUserPref(PREF_EM_HOTFIX_CERTS + "1.sha1Fingerprint"); |
michael@0 | 185 | |
michael@0 | 186 | run_next_test(); |
michael@0 | 187 | }; |
michael@0 | 188 | |
michael@0 | 189 | AddonManagerPrivate.backgroundUpdateCheck(); |
michael@0 | 190 | }); |