Testing Node Remote Access Restrictions in NW.js
This test suite validates node remote functionality in NW.js by implementing a Python-based integration test that verifies remote node access restrictions. The test uses Selenium WebDriver to automate browser interactions and validates security boundaries for node remote access.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
nwjs/nwJs
test/sanity/node-remote-negtive/test.py
import time
import os
import sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from nw_util import *
import subprocess
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common import utils
chrome_options = Options()
chrome_options.add_argument("nwapp=" + os.path.dirname(os.path.abspath(__file__)))
testdir = os.path.dirname(os.path.abspath(__file__))
os.chdir(testdir)
port = str(utils.free_port())
server = subprocess.Popen(['python3', 'http-server.py', port])
manifest = open('package.json', 'w')
manifest.write('''
{
"name":"test-node-remote",
"main":"http://localhost:%s/index.html"
}
''' % (port))
manifest.close()
driver = webdriver.Chrome(executable_path=os.environ['CHROMEDRIVER'], chrome_options=chrome_options, service_log_path="log", service_args=["--verbose"])
try:
print(driver.current_url)
result = wait_for_element_id_content(driver, 'result', 'success')
print(result)
finally:
import platform
if platform.system() == 'Windows':
subprocess.call(['taskkill', '/F', '/T', '/PID', str(server.pid)])
else:
server.terminate()
driver.quit()