Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/signatures.js

Issue 30011555: Issue 7303 - Deprecate the use of String.prototype.substr() (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebase Created Feb. 21, 2019, 2:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/url.js ('K') | « test/matcher.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA= 44 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA=
45 -----END RSA PRIVATE KEY----- 45 -----END RSA PRIVATE KEY-----
46 */ 46 */
47 47
48 let data = "test"; 48 let data = "test";
49 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/ wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; 49 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/ wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ==";
50 let signature = "LzKJE1BOsZDfwD/hncHq+MN5ZygIemb1Pyzx40rm3CoTL4CVPAicS1mOiTv6s 9Li9Vw1ds9HwFWVMFVEwHwfIw=="; 50 let signature = "LzKJE1BOsZDfwD/hncHq+MN5ZygIemb1Pyzx40rm3CoTL4CVPAicS1mOiTv6s 9Li9Vw1ds9HwFWVMFVEwHwfIw==";
51 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); 51 test.ok(verifySignature(publicKey, signature, data), "Correct signature");
52 52
53 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); 53 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
54 test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data "); 54 test.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wrong d ata");
55 test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.s ubstr(6), data), "Wrong signature"); 55 test.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + signatur e.substring(6), data), "Wrong signature");
56 test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), s ignature, data), "Wrong public key"); 56 test.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.substring (6), signature, data), "Wrong public key");
57 test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); 57 test.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.substrin g(71), signature, data), "Wrong public key");
58 58
59 test.done(); 59 test.done();
60 }; 60 };
61 61
62 exports.test2048bitSigningKey = function(test) 62 exports.test2048bitSigningKey = function(test)
63 { 63 {
64 /* 64 /*
65 -----BEGIN RSA PRIVATE KEY----- 65 -----BEGIN RSA PRIVATE KEY-----
66 MIIEowIBAAKCAQEAy45IKQw0R5YBiIFyfKftx3F/6WsvtdNMnCKodkDemXuJOcFu 66 MIIEowIBAAKCAQEAy45IKQw0R5YBiIFyfKftx3F/6WsvtdNMnCKodkDemXuJOcFu
67 Of/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8ZkBRsaQ8HzNoK+vg4 67 Of/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8ZkBRsaQ8HzNoK+vg4
(...skipping 22 matching lines...) Expand all
90 T/YKqjp7uRICikPwvySruukdXDrxZpykOsusG0QbP2qemjfmM025 90 T/YKqjp7uRICikPwvySruukdXDrxZpykOsusG0QbP2qemjfmM025
91 -----END RSA PRIVATE KEY----- 91 -----END RSA PRIVATE KEY-----
92 */ 92 */
93 93
94 let data = "test"; 94 let data = "test";
95 let publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy45IKQw0R5YBiIFyf Kftx3F/6WsvtdNMnCKodkDemXuJOcFuOf/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8Zk BRsaQ8HzNoK+vg4wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsFf AwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/TidSVjqxe6O3hG9jTOsw C8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZtZm1Mr42omgst+KE+5dE6kyx76ra8LwsC EShawIDAQAB"; 95 let publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAy45IKQw0R5YBiIFyf Kftx3F/6WsvtdNMnCKodkDemXuJOcFuOf/KeIjED/wW2DFG8qq72FAByUUFoTLcmawQZPd2htmHIk8Zk BRsaQ8HzNoK+vg4wnI6yN/2lhSP27D4XpedG3mtbG8aYtMuqyQaxWHInSqiM4tqW/8coAPXrRTKYmsFf AwPB1LCg5QI3vCy7Vdbbp907xOXON1+2seF9j8m9rh0sufXgGNWcvTNUvlf/TidSVjqxe6O3hG9jTOsw C8/hez7rbiLroVNnCtIDrdX6OSM/je/XSMMnS5xpZBuqZGZtZm1Mr42omgst+KE+5dE6kyx76ra8LwsC EShawIDAQAB";
96 let signature = "UYTQmygOICKi4ozlMbLSYFZ1olovZZFYT0nZygPrGoA+6+ta+wzKnPnghK4j3 5QSucrf3yN8DSXa/kXBX0LcTmEaSwoNRuM7QPjT6v9hNsVjwNexOUk6pR3DotYuD1yV36sITNjx59McG 8/q6qLyj2A8KVlUbtnz/IiLzzw+wgy6WRjU1meYP8oiQGVIkB21ICqqaJ5kCvM0YrAqzQKAya513O51A DA6aC/EMz6B62XGgZ+AywUMcH2Wvx7cyCvPVLfAbXcgex1JtpPS6vGcdpigaVQkoyl4cIQmX1ppasgJj 2MiYl2htXvFXjYoWniEmspteNu3UybB0nMHnYjKdQ=="; 96 let signature = "UYTQmygOICKi4ozlMbLSYFZ1olovZZFYT0nZygPrGoA+6+ta+wzKnPnghK4j3 5QSucrf3yN8DSXa/kXBX0LcTmEaSwoNRuM7QPjT6v9hNsVjwNexOUk6pR3DotYuD1yV36sITNjx59McG 8/q6qLyj2A8KVlUbtnz/IiLzzw+wgy6WRjU1meYP8oiQGVIkB21ICqqaJ5kCvM0YrAqzQKAya513O51A DA6aC/EMz6B62XGgZ+AywUMcH2Wvx7cyCvPVLfAbXcgex1JtpPS6vGcdpigaVQkoyl4cIQmX1ppasgJj 2MiYl2htXvFXjYoWniEmspteNu3UybB0nMHnYjKdQ==";
97 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); 97 test.ok(verifySignature(publicKey, signature, data), "Correct signature");
98 98
99 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); 99 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
100 test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data "); 100 test.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wrong d ata");
101 test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.s ubstr(6), data), "Wrong signature"); 101 test.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + signatur e.substring(6), data), "Wrong signature");
102 test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), s ignature, data), "Wrong public key"); 102 test.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.substring (6), signature, data), "Wrong public key");
103 test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); 103 test.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.substrin g(71), signature, data), "Wrong public key");
104 104
105 test.done(); 105 test.done();
106 }; 106 };
107 107
108 exports.testVeryLongData = function(test) 108 exports.testVeryLongData = function(test)
109 { 109 {
110 /* 110 /*
111 -----BEGIN RSA PRIVATE KEY----- 111 -----BEGIN RSA PRIVATE KEY-----
112 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX 112 MIIBOQIBAAJBALZc50pEXnz9TSRozwM04rryuaXl/wgUFqV9FHq8HDlkdKvRU0hX
113 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj 113 hb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQJBALRxYs5irhgAz2b6afOj
114 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3 114 TcFr0PRtipckwW/IPw5euZKyvswEJt/tWDv4OdmDnRe8FSy6FG2Got3zxvaxYdc3
115 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6 115 AXkCIQDfFGcytIVq3sbdF3lmhzcXf29R4Hrxg/eoByAKabxknwIhANFGSNMOGPt6
116 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5 116 JRajfB9XmsltQJzbkr2sfHgjMN2FLM49AiAH6tt2yz1o+5snQawHXYkxBk7XIxZ5
117 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf 117 9+sURZx3giUzlQIfXF+pxX9zh41i0ZtYLn181WxkGNjS7OY2CtF9wEoIfQIgcHuf
118 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA= 118 shh1qrvuKiXnD9b72PF676laKdzxzX5rX6cZZLA=
119 -----END RSA PRIVATE KEY----- 119 -----END RSA PRIVATE KEY-----
120 */ 120 */
121 121
122 let data = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobar"; 122 let data = "foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoob arfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfo obarfoobar";
123 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/ wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ=="; 123 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALZc50pEXnz9TSRozwM04rryuaXl/ wgUFqV9FHq8HDlkdKvRU0hXhb/AKrSpCJ0NCxHtal1l/kHYlHG9e7Ev6+MCAwEAAQ==";
124 let signature = "L1LtPxp9VwL/ij8tuIxJqtx6mD3qoFhcEmPl8A1RlNeOP34A25nzyzRWuP2wE bHcKKXnAQESdIXaTaEuymXviQ=="; 124 let signature = "L1LtPxp9VwL/ij8tuIxJqtx6mD3qoFhcEmPl8A1RlNeOP34A25nzyzRWuP2wE bHcKKXnAQESdIXaTaEuymXviQ==";
125 test.ok(verifySignature(publicKey, signature, data), "Correct signature"); 125 test.ok(verifySignature(publicKey, signature, data), "Correct signature");
126 126
127 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data"); 127 test.ok(!verifySignature(publicKey, signature, data + "1"), "Wrong data");
128 test.ok(!verifySignature(publicKey, signature, data.substr(0, 3)), "Wrong data "); 128 test.ok(!verifySignature(publicKey, signature, data.substring(0, 3)), "Wrong d ata");
129 test.ok(!verifySignature(publicKey, signature.substr(0, 5) + "0" + signature.s ubstr(6), data), "Wrong signature"); 129 test.ok(!verifySignature(publicKey, signature.substring(0, 5) + "0" + signatur e.substring(6), data), "Wrong signature");
130 test.ok(!verifySignature(publicKey.substr(0, 5) + "R" + publicKey.substr(6), s ignature, data), "Wrong public key"); 130 test.ok(!verifySignature(publicKey.substring(0, 5) + "R" + publicKey.substring (6), signature, data), "Wrong public key");
131 test.ok(!verifySignature(publicKey.substr(0, 70) + "8" + publicKey.substr(71), signature, data), "Wrong public key"); 131 test.ok(!verifySignature(publicKey.substring(0, 70) + "8" + publicKey.substrin g(71), signature, data), "Wrong public key");
132 132
133 test.done(); 133 test.done();
134 }; 134 };
135 135
136 exports.testRealLifeSignature = function(test) 136 exports.testRealLifeSignature = function(test)
137 { 137 {
138 let data = [ 138 let data = [
139 "/info/Liquidit%C3%A4t.html?ses=Y3JlPTEzNTUyNDE2OTImdGNpZD13d3cuYWZmaWxpbmV0 LXZlcnplaWNobmlzLmRlNTBjNjAwNzIyNTlkNjQuNDA2MjE2MTImZmtpPTcyOTU2NiZ0YXNrPXNlYXJj aCZkb21haW49YWZmaWxpbmV0LXZlcnplaWNobmlzLmRlJnM9ZGZmM2U5MTEzZGNhMWYyMWEwNDcmbGFu Z3VhZ2U9ZGUmYV9pZD0yJmtleXdvcmQ9TGlxdWlkaXQlQzMlQTR0JnBvcz0yJmt3cz03Jmt3c2k9OA== &token=AG06ipCV1LptGtY_9gFnr0vBTPy4O0YTvwoTCObJ3N3ckrQCFYIA3wod2TwAjxgAIABQv5WiA lCH8qgOUJGr9g9QmuuEG1CDnK0pUPbRrk5QhqDgkQNxP4Qqhz9xZe4", 139 "/info/Liquidit%C3%A4t.html?ses=Y3JlPTEzNTUyNDE2OTImdGNpZD13d3cuYWZmaWxpbmV0 LXZlcnplaWNobmlzLmRlNTBjNjAwNzIyNTlkNjQuNDA2MjE2MTImZmtpPTcyOTU2NiZ0YXNrPXNlYXJj aCZkb21haW49YWZmaWxpbmV0LXZlcnplaWNobmlzLmRlJnM9ZGZmM2U5MTEzZGNhMWYyMWEwNDcmbGFu Z3VhZ2U9ZGUmYV9pZD0yJmtleXdvcmQ9TGlxdWlkaXQlQzMlQTR0JnBvcz0yJmt3cz03Jmt3c2k9OA== &token=AG06ipCV1LptGtY_9gFnr0vBTPy4O0YTvwoTCObJ3N3ckrQCFYIA3wod2TwAjxgAIABQv5WiA lCH8qgOUJGr9g9QmuuEG1CDnK0pUPbRrk5QhqDgkQNxP4Qqhz9xZe4",
140 "www.affilinet-verzeichnis.de", 140 "www.affilinet-verzeichnis.de",
141 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Chro me/25.0.1349.2 Safari/537.21" 141 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.21 (KHTML, like Gecko) Chro me/25.0.1349.2 Safari/537.21"
142 ]; 142 ];
143 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANnylWw2vLY4hUn9w06zQKbhKBfvj FUCsdFlb6TdQhxb9RXWXuI4t31c+o8fYOv/s8q1LGPga3DE1L/tHU4LENMCAwEAAQ=="; 143 let publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANnylWw2vLY4hUn9w06zQKbhKBfvj FUCsdFlb6TdQhxb9RXWXuI4t31c+o8fYOv/s8q1LGPga3DE1L/tHU4LENMCAwEAAQ==";
144 let signature = "nLH8Vbc1rzmy0Q+Xg+bvm43IEO42h8rq5D9C0WCn/Y3ykgAoV4npzm7eMlqBS wZBLA/0DuuVsfTJT9MOVaurcA=="; 144 let signature = "nLH8Vbc1rzmy0Q+Xg+bvm43IEO42h8rq5D9C0WCn/Y3ykgAoV4npzm7eMlqBS wZBLA/0DuuVsfTJT9MOVaurcA==";
145 test.ok(verifySignature(publicKey, signature, data.join("\0")), "Correct signa ture"); 145 test.ok(verifySignature(publicKey, signature, data.join("\0")), "Correct signa ture");
146 146
147 test.done(); 147 test.done();
148 }; 148 };
OLDNEW
« lib/url.js ('K') | « test/matcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld