Skip to content

Commit 767b4f6

Browse files
committed
[test] add issue8205-open-redir
Ref #8205
1 parent 87d180c commit 767b4f6

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(async function OpenWindow() {
2+
// This crashes
3+
await nw.Window.open('http://127.0.0.1:{port}/redirectme.html');
4+
})();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name":"test-open-redir",
3+
"main":"app.js"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<script>
2+
window.name = 'remote';
3+
document.write('<h1 id="res">PASS</h1>');
4+
</script>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import time
2+
import os
3+
import subprocess
4+
import sys
5+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
6+
from nw_util import *
7+
from selenium import webdriver
8+
from selenium.webdriver.chrome.options import Options
9+
from selenium.webdriver.common import utils
10+
chrome_options = Options()
11+
chrome_options.add_argument('nwapp=' + os.path.dirname(os.path.abspath(__file__)))
12+
capabilities = {'pageLoadStrategy': 'none'}
13+
testdir = os.path.dirname(os.path.abspath(__file__))
14+
os.chdir(testdir)
15+
port, server = start_http_server()
16+
17+
driver = get_configured_webdriver(chrome_options_instance=chrome_options, additional_capabilities=capabilities)
18+
try:
19+
wait_switch_window_name(driver, 'remote')
20+
print(driver.current_url)
21+
result = wait_for_element_id(driver, 'res')
22+
print('result=' + result)
23+
assert 'PASS' in result
24+
finally:
25+
stop_http_server(server)
26+
driver.quit()

test/sanity/server.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ const path = require('path');
66
let svr = http.createServer(function (req, res) {
77
console.log(`${req.method} ${req.url}`);
88

9+
if (req.url === '/redirectme.html') {
10+
let port = svr.address().port;
11+
res.writeHead(308, { 'Location': `/redirected.html` });
12+
res.end();
13+
return;
14+
}
915
// parse URL
1016
const parsedUrl = url.parse(req.url);
1117
// extract URL path
@@ -45,6 +51,15 @@ let svr = http.createServer(function (req, res) {
4551
res.statusCode = 500;
4652
res.end(`Error getting the file: ${err}.`);
4753
} else {
54+
const normalizedPathname = path.normalize(pathname);
55+
const targetFile = path.normalize('./redirected.html');
56+
57+
if (normalizedPathname === targetFile) {
58+
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
59+
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
60+
res.setHeader('Cross-Origin-Resource-Policy', 'same-origin');
61+
console.log(`Added COOP/COEP/CORP headers for ${pathname}`);
62+
}
4863
// if the file is found, set Content-type and send data
4964
res.setHeader('Content-type', map[ext] || 'text/plain' );
5065
res.end(data);

0 commit comments

Comments
 (0)