1/** 2 * Host information for cross-origin tests. 3 * @returns {Object} with properties for different host information. 4 */ 5function get_host_info() { 6 7 var HTTP_PORT = '{{ports[http][0]}}'; 8 var HTTP_PORT2 = '{{ports[http][1]}}'; 9 var HTTPS_PORT = '{{ports[https][0]}}'; 10 var HTTPS_PORT2 = '{{ports[https][1]}}'; 11 var PROTOCOL = self.location.protocol; 12 var IS_HTTPS = (PROTOCOL == "https:"); 13 var PORT = IS_HTTPS ? HTTPS_PORT : HTTP_PORT; 14 var PORT2 = IS_HTTPS ? HTTPS_PORT2 : HTTP_PORT2; 15 var HTTP_PORT_ELIDED = HTTP_PORT == "80" ? "" : (":" + HTTP_PORT); 16 var HTTP_PORT2_ELIDED = HTTP_PORT2 == "80" ? "" : (":" + HTTP_PORT2); 17 var HTTPS_PORT_ELIDED = HTTPS_PORT == "443" ? "" : (":" + HTTPS_PORT); 18 var PORT_ELIDED = IS_HTTPS ? HTTPS_PORT_ELIDED : HTTP_PORT_ELIDED; 19 var ORIGINAL_HOST = '{{host}}'; 20 var REMOTE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('www1.' + ORIGINAL_HOST); 21 var OTHER_HOST = '{{domains[www2]}}'; 22 var NOTSAMESITE_HOST = (ORIGINAL_HOST === 'localhost') ? '127.0.0.1' : ('{{hosts[alt][]}}'); 23 24 return { 25 HTTP_PORT: HTTP_PORT, 26 HTTP_PORT2: HTTP_PORT2, 27 HTTPS_PORT: HTTPS_PORT, 28 HTTPS_PORT2: HTTPS_PORT2, 29 PORT: PORT, 30 PORT2: PORT2, 31 ORIGINAL_HOST: ORIGINAL_HOST, 32 REMOTE_HOST: REMOTE_HOST, 33 34 ORIGIN: PROTOCOL + "//" + ORIGINAL_HOST + PORT_ELIDED, 35 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + HTTP_PORT_ELIDED, 36 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + HTTPS_PORT_ELIDED, 37 HTTPS_ORIGIN_WITH_CREDS: 'https://foo:bar@' + ORIGINAL_HOST + HTTPS_PORT_ELIDED, 38 HTTP_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + ORIGINAL_HOST + HTTP_PORT2_ELIDED, 39 REMOTE_ORIGIN: PROTOCOL + "//" + REMOTE_HOST + PORT_ELIDED, 40 OTHER_ORIGIN: PROTOCOL + "//" + OTHER_HOST + PORT_ELIDED, 41 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + HTTP_PORT_ELIDED, 42 HTTP_NOTSAMESITE_ORIGIN: 'http://' + NOTSAMESITE_HOST + HTTP_PORT_ELIDED, 43 HTTP_REMOTE_ORIGIN_WITH_DIFFERENT_PORT: 'http://' + REMOTE_HOST + HTTP_PORT2_ELIDED, 44 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + HTTPS_PORT_ELIDED, 45 HTTPS_REMOTE_ORIGIN_WITH_CREDS: 'https://foo:bar@' + REMOTE_HOST + HTTPS_PORT_ELIDED, 46 HTTPS_NOTSAMESITE_ORIGIN: 'https://' + NOTSAMESITE_HOST + HTTPS_PORT_ELIDED, 47 UNAUTHENTICATED_ORIGIN: 'http://' + OTHER_HOST + HTTP_PORT_ELIDED, 48 AUTHENTICATED_ORIGIN: 'https://' + OTHER_HOST + HTTPS_PORT_ELIDED 49 }; 50} 51 52/** 53 * When a default port is used, location.port returns the empty string. 54 * This function attempts to provide an exact port, assuming we are running under wptserve. 55 * @param {*} loc - can be Location/<a>/<area>/URL, but assumes http/https only. 56 * @returns {string} The port number. 57 */ 58function get_port(loc) { 59 if (loc.port) { 60 return loc.port; 61 } 62 return loc.protocol === 'https:' ? '443' : '80'; 63} 64