@whotracksme/reporting 5.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/.editorconfig +12 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc +16 -0
  4. package/.github/workflows/release.yml +34 -0
  5. package/.github/workflows/tests.yml +20 -0
  6. package/.prettierrc +9 -0
  7. package/.tool-versions +1 -0
  8. package/CHANGELOG.md +795 -0
  9. package/LICENSE +373 -0
  10. package/README.md +1 -0
  11. package/communication/README.md +11 -0
  12. package/communication/example/index.js +43 -0
  13. package/communication/example/manifest.json +16 -0
  14. package/communication/karma.conf.cjs +19 -0
  15. package/communication/package.json +52 -0
  16. package/communication/rollup.common-config.cjs +17 -0
  17. package/communication/rollup.config.cjs +10 -0
  18. package/communication/src/encoding.js +54 -0
  19. package/communication/src/errors.js +84 -0
  20. package/communication/src/index.js +76 -0
  21. package/communication/src/logger.js +41 -0
  22. package/communication/src/padding.js +60 -0
  23. package/communication/src/proxied-http.js +231 -0
  24. package/communication/src/server-public-key-accessor.js +123 -0
  25. package/communication/src/timestamps.js +37 -0
  26. package/communication/src/trusted-clock.js +58 -0
  27. package/communication/src/utils.js +28 -0
  28. package/communication/src/zlib.js +17 -0
  29. package/communication/test/helpers/in-memory-database.js +43 -0
  30. package/communication/test/server-public-key-accessor.spec.js +135 -0
  31. package/communication/test/utils.spec.js +43 -0
  32. package/package.json +50 -0
  33. package/reporting/TODO.md +2 -0
  34. package/reporting/assets/request/bloom_filter.dat +0 -0
  35. package/reporting/assets/request/update.json +1 -0
  36. package/reporting/example/content.js +11 -0
  37. package/reporting/example/index.js +132 -0
  38. package/reporting/example/inspector/index.html +17 -0
  39. package/reporting/example/inspector/index.js +27 -0
  40. package/reporting/example/manifests/chromium.json +37 -0
  41. package/reporting/example/manifests/firefox.json +35 -0
  42. package/reporting/example/rules.json +62 -0
  43. package/reporting/example/setup.js +1 -0
  44. package/reporting/example/tests/test1.html +10 -0
  45. package/reporting/karma.conf.cjs +22 -0
  46. package/reporting/package.json +63 -0
  47. package/reporting/rollup.common-config.cjs +19 -0
  48. package/reporting/rollup.config.cjs +20 -0
  49. package/reporting/src/LRU.js +149 -0
  50. package/reporting/src/activity-estimator.js +298 -0
  51. package/reporting/src/alive-check.js +139 -0
  52. package/reporting/src/alive-message-generator.js +142 -0
  53. package/reporting/src/bloom-filters.js +345 -0
  54. package/reporting/src/country-provider.js +295 -0
  55. package/reporting/src/cyrb53.js +32 -0
  56. package/reporting/src/digest.js +33 -0
  57. package/reporting/src/doublefetch-page-handler.js +548 -0
  58. package/reporting/src/duplicate-detector.js +233 -0
  59. package/reporting/src/errors.js +84 -0
  60. package/reporting/src/event-listener-queue.js +121 -0
  61. package/reporting/src/fixed-size-cache.js +63 -0
  62. package/reporting/src/hash-detector.js +1526 -0
  63. package/reporting/src/html-parser.js +17 -0
  64. package/reporting/src/http.js +265 -0
  65. package/reporting/src/index.js +14 -0
  66. package/reporting/src/job-scheduler.js +912 -0
  67. package/reporting/src/logger.js +121 -0
  68. package/reporting/src/md5.js +334 -0
  69. package/reporting/src/message-sender.js +51 -0
  70. package/reporting/src/network.js +140 -0
  71. package/reporting/src/new-page-approver.js +119 -0
  72. package/reporting/src/page-aggregator.js +185 -0
  73. package/reporting/src/page-quorum-check-handler.js +200 -0
  74. package/reporting/src/page-structure.js +136 -0
  75. package/reporting/src/pagedb.js +671 -0
  76. package/reporting/src/pages.js +1798 -0
  77. package/reporting/src/patterns-updater.js +310 -0
  78. package/reporting/src/patterns.js +416 -0
  79. package/reporting/src/persisted-bitarray.js +265 -0
  80. package/reporting/src/persisted-hashes.js +189 -0
  81. package/reporting/src/quorum-checker.js +327 -0
  82. package/reporting/src/random.js +39 -0
  83. package/reporting/src/reporting.js +290 -0
  84. package/reporting/src/request/config.js +116 -0
  85. package/reporting/src/request/content-script.js +77 -0
  86. package/reporting/src/request/database.js +147 -0
  87. package/reporting/src/request/dnt.js +24 -0
  88. package/reporting/src/request/hash.js +101 -0
  89. package/reporting/src/request/index.js +874 -0
  90. package/reporting/src/request/page-telemetry.js +42 -0
  91. package/reporting/src/request/qs-whitelist2.js +247 -0
  92. package/reporting/src/request/resources/prob.js +601 -0
  93. package/reporting/src/request/steps/block-rules.js +40 -0
  94. package/reporting/src/request/steps/check-context.js +37 -0
  95. package/reporting/src/request/steps/cookie-context.js +209 -0
  96. package/reporting/src/request/steps/oauth-detector.js +101 -0
  97. package/reporting/src/request/steps/page-logger.js +177 -0
  98. package/reporting/src/request/steps/redirect-tagger.js +75 -0
  99. package/reporting/src/request/steps/subdomain-check.js +34 -0
  100. package/reporting/src/request/steps/token-checker/index.js +189 -0
  101. package/reporting/src/request/steps/token-checker/token-domain.js +129 -0
  102. package/reporting/src/request/steps/token-examiner.js +182 -0
  103. package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +210 -0
  104. package/reporting/src/request/steps/token-telemetry/index.js +234 -0
  105. package/reporting/src/request/steps/token-telemetry/key-pipeline.js +109 -0
  106. package/reporting/src/request/steps/token-telemetry/token-pipeline.js +105 -0
  107. package/reporting/src/request/time.js +73 -0
  108. package/reporting/src/request/utils/bloom-filter-packed.js +107 -0
  109. package/reporting/src/request/utils/chrome-storage-map.js +282 -0
  110. package/reporting/src/request/utils/subject.js +37 -0
  111. package/reporting/src/request/utils/temp-set.js +56 -0
  112. package/reporting/src/request/utils/tlds.js +55 -0
  113. package/reporting/src/request/utils.js +41 -0
  114. package/reporting/src/request-reporter.js +111 -0
  115. package/reporting/src/sanitizer.js +519 -0
  116. package/reporting/src/search-extractor.js +338 -0
  117. package/reporting/src/self-check.js +105 -0
  118. package/reporting/src/seq-executor.js +43 -0
  119. package/reporting/src/session-storage.js +399 -0
  120. package/reporting/src/url-analyzer.js +161 -0
  121. package/reporting/src/url-cleaner.js +60 -0
  122. package/reporting/src/utils/pacemaker.js +279 -0
  123. package/reporting/src/utils/url.js +114 -0
  124. package/reporting/src/utils.js +345 -0
  125. package/reporting/src/webrequest-pipeline/cname-uncloak.js +110 -0
  126. package/reporting/src/webrequest-pipeline/index.js +287 -0
  127. package/reporting/src/webrequest-pipeline/logger.js +14 -0
  128. package/reporting/src/webrequest-pipeline/page-store.js +282 -0
  129. package/reporting/src/webrequest-pipeline/page.js +140 -0
  130. package/reporting/src/webrequest-pipeline/pipeline.js +249 -0
  131. package/reporting/src/webrequest-pipeline/utils/webrequest.js +113 -0
  132. package/reporting/src/webrequest-pipeline/webrequest-context.js +153 -0
  133. package/reporting/test/README.md +2 -0
  134. package/reporting/test/activity-estimator.spec.js +356 -0
  135. package/reporting/test/alive-check.spec.js +156 -0
  136. package/reporting/test/alive-message-generator.spec.js +186 -0
  137. package/reporting/test/country-provider.spec.js +263 -0
  138. package/reporting/test/doublefetch-page-handler.spec.js +818 -0
  139. package/reporting/test/duplicate-detector.spec.js +689 -0
  140. package/reporting/test/helpers/dom-parsers.js +41 -0
  141. package/reporting/test/helpers/fake-session-storage.js +69 -0
  142. package/reporting/test/helpers/fast-check-utils.js +28 -0
  143. package/reporting/test/helpers/fetch-mock.js +57 -0
  144. package/reporting/test/helpers/in-memory-database.js +14 -0
  145. package/reporting/test/helpers/memory-map.js +72 -0
  146. package/reporting/test/helpers/pagedb-mocks.js +41 -0
  147. package/reporting/test/index.js +47 -0
  148. package/reporting/test/job-scheduler.spec.js +691 -0
  149. package/reporting/test/network.spec.js +72 -0
  150. package/reporting/test/page-aggregator.spec.js +104 -0
  151. package/reporting/test/page-quorum-check-handler.spec.js +86 -0
  152. package/reporting/test/pagedb.spec.js +250 -0
  153. package/reporting/test/pages.spec.js +693 -0
  154. package/reporting/test/patterns-updater.spec.js +446 -0
  155. package/reporting/test/patterns.spec.js +751 -0
  156. package/reporting/test/persisted-hashes.spec.js +169 -0
  157. package/reporting/test/reporting.spec.js +205 -0
  158. package/reporting/test/request/database.spec.js +59 -0
  159. package/reporting/test/request/hash.spec.js +108 -0
  160. package/reporting/test/request/index.spec.js +378 -0
  161. package/reporting/test/request/qs-whitelist2.spec.js +189 -0
  162. package/reporting/test/request/steps/check-context.spec.js +51 -0
  163. package/reporting/test/request/steps/oauth-detector.spec.js +339 -0
  164. package/reporting/test/request/test-pages.js +1246 -0
  165. package/reporting/test/request/utils/bloom-filter-packed.spec.js +37 -0
  166. package/reporting/test/request/utils/chrome-storage-map.spec.js +28 -0
  167. package/reporting/test/request/utils/tldts.spec.js +62 -0
  168. package/reporting/test/request/utils.spec.js +168 -0
  169. package/reporting/test/sanitizer.spec.js +1087 -0
  170. package/reporting/test/search-extractor.spec.js +590 -0
  171. package/reporting/test/seq-executor.spec.js +158 -0
  172. package/reporting/test/session-storage.spec.js +400 -0
  173. package/reporting/test/setup.js +24 -0
  174. package/reporting/test/url-analyzer.spec.js +451 -0
  175. package/reporting/test/url-cleaner.spec.js +102 -0
  176. package/reporting/test/utils/pacemaker.spec.js +222 -0
  177. package/reporting/test/utils/url.spec.js +660 -0
  178. package/reporting/test/utils.spec.js +299 -0
  179. package/reporting/test/webrequest-pipeline/pipeline.spec.js +251 -0
