Skip to content

Commit

Permalink
Minor reformatting and commenting for test script.
Browse files Browse the repository at this point in the history
  • Loading branch information
00Fjongl committed Jul 11, 2024
1 parent 8e32436 commit 74b033d
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
const axios = require("axios");
const puppeteer = require("puppeteer");

async function testEndpoint(url) {
const testEndpoint = async url => {
try {
const response = await axios.get(url);
return response.status === 200;
} catch (error) {
console.error(`Error while testing ${url}:`, error.message);
return false;
}
}
};

async function testGeneratedUrl(url, headers) {
const testGeneratedUrl = async (url, headers) => {
try {
console.log(`Testing generated URL: ${url}`);

Expand All @@ -22,9 +22,9 @@ async function testGeneratedUrl(url, headers) {
console.error(`Error while testing generated URL ${url}:`, error.message);
return false;
}
}
};

async function testServerResponse() {
const testServerResponse = async () => {
const endpoints = [
"http://localhost:8080/",
"http://localhost:8080/?pathtonowhere",
Expand All @@ -45,9 +45,9 @@ async function testServerResponse() {
);
process.exit(1);
}
}
};

async function testCommonJSOnPage() {
const testCommonJSOnPage = async () => {
const browser = await puppeteer.launch({
args: [
"--enable-features=NetworkService",
Expand All @@ -60,16 +60,16 @@ async function testCommonJSOnPage() {
const page = await browser.newPage();

try {
async function getHeaders() {
const getHeaders = async () => {
const headers = {};

headers["User-Agent"] = await page.evaluate(() => navigator.userAgent);
headers["Referer"] = await page.evaluate(() => window.location.href);

return headers;
}
};

async function testRammerhead() {
const testRammerhead = async () => {
await page.goto("http://localhost:8080/?rh");

const testResults = await page.evaluate(async () => {
Expand Down Expand Up @@ -115,7 +115,7 @@ async function testCommonJSOnPage() {
);

return rammerheadTestPassed;
}
};

/*
Expand Down Expand Up @@ -155,7 +155,7 @@ xx xx



async function testUltraviolet() {
const testUltraviolet = async () => {
await page.goto("http://localhost:8080/?q");

const testResults = await page.evaluate(async () => {
Expand All @@ -179,10 +179,15 @@ xx xx
});

if (window.goProx && window.goProx.ultraviolet) {
// For the hacky URL test, use the URL page's EXACT title.
const website = {
path: "example.com",
title: "Example Domain"
};

try {
// For the hacky URL test, keep this as example.com.
const generatedUrl = window.goProx.ultraviolet(
"example.com",
website.path,
false
);
console.log("Generated Ultraviolet URL:", generatedUrl);
Expand All @@ -193,13 +198,15 @@ xx xx
const testGeneratedUrlHacky = async (url) => {
let result = false;
const exampleIFrame = document.createElement("iframe");
const waitForDocument = new Promise(resolve => exampleIFrame.addEventListener("load", () => {
result = exampleIFrame.contentWindow.document.title === "Example Domain";
const waitForDocument = new Promise(resolve => {
document.documentElement.appendChild(exampleIFrame);
exampleIFrame.addEventListener("load", () => {
result = exampleIFrame.contentWindow.document.title === website.title;
resolve();
}));
});
});
exampleIFrame.src = url;
exampleIFrame.style.display = "none";
document.documentElement.appendChild(exampleIFrame);
await waitForDocument;
return result;
};
Expand Down Expand Up @@ -227,7 +234,7 @@ xx xx
console.log(`Ultraviolet test result: failure`);
return false;
}
}
};

// Run tests for Rammerhead and Ultraviolet
const rammerheadPassed = await testRammerhead();
Expand All @@ -246,6 +253,6 @@ xx xx
} finally {
await browser.close();
}
}
};

testServerResponse();

0 comments on commit 74b033d

Please sign in to comment.