updated test script

This commit is contained in:
QuiteAFancyEmerald 2024-07-10 18:44:49 -07:00
parent 13c2f6c6e7
commit a4c7d9f395
2 changed files with 64 additions and 35 deletions

View file

@ -27,7 +27,6 @@
"express": "^4.19.2", "express": "^4.19.2",
"helmet": "^7.1.0", "helmet": "^7.1.0",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"node-fetch": "^3.3.2",
"puppeteer": "^22.12.1", "puppeteer": "^22.12.1",
"rammerhead": "https://github.com/NebulaServices/rammerhead/releases/download/rammerhead-1.2.41-nebula.8/rammerhead-1.2.41-nebula.7.tgz", "rammerhead": "https://github.com/NebulaServices/rammerhead/releases/download/rammerhead-1.2.41-nebula.8/rammerhead-1.2.41-nebula.7.tgz",
"wisp-server-node": "^1.0.6", "wisp-server-node": "^1.0.6",

98
test.js
View file

@ -11,9 +11,14 @@ async function testEndpoint(url) {
} }
} }
async function testGeneratedUrl(url) { async function testGeneratedUrl(url, headers) {
try { try {
const response = await axios.get(url); console.log(`Testing generated URL: ${url}`);
// Make the Axios request with custom headers
const response = await axios.get(url, { headers });
console.log(`Response status for ${url}: ${response.status}`);
return response.status === 200; return response.status === 200;
} catch (error) { } catch (error) {
console.error(`Error while testing generated URL ${url}:`, error.message); console.error(`Error while testing generated URL ${url}:`, error.message);
@ -46,13 +51,28 @@ async function testServerResponse() {
async function testCommonJSOnPage() { async function testCommonJSOnPage() {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
args: ["--enable-features=NetworkService"], args: [
"--enable-features=NetworkService",
"--enable-features=ServiceWorker",
"--enable-features=InsecureOrigins",
],
headless: false, headless: false,
ignoreHTTPSErrors: true, ignoreHTTPSErrors: true,
}); });
const page = await browser.newPage(); const page = await browser.newPage();
try { try {
// Function to extract headers from the page context
async function getHeaders() {
const headers = {};
// Example: Extract headers dynamically from the page
headers['User-Agent'] = await page.evaluate(() => navigator.userAgent);
headers['Referer'] = await page.evaluate(() => window.location.href);
return headers;
}
// Function to test Rammerhead with "?rh" // Function to test Rammerhead with "?rh"
async function testRammerhead() { async function testRammerhead() {
await page.goto("http://localhost:8080/?rh"); await page.goto("http://localhost:8080/?rh");
@ -88,9 +108,10 @@ async function testCommonJSOnPage() {
console.log("Rammerhead test results:", testResults); console.log("Rammerhead test results:", testResults);
const headers = await getHeaders();
const rammerheadTestPassed = const rammerheadTestPassed =
testResults.rammerhead !== "failure" && testResults.rammerhead !== "failure" &&
(await testGeneratedUrl(testResults.rammerhead)); (await testGeneratedUrl(testResults.rammerhead, headers));
console.log( console.log(
`Rammerhead test result: ${ `Rammerhead test result: ${
@ -104,44 +125,53 @@ async function testCommonJSOnPage() {
async function testUltraviolet() { async function testUltraviolet() {
await page.goto("http://localhost:8080/?q"); await page.goto("http://localhost:8080/?q");
// Wait for the service worker to be active // Wait for the document's readyState to be complete
await page.waitForFunction( await page.waitForFunction(() => document.readyState === "complete");
() => navigator.serviceWorker.controller !== null
);
const testResults = await page.evaluate(async () => { // Evaluate the function to register the service worker
const results = {}; await page.evaluate(async () => {
const stockSW = "/uv/sw.js";
const swAllowedHostnames = ["localhost", "127.0.0.1"];
if (window.goProx && window.goProx.ultraviolet) { async function registerSW() {
try { if (!navigator.serviceWorker) {
const generatedUrl = await window.goProx.ultraviolet( if (
"example.com", location.protocol !== "https:" &&
false !swAllowedHostnames.includes(location.hostname)
); )
console.log("Generated Ultraviolet URL:", generatedUrl); throw new Error(
results.ultraviolet = generatedUrl ? generatedUrl : "failure"; "Service workers cannot be registered without https."
} catch (e) { );
results.ultraviolet = "failure: " + e.message;
throw new Error("Your browser doesn't support service workers.");
} }
} else {
results.goProx = "not defined"; await navigator.serviceWorker.register(stockSW);
let wispUrl =
(location.protocol === "https:" ? "wss" : "ws") +
"://" +
location.host +
"/wisp/";
await BareMux.SetTransport("EpxMod.EpoxyClient", { wisp: wispUrl });
// When testing proxy support, clear service workers from 8080 (or whatever current port you are using)
// navigator.serviceWorker.register(stockSW).then(register => register.unregister().then(bool => console.log("Unregistered: " + bool)));
} }
return results; await registerSW();
}); });
console.log("Ultraviolet test results:", testResults); // Test for the existence of /assets/js/register-sw.js
const swTestPassed = await testEndpoint("http://localhost:8080/assets/js/register-sw.js");
if (testResults.ultraviolet && testResults.ultraviolet !== "failure") { console.log(
const uvTestPassed = await testGeneratedUrl(testResults.ultraviolet); `Service Worker registration test result: ${
console.log( swTestPassed ? "success" : "failure"
`Ultraviolet test result: ${uvTestPassed ? "success" : "failure"}` }`
); );
return uvTestPassed;
} else { return swTestPassed;
console.log(`Ultraviolet test result: failure`);
return false;
}
} }
// Run tests for Rammerhead and Ultraviolet // Run tests for Rammerhead and Ultraviolet