Skip to content

Commit 54d30d4

Browse files
committed
[NOCSL] Add url validation (Constructor-io#419)
* add tests * add url validation * try catch * remove console log * more tests * minor test fix
1 parent dd8b22d commit 54d30d4

3 files changed

Lines changed: 106 additions & 49 deletions

File tree

spec/src/modules/tracker.js

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const testAnalyticsTag = { param1: 'test', param2: 'test2' };
2727
const utmParameters = 'utm_source=attentive&utm_medium=sms&utm_campaign=campaign_1';
2828
const url = `http://localhost.test/path/name?query=term&category=cat&${utmParameters}`;
2929
const referrer = 'https://www.google.com/';
30+
const canonicalUrl = 'https://localhost/';
3031

3132
function validateOriginReferrer(requestParams) {
3233
expect(requestParams).to.have.property('origin_referrer').to.contain('localhost.test/path/name');
@@ -201,7 +202,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
201202

202203
// Request
203204
expect(fetchSpy).to.have.been.called;
204-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
205+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
205206
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
206207

207208
// Response
@@ -490,7 +491,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
490491

491492
// Request
492493
expect(fetchSpy).to.have.been.called;
493-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
494+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
494495
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
495496

496497
// Response
@@ -1066,7 +1067,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
10661067

10671068
// Request
10681069
expect(fetchSpy).to.have.been.called;
1069-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
1070+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
10701071
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
10711072
validateOriginReferrer(requestParams);
10721073

@@ -1439,7 +1440,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
14391440

14401441
// Request
14411442
expect(fetchSpy).to.have.been.called;
1442-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
1443+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
14431444
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
14441445

14451446
// Response
@@ -1850,7 +1851,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
18501851

18511852
// Request
18521853
expect(fetchSpy).to.have.been.called;
1853-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
1854+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
18541855
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
18551856

18561857
// Response
@@ -2317,11 +2318,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
23172318

23182319
// Request
23192320
expect(fetchSpy).to.have.been.called;
2320-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
2321+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
23212322
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
23222323

23232324
// Body
2324-
expect(bodyParams).to.have.property('canonical_url').to.equal('https://localhost');
2325+
expect(bodyParams).to.have.property('canonical_url').to.equal(canonicalUrl);
23252326
expect(bodyParams).to.have.property('document_referrer').to.equal(referrer);
23262327

23272328
// Response
@@ -3031,7 +3032,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
30313032

30323033
// Request
30333034
expect(fetchSpy).to.have.been.called;
3034-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
3035+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
30353036
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
30363037

30373038
// Response
@@ -3579,7 +3580,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
35793580

35803581
// Request
35813582
expect(fetchSpy).to.have.been.called;
3582-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
3583+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
35833584
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
35843585

35853586
// Response
@@ -4168,11 +4169,11 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
41684169

41694170
// Request
41704171
expect(fetchSpy).to.have.been.called;
4171-
expect(requestQueryParams).to.have.property('canonical_url').to.equal('https://localhost');
4172+
expect(requestQueryParams).to.have.property('canonical_url').to.equal(canonicalUrl);
41724173
expect(requestQueryParams).to.have.property('document_referrer').to.equal(referrer);
41734174

41744175
// Body
4175-
expect(requestBodyParams).to.have.property('canonical_url').to.equal('https://localhost');
4176+
expect(requestBodyParams).to.have.property('canonical_url').to.equal(canonicalUrl);
41764177
expect(requestBodyParams).to.have.property('document_referrer').to.equal(referrer);
41774178

41784179
// Response
@@ -4663,7 +4664,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
46634664

46644665
// Request
46654666
expect(fetchSpy).to.have.been.called;
4666-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
4667+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
46674668
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
46684669

46694670
// Response
@@ -5373,7 +5374,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
53735374

53745375
// Request
53755376
expect(fetchSpy).to.have.been.called;
5376-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
5377+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
53775378
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
53785379

53795380
// Response
@@ -5920,7 +5921,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
59205921

59215922
// Request
59225923
expect(fetchSpy).to.have.been.called;
5923-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
5924+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
59245925
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
59255926

59265927
// Response
@@ -6339,7 +6340,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
63396340

63406341
// Request
63416342
expect(fetchSpy).to.have.been.called;
6342-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
6343+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
63436344
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
63446345

63456346
// Response
@@ -6754,7 +6755,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
67546755

67556756
// Request
67566757
expect(fetchSpy).to.have.been.called;
6757-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
6758+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
67586759
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
67596760

67606761
// Response
@@ -7204,7 +7205,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
72047205

72057206
// Request
72067207
expect(fetchSpy).to.have.been.called;
7207-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
7208+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
72087209
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
72097210

72107211
// Response
@@ -7658,7 +7659,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
76587659

76597660
// Request
76607661
expect(fetchSpy).to.have.been.called;
7661-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
7662+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
76627663
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
76637664

76647665
// Response
@@ -8158,7 +8159,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
81588159

81598160
// Request
81608161
expect(fetchSpy).to.have.been.called;
8161-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
8162+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
81628163
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
81638164

81648165
// Response
@@ -8596,7 +8597,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
85968597

85978598
// Request
85988599
expect(fetchSpy).to.have.been.called;
8599-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
8600+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
86008601
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
86018602

86028603
// Response
@@ -9085,7 +9086,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
90859086

90869087
// Request
90879088
expect(fetchSpy).to.have.been.called;
9088-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
9089+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
90899090
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
90909091

90919092
// Response
@@ -9400,7 +9401,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
94009401

94019402
// Request
94029403
expect(fetchSpy).to.have.been.called;
9403-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
9404+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
94049405
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
94059406

94069407
// Response
@@ -9718,7 +9719,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
97189719

97199720
// Request
97209721
expect(fetchSpy).to.have.been.called;
9721-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
9722+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
97229723
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
97239724

97249725
// Response
@@ -10044,7 +10045,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1004410045

1004510046
// Request
1004610047
expect(fetchSpy).to.have.been.called;
10047-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
10048+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1004810049
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1004910050

1005010051
// Response
@@ -10388,7 +10389,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1038810389

1038910390
// Request
1039010391
expect(fetchSpy).to.have.been.called;
10391-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
10392+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1039210393
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1039310394

1039410395
// Response
@@ -10707,7 +10708,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1070710708

1070810709
// Request
1070910710
expect(fetchSpy).to.have.been.called;
10710-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
10711+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1071110712
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1071210713

1071310714
// Response
@@ -11022,7 +11023,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1102211023

1102311024
// Request
1102411025
expect(fetchSpy).to.have.been.called;
11025-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
11026+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1102611027
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1102711028

1102811029
// Response
@@ -11337,7 +11338,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1133711338

1133811339
// Request
1133911340
expect(fetchSpy).to.have.been.called;
11340-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
11341+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1134111342
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1134211343

1134311344
// Response
@@ -11655,7 +11656,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1165511656

1165611657
// Request
1165711658
expect(fetchSpy).to.have.been.called;
11658-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
11659+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1165911660
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1166011661

1166111662
// Response
@@ -11981,7 +11982,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1198111982

1198211983
// Request
1198311984
expect(fetchSpy).to.have.been.called;
11984-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
11985+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1198511986
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1198611987

1198711988
// Response
@@ -12325,7 +12326,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1232512326

1232612327
// Request
1232712328
expect(fetchSpy).to.have.been.called;
12328-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
12329+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1232912330
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1233012331

1233112332
// Response
@@ -12644,7 +12645,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1264412645

1264512646
// Request
1264612647
expect(fetchSpy).to.have.been.called;
12647-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
12648+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1264812649
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1264912650

1265012651
// Response
@@ -12981,7 +12982,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1298112982

1298212983
// Request
1298312984
expect(fetchSpy).to.have.been.called;
12984-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
12985+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1298512986
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1298612987

1298712988
// Response
@@ -13310,7 +13311,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1331013311

1331113312
// Request
1331213313
expect(fetchSpy).to.have.been.called;
13313-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
13314+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1331413315
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1331513316

1331613317
// Response
@@ -13632,7 +13633,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1363213633

1363313634
// Request
1363413635
expect(fetchSpy).to.have.been.called;
13635-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
13636+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1363613637
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1363713638

1363813639
// Response
@@ -13952,7 +13953,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1395213953

1395313954
// Request
1395413955
expect(fetchSpy).to.have.been.called;
13955-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
13956+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1395613957
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1395713958

1395813959
// Response
@@ -14273,7 +14274,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1427314274

1427414275
// Request
1427514276
expect(fetchSpy).to.have.been.called;
14276-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
14277+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1427714278
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1427814279

1427914280
// Response
@@ -14594,7 +14595,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1459414595

1459514596
// Request
1459614597
expect(fetchSpy).to.have.been.called;
14597-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
14598+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1459814599
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1459914600

1460014601
// Response
@@ -14917,7 +14918,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1491714918

1491814919
// Request
1491914920
expect(fetchSpy).to.have.been.called;
14920-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
14921+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1492114922
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1492214923

1492314924
// Response
@@ -15240,7 +15241,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1524015241

1524115242
// Request
1524215243
expect(fetchSpy).to.have.been.called;
15243-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
15244+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1524415245
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1524515246

1524615247
// Response
@@ -15537,7 +15538,7 @@ describe(`ConstructorIO - Tracker${bundledDescriptionSuffix}`, () => {
1553715538
expect(requestParams).to.have.property('s');
1553815539
expect(requestParams).to.have.property('c').to.equal(clientVersion);
1553915540
expect(requestParams).to.have.property('_dt');
15540-
expect(requestParams).to.have.property('canonical_url').to.equal('https://localhost');
15541+
expect(requestParams).to.have.property('canonical_url').to.equal(canonicalUrl);
1554115542
expect(requestParams).to.have.property('document_referrer').to.equal(referrer);
1554215543
expect(requestParams)
1554315544
.to.have.property('banner_ad_id')

0 commit comments

Comments
 (0)