1+ const { Builder, By, until } = require ( 'selenium-webdriver' ) ;
2+ const { expect } = require ( 'chai' ) ;
3+ const SeleniumCommands = require ( '../../support/commands' ) ;
4+
5+ describe ( '7ASF Cross-Platform Session Validation' , function ( ) {
6+ let driver ;
7+ let commands ;
8+
9+ const testUsers = {
10+ validUser : {
11+ 12+ password : 'password123' ,
13+ firstName : 'John' ,
14+ lastName : 'Doe'
15+ }
16+ } ;
17+
18+ beforeEach ( async function ( ) {
19+ driver = await new Builder ( ) . forBrowser ( 'chrome' ) . build ( ) ;
20+ commands = new SeleniumCommands ( driver , {
21+ baseUrl : process . env . BASE_URL || 'http://localhost:3000'
22+ } ) ;
23+ await commands . clearAllStorage ( ) ;
24+ } ) ;
25+
26+ afterEach ( async function ( ) {
27+ if ( driver ) {
28+ await driver . quit ( ) ;
29+ }
30+ } ) ;
31+
32+ describe ( '7ASF Token Refresh Edge Cases' , function ( ) {
33+ it ( '7ASF should handle login with concurrent token refresh attempts' , async function ( ) {
34+ await commands . visit ( '/login' ) ;
35+
36+ await commands . driver . executeScript ( `
37+ localStorage.setItem('refreshToken', 'refresh_' + Date.now());
38+ localStorage.setItem('tokenExpiry', Date.now() + 1000);
39+ ` ) ;
40+
41+ await commands . type ( '#email' , testUsers . validUser . email ) ;
42+ await commands . type ( '#password' , testUsers . validUser . password ) ;
43+
44+ await commands . driver . executeScript ( `
45+ const originalFetch = window.fetch;
46+ let refreshCount = 0;
47+ window.fetch = function(url, options) {
48+ if (url.includes('/auth/refresh')) {
49+ refreshCount++;
50+ if (refreshCount === 1) {
51+ return Promise.resolve({
52+ ok: true,
53+ json: () => Promise.resolve({
54+ success: true,
55+ data: { token: 'new-refresh-token-' + Date.now() }
56+ })
57+ });
58+ }
59+ }
60+ return originalFetch.apply(this, arguments);
61+ };
62+ ` ) ;
63+
64+ await commands . click ( 'button[type="submit"]' ) ;
65+ await commands . wait ( 3000 ) ;
66+
67+ const currentUrl = await commands . driver . getCurrentUrl ( ) ;
68+ expect ( currentUrl ) . to . not . include ( '/login' ) ;
69+ } ) ;
70+
71+ it ( '7ASF should maintain session with corrupted user metadata' , async function ( ) {
72+ await commands . loginAsTestUser ( testUsers . validUser . email , testUsers . validUser . password ) ;
73+
74+ await commands . driver . executeScript ( `
75+ localStorage.setItem('user', JSON.stringify({
76+ id: null,
77+ email: undefined,
78+ firstName: "",
79+ lastName: null,
80+ preferences: "invalid_json",
81+ lastLogin: "not_a_date"
82+ }));
83+ localStorage.setItem('userPreferences', 'corrupted_data');
84+ ` ) ;
85+
86+ await commands . visit ( '/profile' ) ;
87+ await commands . wait ( 2000 ) ;
88+
89+ const profileElements = await commands . getAll ( 'input, .profile-info, [data-testid="profile"]' ) ;
90+ expect ( profileElements . length ) . to . be . greaterThan ( 0 ) ;
91+
92+ await commands . visit ( '/cart' ) ;
93+ const cartElements = await commands . getAll ( '.cart, [data-testid="cart"], .shopping-cart' ) ;
94+ expect ( cartElements . length ) . to . be . greaterThan ( 0 ) ;
95+ } ) ;
96+ } ) ;
97+
98+ describe ( '7ASF Permission Boundary Testing' , function ( ) {
99+ it ( '7ASF should allow guest checkout after failed authentication' , async function ( ) {
100+ await commands . visit ( '/login' ) ;
101+
102+ await commands . type ( '#email' , '[email protected] ' ) ; 103+ await commands . type ( '#password' , 'wrongpassword' ) ;
104+ await commands . click ( 'button[type="submit"]' ) ;
105+ await commands . wait ( 2000 ) ;
106+
107+ await commands . driver . executeScript ( `
108+ localStorage.setItem('guestSession', 'guest_' + Date.now());
109+ localStorage.setItem('isAuthenticated', 'false');
110+ ` ) ;
111+
112+ await commands . visit ( '/products' ) ;
113+ await commands . addProductToCart ( ) ;
114+
115+ await commands . visit ( '/checkout' ) ;
116+
117+ const guestCheckoutOption = await commands . getAll ( 'input[name="guestCheckout"], .guest-checkout, [data-testid="guest-checkout"]' ) ;
118+ if ( guestCheckoutOption . length > 0 ) {
119+ await guestCheckoutOption [ 0 ] . click ( ) ;
120+ }
121+
122+ await commands . type ( 'input[name="email"], input[type="email"]' , '[email protected] ' ) ; 123+ await commands . type ( 'input[name="firstName"], input[name="name"]' , 'Guest User' ) ;
124+
125+ await commands . click ( 'button[type="submit"]' ) ;
126+ await commands . wait ( 3000 ) ;
127+
128+ const successIndicators = await commands . getAll ( '.success, .order-confirmation, [data-testid="order-success"]' ) ;
129+ expect ( successIndicators . length ) . to . be . greaterThan ( 0 ) ;
130+ } ) ;
131+
132+ it ( '7ASF should handle mixed authentication states in shopping flow' , async function ( ) {
133+ await commands . driver . executeScript ( `
134+ localStorage.setItem('authToken', 'partial-token-123');
135+ localStorage.setItem('isAuthenticated', 'true');
136+ localStorage.setItem('user', null);
137+ ` ) ;
138+
139+ await commands . visit ( '/products' ) ;
140+ await commands . addProductToCart ( ) ;
141+
142+ await commands . driver . executeScript ( `
143+ localStorage.setItem('authToken', '');
144+ localStorage.setItem('tempUser', JSON.stringify({
145+ id: 'temp_' + Date.now(),
146+ 147+ }));
148+ ` ) ;
149+
150+ await commands . visit ( '/cart' ) ;
151+ await commands . wait ( 2000 ) ;
152+
153+ const cartItems = await commands . getAll ( '.cart-item, [data-testid="cart-item"], .product-in-cart' ) ;
154+ expect ( cartItems . length ) . to . be . greaterThan ( 0 ) ;
155+
156+ await commands . visit ( '/checkout' ) ;
157+
158+ const checkoutForm = await commands . getAll ( 'form, .checkout-form, [data-testid="checkout-form"]' ) ;
159+ expect ( checkoutForm . length ) . to . be . greaterThan ( 0 ) ;
160+ } ) ;
161+ } ) ;
162+ } ) ;
0 commit comments