@@ -0,0 +1,660 @@
1
+ /**
2
+ * WhoTracks.Me
3
+ * https://whotracks.me/
4
+ *
5
+ * Copyright 2017-present Ghostery GmbH. All rights reserved.
6
+ *
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at http://mozilla.org/MPL/2.0
10
+ */
11
+
12
+ import * as chai from 'chai';
13
+
14
+ import { isPrivateIP, getName, parse } from '../../src/utils/url';
15
+
16
+ const plainUrls = [
17
+ {
18
+ url: 'https://cliqz.com',
19
+ url_parts: {
20
+ username: '',
21
+ protocol: 'https',
22
+ hostname: 'cliqz.com',
23
+ path: '/',
24
+ query: '',
25
+ query_keys: {},
26
+ password: '',
27
+ },
28
+ },
29
+ {
30
+ url: 'https://ssl.bbc.co.uk/frameworks/fig/1/fig.js',
31
+ url_parts: {
32
+ username: '',
33
+ protocol: 'https',
34
+ hostname: 'ssl.bbc.co.uk',
35
+ path: '/frameworks/fig/1/fig.js',
36
+ query: '',
37
+ query_keys: {},
38
+ password: '',
39
+ },
40
+ },
41
+ {
42
+ url: 'http://www.bbc.co.uk/wwscripts/flag',
43
+ url_parts: {
44
+ username: '',
45
+ protocol: 'http',
46
+ hostname: 'www.bbc.co.uk',
47
+ path: '/wwscripts/flag',
48
+ query: '',
49
+ query_keys: {},
50
+ password: '',
51
+ },
52
+ },
53
+ ];
54
+
55
+ const queryStrings = [
56
+ {
57
+ url: 'http://pubads.g.doubleclick.net/gampad/ads?gdfp_req=1&correlator=1810614703467044&output=json_html&callback=googletag.impl.pubads.setAdContentsBySlotForSync&impl=ss&json_a=1&eid=108809047%2C108809030%2C108809035%2C108809050&sc=0&sfv=1-0-2&iu_parts=4817%2Cbbccom.live.site.news%2Csport_live_content&enc_prev_ius=%2F0%2F1%2F2%2C%2F0%2F1%2F2%2C%2F0%2F1%2F2%2C%2F0%2F1%2F2&prev_iu_szs=1x1%2C728x90%7C970x300%7C970x250%7C970x90%7C970x66%7C940x230%7C930x180%7C844x179%2C300x250%7C300x600%7C300x1050%2C1x1&ists=1&prev_scp=slot%3Dwallpaper%7Cslot%3Dleaderboard%26sl%3Dtop%7Cslot%3Dmpu%26sl%3Dmiddle%7Cslot%3Dinterstitial&cust_params=kuid%3Dptbex8ffm%26khost%3Dwww.bbc.com%26frd%3D1%26channel%3Dsport%26sectn%3Dlive%26subsect%3Dcricket%26domain%3Dwww.bbc.com%26story_id%3D32809781%26ctype%3Dcontent%26asset_type%3Dlive_event%26referrer%3Dsport0%26referrer_domain%3Dwww.bbc.com%26esi%3D0&cookie=ID%3D2cdd06c7dff60cd5%3AT%3D1438088344%3AS%3DALNI_MY1v4VPWDbtZ4xhDnMydFQI_tzg2g&lmt=1438251866&dt=1438251866165&frm=20&biw=1132&bih=683&oid=3&adks=4009376745%2C679768530%2C2444114410%2C834144271&gut=v2&ifi=1&u_tz=120&u_his=4&u_h=900&u_w=1440&u_ah=828&u_aw=1440&u_cd=24&u_nplug=2&u_nmime=39&u_sd=2&flash=0&url=http%3A%2F%2Fwww.bbc.com%2Fsport%2Flive%2Fcricket%2F32809781&ref=http%3A%2F%2Fwww.bbc.com%2Fsport%2F0%2F&dssz=71&icsg=134217728&std=5&csl=183&vrg=68&vrp=68&ga_vid=1104604060.1437652108&ga_sid=1438251866&ga_hid=1225307609',
58
+ url_parts: {
59
+ username: '',
60
+ protocol: 'http',
61
+ hostname: 'pubads.g.doubleclick.net',
62
+ path: '/gampad/ads',
63
+ query:
64
+ 'gdfp_req=1&correlator=1810614703467044&output=json_html&callback=googletag.impl.pubads.setAdContentsBySlotForSync&impl=ss&json_a=1&eid=108809047%2C108809030%2C108809035%2C108809050&sc=0&sfv=1-0-2&iu_parts=4817%2Cbbccom.live.site.news%2Csport_live_content&enc_prev_ius=%2F0%2F1%2F2%2C%2F0%2F1%2F2%2C%2F0%2F1%2F2%2C%2F0%2F1%2F2&prev_iu_szs=1x1%2C728x90%7C970x300%7C970x250%7C970x90%7C970x66%7C940x230%7C930x180%7C844x179%2C300x250%7C300x600%7C300x1050%2C1x1&ists=1&prev_scp=slot%3Dwallpaper%7Cslot%3Dleaderboard%26sl%3Dtop%7Cslot%3Dmpu%26sl%3Dmiddle%7Cslot%3Dinterstitial&cust_params=kuid%3Dptbex8ffm%26khost%3Dwww.bbc.com%26frd%3D1%26channel%3Dsport%26sectn%3Dlive%26subsect%3Dcricket%26domain%3Dwww.bbc.com%26story_id%3D32809781%26ctype%3Dcontent%26asset_type%3Dlive_event%26referrer%3Dsport0%26referrer_domain%3Dwww.bbc.com%26esi%3D0&cookie=ID%3D2cdd06c7dff60cd5%3AT%3D1438088344%3AS%3DALNI_MY1v4VPWDbtZ4xhDnMydFQI_tzg2g&lmt=1438251866&dt=1438251866165&frm=20&biw=1132&bih=683&oid=3&adks=4009376745%2C679768530%2C2444114410%2C834144271&gut=v2&ifi=1&u_tz=120&u_his=4&u_h=900&u_w=1440&u_ah=828&u_aw=1440&u_cd=24&u_nplug=2&u_nmime=39&u_sd=2&flash=0&url=http%3A%2F%2Fwww.bbc.com%2Fsport%2Flive%2Fcricket%2F32809781&ref=http%3A%2F%2Fwww.bbc.com%2Fsport%2F0%2F&dssz=71&icsg=134217728&std=5&csl=183&vrg=68&vrp=68&ga_vid=1104604060.1437652108&ga_sid=1438251866&ga_hid=1225307609',
65
+ query_keys: {
66
+ flash: '0',
67
+ u_his: '4',
68
+ u_nmime: '39',
69
+ enc_prev_ius: '/0/1/2,/0/1/2,/0/1/2,/0/1/2',
70
+ icsg: '134217728',
71
+ correlator: '1810614703467044',
72
+ ga_hid: '1225307609',
73
+ csl: '183',
74
+ output: 'json_html',
75
+ u_h: '900',
76
+ prev_scp:
77
+ 'slot=wallpaper|slot=leaderboard&sl=top|slot=mpu&sl=middle|slot=interstitial',
78
+ frm: '20',
79
+ prev_iu_szs:
80
+ '1x1,728x90|970x300|970x250|970x90|970x66|940x230|930x180|844x179,300x250|300x600|300x1050,1x1',
81
+ gdfp_req: '1',
82
+ ists: '1',
83
+ u_w: '1440',
84
+ u_sd: '2',
85
+ ref: 'http://www.bbc.com/sport/0/',
86
+ ga_vid: '1104604060.1437652108',
87
+ vrp: '68',
88
+ bih: '683',
89
+ sfv: '1-0-2',
90
+ u_cd: '24',
91
+ oid: '3',
92
+ lmt: '1438251866',
93
+ adks: '4009376745,679768530,2444114410,834144271',
94
+ u_ah: '828',
95
+ json_a: '1',
96
+ vrg: '68',
97
+ ga_sid: '1438251866',
98
+ biw: '1132',
99
+ dt: '1438251866165',
100
+ cust_params:
101
+ 'kuid=ptbex8ffm&khost=www.bbc.com&frd=1&channel=sport&sectn=live&subsect=cricket&domain=www.bbc.com&story_id=32809781&ctype=content&asset_type=live_event&referrer=sport0&referrer_domain=www.bbc.com&esi=0',
102
+ std: '5',
103
+ u_aw: '1440',
104
+ u_tz: '120',
105
+ iu_parts: '4817,bbccom.live.site.news,sport_live_content',
106
+ url: 'http://www.bbc.com/sport/live/cricket/32809781',
107
+ u_nplug: '2',
108
+ callback: 'googletag.impl.pubads.setAdContentsBySlotForSync',
109
+ dssz: '71',
110
+ eid: '108809047,108809030,108809035,108809050',
111
+ gut: 'v2',
112
+ sc: '0',
113
+ cookie:
114
+ 'ID=2cdd06c7dff60cd5:T=1438088344:S=ALNI_MY1v4VPWDbtZ4xhDnMydFQI_tzg2g',
115
+ ifi: '1',
116
+ impl: 'ss',
117
+ },
118
+ password: '',
119
+ },
120
+ },
121
+ {
122
+ url: 'http://cdn.krxd.net/controltag?confid=JZh7-1tL',
123
+ url_parts: {
124
+ username: '',
125
+ protocol: 'http',
126
+ hostname: 'cdn.krxd.net',
127
+ path: '/controltag',
128
+ query: 'confid=JZh7-1tL',
129
+ query_keys: {
130
+ confid: 'JZh7-1tL',
131
+ },
132
+ password: '',
133
+ },
134
+ },
135
+ {
136
+ url: 'http://sa.bbc.co.uk/bbc/bbc/s?name=sport.cricket.international.live_coverage.32809781.page&app_name=sport&app_version=2.8.1058&app_edition=1&is_app=0&page_type=live_coverage&pal_route=bbc_live_sport&ml_name=barlesque&app_type=responsive&language=en-GB&ml_version=0.26.31&pal_webapp=onesport&prod_name=sport&blq_s=4d&blq_r=2.7&blq_v=default&blq_e=pal&bbc_mc=ad1ps1pf1&screen_resolution=1440x900&bbc_site=&ns_ti=Ashes%202015%3A%20England%20v%20Australia%2C%20third%20Test%2C%20Edgbaston%2C%20day%20two%20-%20BBC%20Sport&ns_c=UTF-8&ns__t=1438251866485&ns_jspageurl=http%3A%2F%2Fwww.bbc.com%2Fsport%2Flive%2Fcricket%2F32809781&ns_referrer=http%3A%2F%2Fwww.bbc.com%2Fsport%2F0%2F',
137
+ url_parts: {
138
+ username: '',
139
+ protocol: 'http',
140
+ hostname: 'sa.bbc.co.uk',
141
+ path: '/bbc/bbc/s',
142
+ query:
143
+ 'name=sport.cricket.international.live_coverage.32809781.page&app_name=sport&app_version=2.8.1058&app_edition=1&is_app=0&page_type=live_coverage&pal_route=bbc_live_sport&ml_name=barlesque&app_type=responsive&language=en-GB&ml_version=0.26.31&pal_webapp=onesport&prod_name=sport&blq_s=4d&blq_r=2.7&blq_v=default&blq_e=pal&bbc_mc=ad1ps1pf1&screen_resolution=1440x900&bbc_site=&ns_ti=Ashes%202015%3A%20England%20v%20Australia%2C%20third%20Test%2C%20Edgbaston%2C%20day%20two%20-%20BBC%20Sport&ns_c=UTF-8&ns__t=1438251866485&ns_jspageurl=http%3A%2F%2Fwww.bbc.com%2Fsport%2Flive%2Fcricket%2F32809781&ns_referrer=http%3A%2F%2Fwww.bbc.com%2Fsport%2F0%2F',
144
+ query_keys: {
145
+ screen_resolution: '1440x900',
146
+ app_name: 'sport',
147
+ ns_jspageurl: 'http://www.bbc.com/sport/live/cricket/32809781',
148
+ ml_version: '0.26.31',
149
+ pal_webapp: 'onesport',
150
+ app_type: 'responsive',
151
+ ml_name: 'barlesque',
152
+ app_edition: '1',
153
+ bbc_mc: 'ad1ps1pf1',
154
+ page_type: 'live_coverage',
155
+ app_version: '2.8.1058',
156
+ prod_name: 'sport',
157
+ bbc_site: '',
158
+ blq_s: '4d',
159
+ blq_r: '2.7',
160
+ blq_v: 'default',
161
+ ns_ti:
162
+ 'Ashes 2015: England v Australia, third Test, Edgbaston, day two - BBC Sport',
163
+ blq_e: 'pal',
164
+ pal_route: 'bbc_live_sport',
165
+ name: 'sport.cricket.international.live_coverage.32809781.page',
166
+ language: 'en-GB',
167
+ ns_referrer: 'http://www.bbc.com/sport/0/',
168
+ is_app: '0',
169
+ ns__t: '1438251866485',
170
+ ns_c: 'UTF-8',
171
+ },
172
+ password: '',
173
+ },
174
+ },
175
+ {
176
+ url: 'http://r.nexac.com/e/getdata.xgi?dt=br&pkey=jtkr94hrnfw22&ru=http://ar.atwola.com/atd?it=7%26iv=%3cna_di%3e%26at=8%26av=%3cna_di2%3e%26ds=7%26ed=%3cna_da%3e%26rand=799496',
177
+ url_parts: {
178
+ username: '',
179
+ protocol: 'http',
180
+ hostname: 'r.nexac.com',
181
+ path: '/e/getdata.xgi',
182
+ query:
183
+ 'dt=br&pkey=jtkr94hrnfw22&ru=http://ar.atwola.com/atd?it=7%26iv=%3cna_di%3e%26at=8%26av=%3cna_di2%3e%26ds=7%26ed=%3cna_da%3e%26rand=799496',
184
+ query_keys: {
185
+ pkey: 'jtkr94hrnfw22',
186
+ dt: 'br',
187
+ ru: 'http://ar.atwola.com/atd?it=7&iv=<na_di>&at=8&av=<na_di2>&ds=7&ed=<na_da>&rand=799496',
188
+ },
189
+ password: '',
190
+ },
191
+ },
192
+ {
193
+ url: 'http://tags.bluekai.com/site/19275?ret=html&phint=page=Mashable&phint=channel=home&phint=prop2=Channel',
194
+ url_parts: {
195
+ username: '',
196
+ protocol: 'http',
197
+ hostname: 'tags.bluekai.com',
198
+ path: '/site/19275',
199
+ query:
200
+ 'ret=html&phint=page=Mashable&phint=channel=home&phint=prop2=Channel',
201
+ searchParams: [
202
+ ['ret', 'html'],
203
+ ['phint', 'page=Mashable'],
204
+ ['phint', 'channel=home'],
205
+ ['phint', 'prop2=Channel'],
206
+ ],
207
+ password: '',
208
+ },
209
+ },
210
+ {
211
+ url: 'http://www.adidas.de?cm_mmc=AdieSEM_Google-_-Adidas-Brand-B-Exact-_-Brand-adidas-X-General-_-adidas&cm_mmca1=DE&cm_mmca2=e&gclid=Cj0KEQiA496zBRDoi5OY3p2xmaUBEiQArLNnKyRcv0vcTG0u8qPDyE-mwvW_CMkrZ4SGYODRzSZ54mAaAlBc8P8HAQ&gclsrc=aw.ds',
212
+ url_parts: {
213
+ username: '',
214
+ protocol: 'http',
215
+ hostname: 'www.adidas.de',
216
+ path: '/',
217
+ query:
218
+ 'cm_mmc=AdieSEM_Google-_-Adidas-Brand-B-Exact-_-Brand-adidas-X-General-_-adidas&cm_mmca1=DE&cm_mmca2=e&gclid=Cj0KEQiA496zBRDoi5OY3p2xmaUBEiQArLNnKyRcv0vcTG0u8qPDyE-mwvW_CMkrZ4SGYODRzSZ54mAaAlBc8P8HAQ&gclsrc=aw.ds',
219
+ query_keys: {
220
+ cm_mmc:
221
+ 'AdieSEM_Google-_-Adidas-Brand-B-Exact-_-Brand-adidas-X-General-_-adidas',
222
+ cm_mmca1: 'DE',
223
+ cm_mmca2: 'e',
224
+ gclid:
225
+ 'Cj0KEQiA496zBRDoi5OY3p2xmaUBEiQArLNnKyRcv0vcTG0u8qPDyE-mwvW_CMkrZ4SGYODRzSZ54mAaAlBc8P8HAQ',
226
+ gclsrc: 'aw.ds',
227
+ },
228
+ password: '',
229
+ },
230
+ },
231
+ {
232
+ url: 'http://pix04.revsci.net/F09828/b3/Z/3/120814/588347998.js?D=DM_LOC%3Dhttp%253A%252F%252Fwww.eltern.de%252F%253Fbpid%253Dgrunerjahr%2526_rsiL%253D0%26DM_EOM%3D1&C=F09828&asidi=cliqz.com/tracking&asidi=V6roVyy38IZUh0ZkC_jXhw',
233
+ url_parts: {
234
+ protocol: 'http',
235
+ hostname: 'pix04.revsci.net',
236
+ path: '/F09828/b3/Z/3/120814/588347998.js',
237
+ query:
238
+ 'D=DM_LOC%3Dhttp%253A%252F%252Fwww.eltern.de%252F%253Fbpid%253Dgrunerjahr%2526_rsiL%253D0%26DM_EOM%3D1&C=F09828&asidi=cliqz.com/tracking&asidi=V6roVyy38IZUh0ZkC_jXhw',
239
+ searchParams: [
240
+ [
241
+ 'D',
242
+ 'DM_LOC=http%3A%2F%2Fwww.eltern.de%2F%3Fbpid%3Dgrunerjahr%26_rsiL%3D0&DM_EOM=1',
243
+ ],
244
+ ['C', 'F09828'],
245
+ ['asidi', 'cliqz.com/tracking'],
246
+ ['asidi', 'V6roVyy38IZUh0ZkC_jXhw'],
247
+ ],
248
+ username: '',
249
+ password: '',
250
+ },
251
+ },
252
+ {
253
+ url: 'https://securepubads.g.doubleclick.net/gampad/ads?gdfp_req=1&correlator=381867223985307&output=json_html&callback=googletag.impl.pubads.setPassbackAdContents&impl=s&eid=108809080&sc=1&sfv=1-0-6&iu=/59666047/theguardian.com/x-passback/appnexus&sz=300x250&scp=url=https%3A%2F%2Fwww.theguardian.com%2Fuk-news&edition=int&ct=section&p=ng&k=uk-news&su=0&bp=wide&x=&gdncrm=&pv=j0hz3tifocrvn65tut9x&co=&tn=&slot=inline1&passback=mediamath,appnexus&eri=2&cookie=ID=801c1fee7e3ea0e0:T=1489154693:S=ALNI_Mb77wmklXwm0DZhnZUkB8VwQuRd-Q&cdm=www.theguardian.com&lmt=1490006017&dt=1490006017168&cc=100&ea=0&frm=23&biw=1349&bih=1098&isw=300&ish=250&oid=3&adk=2342784336&ifi=1&ifk=2042039554&u_tz=60&u_his=3&u_h=1440&u_w=2560&u_ah=1366&u_aw=2560&u_cd=24&u_nplug=1&u_nmime=2&u_sd=1&flash=23.0.0&nhd=1&url=https://www.theguardian.com/uk-news&ref=https://www.theguardian.com/international&top=https://www.theguardian.com/uk-news&dssz=8&icsg=346&mso=544&std=8&vrg=111&vrp=111&ga_vid=933737547.1488448014&ga_sid=1490006017&ga_hid=907246662',
254
+ url_parts: {
255
+ hostname: 'securepubads.g.doubleclick.net',
256
+ protocol: 'https',
257
+ path: '/gampad/ads',
258
+ query:
259
+ 'gdfp_req=1&correlator=381867223985307&output=json_html&callback=googletag.impl.pubads.setPassbackAdContents&impl=s&eid=108809080&sc=1&sfv=1-0-6&iu=/59666047/theguardian.com/x-passback/appnexus&sz=300x250&scp=url=https%3A%2F%2Fwww.theguardian.com%2Fuk-news&edition=int&ct=section&p=ng&k=uk-news&su=0&bp=wide&x=&gdncrm=&pv=j0hz3tifocrvn65tut9x&co=&tn=&slot=inline1&passback=mediamath,appnexus&eri=2&cookie=ID=801c1fee7e3ea0e0:T=1489154693:S=ALNI_Mb77wmklXwm0DZhnZUkB8VwQuRd-Q&cdm=www.theguardian.com&lmt=1490006017&dt=1490006017168&cc=100&ea=0&frm=23&biw=1349&bih=1098&isw=300&ish=250&oid=3&adk=2342784336&ifi=1&ifk=2042039554&u_tz=60&u_his=3&u_h=1440&u_w=2560&u_ah=1366&u_aw=2560&u_cd=24&u_nplug=1&u_nmime=2&u_sd=1&flash=23.0.0&nhd=1&url=https://www.theguardian.com/uk-news&ref=https://www.theguardian.com/international&top=https://www.theguardian.com/uk-news&dssz=8&icsg=346&mso=544&std=8&vrg=111&vrp=111&ga_vid=933737547.1488448014&ga_sid=1490006017&ga_hid=907246662',
260
+ query_keys: {
261
+ gdfp_req: '1',
262
+ correlator: '381867223985307',
263
+ output: 'json_html',
264
+ callback: 'googletag.impl.pubads.setPassbackAdContents',
265
+ impl: 's',
266
+ eid: '108809080',
267
+ sc: '1',
268
+ sfv: '1-0-6',
269
+ iu: '/59666047/theguardian.com/x-passback/appnexus',
270
+ sz: '300x250',
271
+ scp: 'url=https://www.theguardian.com/uk-news',
272
+ edition: 'int',
273
+ ct: 'section',
274
+ p: 'ng',
275
+ k: 'uk-news',
276
+ su: '0',
277
+ bp: 'wide',
278
+ x: '',
279
+ gdncrm: '',
280
+ pv: 'j0hz3tifocrvn65tut9x',
281
+ co: '',
282
+ tn: '',
283
+ slot: 'inline1',
284
+ passback: 'mediamath,appnexus',
285
+ eri: '2',
286
+ cookie:
287
+ 'ID=801c1fee7e3ea0e0:T=1489154693:S=ALNI_Mb77wmklXwm0DZhnZUkB8VwQuRd-Q',
288
+ cdm: 'www.theguardian.com',
289
+ lmt: '1490006017',
290
+ dt: '1490006017168',
291
+ cc: '100',
292
+ ea: '0',
293
+ frm: '23',
294
+ biw: '1349',
295
+ bih: '1098',
296
+ isw: '300',
297
+ ish: '250',
298
+ oid: '3',
299
+ adk: '2342784336',
300
+ ifi: '1',
301
+ ifk: '2042039554',
302
+ u_tz: '60',
303
+ u_his: '3',
304
+ u_h: '1440',
305
+ u_w: '2560',
306
+ u_ah: '1366',
307
+ u_aw: '2560',
308
+ u_cd: '24',
309
+ u_nplug: '1',
310
+ u_nmime: '2',
311
+ u_sd: '1',
312
+ flash: '23.0.0',
313
+ nhd: '1',
314
+ url: 'https://www.theguardian.com/uk-news',
315
+ ref: 'https://www.theguardian.com/international',
316
+ top: 'https://www.theguardian.com/uk-news',
317
+ dssz: '8',
318
+ icsg: '346',
319
+ mso: '544',
320
+ std: '8',
321
+ vrg: '111',
322
+ vrp: '111',
323
+ ga_vid: '933737547.1488448014',
324
+ ga_sid: '1490006017',
325
+ ga_hid: '907246662',
326
+ },
327
+ },
328
+ },
329
+ ];
330
+
331
+ const parameters = [
332
+ {
333
+ url: 'http://pixel.quantserve.com/pixel;r=1275226977;a=p-3aud4J6uA4Z6Y;labels=verticalHP.index;fpan=0;fpa=P0-113403507-1437990328261;ns=0;ce=1;cm=;je=0;sr=1440x900x24;enc=n;dst=1;et=1438251870170;tzo=-120;ref=;url=http%3A%2F%2Fwww.buzzfeed.com%2F;ogl=site_name.BuzzFeed%2Ctype.website%2Cdescription.BuzzFeed%20has%20the%20hottest%252C%20most%20social%20content%20on%20the%20web%252E%20We%20feature%20breaking%20bu%2Ctitle.BuzzFeed%2Cimage.http%3A%2F%2Fs3-ak%252Ebuzzfed%252Ecom%2Fstatic%2Fimages%2Fglobal%2Fbuzzfeed%252Ejpg%3Fv%3D201507291520%2Curl.http%3A%2F%2Fwww%252Ebuzzfeed%252Ecom',
334
+ url_parts: {
335
+ username: '',
336
+ protocol: 'http',
337
+ hostname: 'pixel.quantserve.com',
338
+ path: '/pixel;r=1275226977;a=p-3aud4J6uA4Z6Y;labels=verticalHP.index;fpan=0;fpa=P0-113403507-1437990328261;ns=0;ce=1;cm=;je=0;sr=1440x900x24;enc=n;dst=1;et=1438251870170;tzo=-120;ref=;url=http%3A%2F%2Fwww.buzzfeed.com%2F;ogl=site_name.BuzzFeed%2Ctype.website%2Cdescription.BuzzFeed%20has%20the%20hottest%252C%20most%20social%20content%20on%20the%20web%252E%20We%20feature%20breaking%20bu%2Ctitle.BuzzFeed%2Cimage.http%3A%2F%2Fs3-ak%252Ebuzzfed%252Ecom%2Fstatic%2Fimages%2Fglobal%2Fbuzzfeed%252Ejpg%3Fv%3D201507291520%2Curl.http%3A%2F%2Fwww%252Ebuzzfeed%252Ecom',
339
+ parameters:
340
+ 'r=1275226977;a=p-3aud4J6uA4Z6Y;labels=verticalHP.index;fpan=0;fpa=P0-113403507-1437990328261;ns=0;ce=1;cm=;je=0;sr=1440x900x24;enc=n;dst=1;et=1438251870170;tzo=-120;ref=;url=http%3A%2F%2Fwww.buzzfeed.com%2F;ogl=site_name.BuzzFeed%2Ctype.website%2Cdescription.BuzzFeed%20has%20the%20hottest%252C%20most%20social%20content%20on%20the%20web%252E%20We%20feature%20breaking%20bu%2Ctitle.BuzzFeed%2Cimage.http%3A%2F%2Fs3-ak%252Ebuzzfed%252Ecom%2Fstatic%2Fimages%2Fglobal%2Fbuzzfeed%252Ejpg%3Fv%3D201507291520%2Curl.http%3A%2F%2Fwww%252Ebuzzfeed%252Ecom',
341
+ parameter_keys: {
342
+ r: '1275226977',
343
+ a: 'p-3aud4J6uA4Z6Y',
344
+ labels: 'verticalHP.index',
345
+ fpan: '0',
346
+ fpa: 'P0-113403507-1437990328261',
347
+ ns: '0',
348
+ ce: '1',
349
+ cm: '',
350
+ je: '0',
351
+ sr: '1440x900x24',
352
+ enc: 'n',
353
+ dst: '1',
354
+ et: '1438251870170',
355
+ tzo: '-120',
356
+ ref: '',
357
+ url: 'http://www.buzzfeed.com/',
358
+ ogl: 'site_name.BuzzFeed,type.website,description.BuzzFeed has the hottest%2C most social content on the web%2E We feature breaking bu,title.BuzzFeed,image.http://s3-ak%2Ebuzzfed%2Ecom/static/images/global/buzzfeed%2Ejpg?v=201507291520,url.http://www%2Ebuzzfeed%2Ecom',
359
+ },
360
+ query: '',
361
+ query_keys: {},
362
+ password: '',
363
+ },
364
+ },
365
+ ];
366
+
367
+ const fragments = [
368
+ {
369
+ url: 'http://s7.addthis.com/js/250/addthis_widget.js#async=1&username=wettercom',
370
+ url_parts: {
371
+ username: '',
372
+ protocol: 'http',
373
+ hostname: 's7.addthis.com',
374
+ path: '/js/250/addthis_widget.js',
375
+ query: '',
376
+ query_keys: {},
377
+ fragment: '#async=1&username=wettercom',
378
+ fragment_keys: {
379
+ async: '1',
380
+ username: 'wettercom',
381
+ },
382
+ password: '',
383
+ },
384
+ },
385
+ ];
386
+
387
+ const combined = [
388
+ {
389
+ url: 'https://accounts.google.com/o/oauth2/postmessageRelay?parent=http%3A%2F%2Fwww.buzzfeed.com#rpctoken=797034019&forcesecure=1',
390
+ url_parts: {
391
+ username: '',
392
+ protocol: 'https',
393
+ hostname: 'accounts.google.com',
394
+ path: '/o/oauth2/postmessageRelay',
395
+ query: 'parent=http%3A%2F%2Fwww.buzzfeed.com',
396
+ query_keys: {
397
+ parent: 'http://www.buzzfeed.com',
398
+ },
399
+ fragment: '#rpctoken=797034019&forcesecure=1',
400
+ fragment_keys: {
401
+ rpctoken: '797034019',
402
+ forcesecure: '1',
403
+ },
404
+ password: '',
405
+ },
406
+ },
407
+ {
408
+ url: 'http://fast.adobe.demdex.net/dest4.html?d_nsid=0#http%3A%2F%2Fwww.adobe.com%2F%23',
409
+ url_parts: {
410
+ username: '',
411
+ protocol: 'http',
412
+ hostname: 'fast.adobe.demdex.net',
413
+ path: '/dest4.html',
414
+ query: 'd_nsid=0',
415
+ query_keys: {
416
+ d_nsid: '0',
417
+ },
418
+ fragment: '#http%3A%2F%2Fwww.adobe.com%2F%23',
419
+ fragment_keys: {
420
+ 'http%3A%2F%2Fwww.adobe.com%2F%23': 'true',
421
+ },
422
+ password: '',
423
+ },
424
+ },
425
+ {
426
+ url: 'http://myname:mypassword@example.com:81/some/path;with=parameters;howmany=2?also=query#andfinally=fragment',
427
+ url_parts: {
428
+ protocol: 'http',
429
+ username: 'myname',
430
+ password: 'mypassword',
431
+ hostname: 'example.com',
432
+ port: '81',
433
+ path: '/some/path;with=parameters;howmany=2',
434
+ parameters: 'with=parameters;howmany=2',
435
+ parameter_keys: {
436
+ with: 'parameters',
437
+ howmany: '2',
438
+ },
439
+ query: 'also=query',
440
+ query_keys: {
441
+ also: 'query',
442
+ },
443
+ fragment: '#andfinally=fragment',
444
+ fragment_keys: {
445
+ andfinally: 'fragment',
446
+ },
447
+ },
448
+ },
449
+ ];
450
+
451
+ const special = [
452
+ {
453
+ url: 'https://apis.google.com/_/scs/apps-static/_/js/k=oz.gapi.de.qTommvXNk3Y.O/m=gapi_iframes_style_common,plusone/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCPFQTY3xyU4E7vwFYmIgrjbG0BFEA/cb=gapi.loaded_0',
454
+ url_parts: {
455
+ protocol: 'https',
456
+ hostname: 'apis.google.com',
457
+ path: '/_/scs/apps-static/_/js/k=oz.gapi.de.qTommvXNk3Y.O/m=gapi_iframes_style_common,plusone/rt=j/sv=1/d=1/ed=1/am=AQ/rs=AGLTcCPFQTY3xyU4E7vwFYmIgrjbG0BFEA/cb=gapi.loaded_0',
458
+ },
459
+ },
460
+ {
461
+ url: 'https://accounts.google.com/o/oauth2/postmessageRelay?parent=https%3A%2F%2Fwww.blogger.com&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.de.qTommvXNk3Y.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAGLTcCPFQTY3xyU4E7vwFYmIgrjbG0BFEA#rpctoken=686210141&forcesecure=1',
462
+ url_parts: {
463
+ protocol: 'https',
464
+ hostname: 'accounts.google.com',
465
+ path: '/o/oauth2/postmessageRelay',
466
+ query:
467
+ 'parent=https%3A%2F%2Fwww.blogger.com&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.de.qTommvXNk3Y.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAGLTcCPFQTY3xyU4E7vwFYmIgrjbG0BFEA',
468
+ query_keys: {
469
+ parent: 'https://www.blogger.com',
470
+ jsh: 'm;/_/scs/apps-static/_/js/k=oz.gapi.de.qTommvXNk3Y.O/m=__features__/am=AQ/rt=j/d=1/rs=AGLTcCPFQTY3xyU4E7vwFYmIgrjbG0BFEA',
471
+ },
472
+ fragment: '#rpctoken=686210141&forcesecure=1',
473
+ fragment_keys: {
474
+ rpctoken: '686210141',
475
+ forcesecure: '1',
476
+ },
477
+ },
478
+ },
479
+ ];
480
+
481
+ const emptyParts = {
482
+ protocol: '',
483
+ username: '',
484
+ password: '',
485
+ hostname: '',
486
+ port: '',
487
+ path: '',
488
+ parameters: '',
489
+ parameter_keys: {},
490
+ query: '',
491
+ query_keys: {},
492
+ fragment: '',
493
+ fragment_keys: {},
494
+ };
495
+
496
+ const keyValueTestCases = [
497
+ {
498
+ url: 'https://cliqz.com',
499
+ expectedKv: [],
500
+ },
501
+ {
502
+ url: 'http://pix04.revsci.net/F09828/b3/Z/3/120814/588347998.js?D=DM_LOC%3Dhttp%253A%252F%252Fwww.eltern.de%252F%253Fbpid%253Dgrunerjahr%2526_rsiL%253D0%26DM_EOM%3D1&C=F09828&asidi=cliqz.com/tracking&asidi=V6roVyy38IZUh0ZkC_jXhw',
503
+ expectedKv: [
504
+ [
505
+ 'D',
506
+ 'DM_LOC=http%3A%2F%2Fwww.eltern.de%2F%3Fbpid%3Dgrunerjahr%26_rsiL%3D0&DM_EOM=1',
507
+ ],
508
+ ['C', 'F09828'],
509
+ ['asidi', 'cliqz.com/tracking'],
510
+ ['asidi', 'V6roVyy38IZUh0ZkC_jXhw'],
511
+ ],
512
+ },
513
+ ];
514
+
515
+ function fillInSpec(spec) {
516
+ Object.keys(emptyParts).forEach(function (k) {
517
+ // eslint-disable-next-line no-param-reassign
518
+ spec[k] = spec[k] || emptyParts[k];
519
+ });
520
+ return spec;
521
+ }
522
+
523
+ describe('utils/url', function () {
524
+ describe('#isPrivateIP', function () {
525
+ it('should detect private ipv4 subnets', function () {
526
+ chai.expect(isPrivateIP('127.0.0.1')).to.be.true;
527
+ chai.expect(isPrivateIP('192.168.2.107')).to.be.true;
528
+ chai.expect(isPrivateIP('192.168.1.41')).to.be.true;
529
+ chai.expect(isPrivateIP('10.0.5.250')).to.be.true;
530
+ });
531
+
532
+ it('should detect public ipv4 subnets', function () {
533
+ chai.expect(isPrivateIP('93.184.216.34')).to.be.false;
534
+ });
535
+
536
+ // once we add support for ipv6, this test is expected to pass
537
+ it('should detect private ipv6 subnets', function () {
538
+ chai.expect(isPrivateIP('::1')).to.be.true;
539
+ chai.expect(isPrivateIP('0:0:0:0:0:0:0:1')).to.be.true;
540
+ chai.expect(isPrivateIP('fd12:3456:789a:1::1')).to.be.true;
541
+ });
542
+
543
+ it('should detect public ipv6 address', function () {
544
+ chai.expect(isPrivateIP('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).to.be
545
+ .false;
546
+ });
547
+ });
548
+
549
+ describe('#getName', () => {
550
+ it('return "null" for invalid URL', () => {
551
+ chai.expect(getName(parse('foo'))).to.equal(null);
552
+ });
553
+
554
+ it('return "IP" if URL is ipv4', () => {
555
+ chai.expect(getName(parse('https://1.1.1.1/'))).to.equal('IP');
556
+ });
557
+
558
+ // Currently not handled by '@cliqz/url-parser' but will be fixed soon.
559
+ it.skip('return "IP" if URL is ipv6', () => {
560
+ chai.expect(getName(parse('https://[::1]/'))).to.equal('IP');
561
+ });
562
+
563
+ it('handle localhost', () => {
564
+ chai
565
+ .expect(getName(parse('http://localhost/path')))
566
+ .to.equal('localhost');
567
+ });
568
+
569
+ it('return domain without suffix', () => {
570
+ chai.expect(getName(parse('https://sub.foo.co.uk'))).to.equal('foo');
571
+ });
572
+ });
573
+
574
+ describe('#parse', () => {
575
+ function testSpecArray(name, spec) {
576
+ describe(name, function () {
577
+ spec.forEach(function (testcase) {
578
+ let urlDesc = testcase.url;
579
+ if (urlDesc.length > 180) urlDesc = `${urlDesc.substring(0, 180)}...`;
580
+ it(urlDesc, function () {
581
+ const expected = fillInSpec(testcase.url_parts);
582
+ const actual = parse(testcase.url);
583
+ chai.expect(actual.protocol).to.equal(`${expected.protocol}:`);
584
+ chai.expect(actual.username).to.equal(expected.username);
585
+ chai.expect(actual.password).to.equal(expected.password);
586
+ chai.expect(actual.hostname).to.equal(expected.hostname);
587
+ chai.expect(actual.port).to.equal(expected.port);
588
+ chai.expect(actual.pathname).to.equal(expected.path);
589
+ if (expected.query) {
590
+ chai.expect(actual.search).to.equal(`?${expected.query}`);
591
+ } else {
592
+ chai.expect(actual.search).to.equal('');
593
+ }
594
+ chai.expect(actual.hash).to.equal(expected.fragment);
595
+
596
+ if (expected.searchParams) {
597
+ chai
598
+ .expect(actual.searchParams.params.length, 'detected QS values')
599
+ .to.equal(expected.searchParams.length);
600
+ let i = 0;
601
+ for (const [k, v] of actual.searchParams.entries()) {
602
+ chai.expect(k).to.equal(expected.searchParams[i][0]);
603
+ chai.expect(v).to.equal(expected.searchParams[i][1]);
604
+ i += 1;
605
+ }
606
+ } else {
607
+ // legacy spec using object
608
+ chai
609
+ .expect(actual.searchParams.params.length, 'detected QS values')
610
+ .to.equal(Object.keys(expected.query_keys).length);
611
+ chai
612
+ .expect(actual.parameters.params.length, 'detected PS values')
613
+ .to.equal(Object.keys(expected.parameter_keys).length);
614
+
615
+ for (const [k, v] of actual.searchParams.entries()) {
616
+ chai.expect(v).to.equal(expected.query_keys[k]);
617
+ }
618
+ for (const [k, v] of actual.parameters.entries()) {
619
+ chai.expect(v).to.equal(expected.parameter_keys[k]);
620
+ }
621
+ }
622
+ });
623
+ });
624
+ });
625
+ }
626
+
627
+ // test examples
628
+ testSpecArray('plain urls', plainUrls);
629
+ testSpecArray('query strings', queryStrings);
630
+ testSpecArray('parameter strings', parameters);
631
+ testSpecArray('fragment strings', fragments);
632
+ testSpecArray('combined', combined);
633
+ testSpecArray('special', special);
634
+
635
+ describe('get', function () {
636
+ it('returns null if argument is falsy', () => {
637
+ chai.expect(parse('')).to.be.null;
638
+ chai.expect(parse()).to.be.null;
639
+ chai.expect(parse(false)).to.be.null;
640
+ chai.expect(parse(null)).to.be.null;
641
+ });
642
+
643
+ it('returns parsed url info for valid url', () => {
644
+ const urlParts = parse('https://cliqz.com');
645
+ chai.expect(urlParts.hostname).to.equal('cliqz.com');
646
+ chai.expect(urlParts.protocol).to.equal('https:');
647
+ chai.expect(urlParts.pathname).to.equal('/');
648
+ });
649
+ });
650
+
651
+ describe('getKeyValues', function () {
652
+ keyValueTestCases.forEach((testCase) => {
653
+ it(testCase.url, () => {
654
+ const kv = [...parse(testCase.url).searchParams.entries()];
655
+ chai.expect(kv).to.eql(testCase.expectedKv);
656
+ });
657
+ });
658
+ });
659
+ });
660
+ });