1+ /*
2+ * JavaScript tracker for Snowplow: tests/functional/cookies.spec.js
3+ *
4+ * Significant portions copyright 2010 Anthon Pang. Remainder copyright
5+ * 2012-2020 Snowplow Analytics Ltd. All rights reserved.
6+ *
7+ * Redistribution and use in source and binary forms, with or without
8+ * modification, are permitted provided that the following conditions are
9+ * met:
10+ *
11+ * * Redistributions of source code must retain the above copyright
12+ * notice, this list of conditions and the following disclaimer.
13+ *
14+ * * Redistributions in binary form must reproduce the above copyright
15+ * notice, this list of conditions and the following disclaimer in the
16+ * documentation and/or other materials provided with the distribution.
17+ *
18+ * * Neither the name of Anthon Pang nor Snowplow Analytics Ltd nor the
19+ * names of their contributors may be used to endorse or promote products
20+ * derived from this software without specific prior written permission.
21+ *
22+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33+ */
34+
35+ describe ( 'Tracker created domain cookies' , ( ) => {
36+ it ( 'contain the expected cookie names' , ( ) => {
37+ browser . url ( '/cookies.html' )
38+ browser . waitUntil (
39+ ( ) => $ ( '#init' ) . getText ( ) === 'true' ,
40+ 5000 ,
41+ 'expected init after 5s'
42+ )
43+
44+ browser . waitUntil (
45+ ( ) => $ ( '#cookies' ) . getText ( ) !== '' ,
46+ 5000 ,
47+ 'expected cookie to be set after 5s'
48+ )
49+
50+ const cookies = $ ( '#cookies' ) . getText ( ) ;
51+
52+ expect ( cookies ) . not . toContain ( '_sp_0ses.' ) ; // Missing as tests are not HTTPS and `cookieSecure: true` by default
53+ expect ( cookies ) . not . toContain ( '_sp_0id.' ) ;
54+ expect ( cookies ) . not . toContain ( '_sp_3es.' ) ; // Missing as cookie lifetime is too short (1)
55+ expect ( cookies ) . not . toContain ( '_sp_3id.' ) ;
56+ expect ( cookies ) . not . toContain ( '_sp_4ses.' ) ; // Missing as anonymous tracking enabled
57+ expect ( cookies ) . not . toContain ( '_sp_4id.' ) ;
58+ expect ( cookies ) . not . toContain ( '_sp_5ses.' ) ; // Missing as only using local storage
59+ expect ( cookies ) . not . toContain ( '_sp_5id.' ) ;
60+ expect ( cookies ) . not . toContain ( '_sp_7ses.' ) ; // Can't set a cookie for another domain
61+ expect ( cookies ) . not . toContain ( '_sp_7id.' ) ;
62+
63+ expect ( cookies ) . toContain ( '_sp_1ses.' ) ;
64+ expect ( cookies ) . toContain ( '_sp_1id.' ) ;
65+ expect ( cookies ) . toContain ( '_sp_2ses.' ) ;
66+ expect ( cookies ) . toContain ( '_sp_2id.' ) ;
67+ expect ( cookies ) . toContain ( '_sp_6ses.' ) ;
68+ expect ( cookies ) . toContain ( '_sp_6id.' ) ;
69+
70+ expect ( $ ( '#getDomainUserId' ) . getText ( ) ) . toMatch ( / \b [ 0 - 9 a - f ] { 8 } \b - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - \b [ 0 - 9 a - f ] { 12 } \b / i) ;
71+ expect ( $ ( '#getDomainUserInfo' ) . getText ( ) ) . toMatch ( / \b [ 0 - 9 a - f ] { 8 } \b - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - \b [ 0 - 9 a - f ] { 12 } \b .[ 0 - 9 ] + .[ 0 - 9 ] .[ 0 - 9 ] + .[ 0 - 9 ] + .\b [ 0 - 9 a - f ] { 8 } \b - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - \b [ 0 - 9 a - f ] { 12 } \b / i) ;
72+ expect ( $ ( '#getUserId' ) . getText ( ) ) . toBe ( 'Dave' ) ;
73+ expect ( $ ( '#getCookieName' ) . getText ( ) ) . toMatch ( / _ s p _ 1 i d .[ 0 - 9 a - z ] { 4 } / i) ;
74+ expect ( $ ( '#getPageViewId' ) . getText ( ) ) . toMatch ( / \b [ 0 - 9 a - f ] { 8 } \b - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - [ 0 - 9 a - f ] { 4 } - \b [ 0 - 9 a - f ] { 12 } \b / i) ;
75+ } )
76+ } )
0 commit comments