mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-13 12:00:02 -04:00
Minor reformatting and commenting for test script.
This commit is contained in:
parent
8e3243670c
commit
74b033df30
1 changed files with 27 additions and 20 deletions
47
test.js
47
test.js
|
@ -1,7 +1,7 @@
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const puppeteer = require("puppeteer");
|
const puppeteer = require("puppeteer");
|
||||||
|
|
||||||
async function testEndpoint(url) {
|
const testEndpoint = async url => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(url);
|
const response = await axios.get(url);
|
||||||
return response.status === 200;
|
return response.status === 200;
|
||||||
|
@ -9,9 +9,9 @@ async function testEndpoint(url) {
|
||||||
console.error(`Error while testing ${url}:`, error.message);
|
console.error(`Error while testing ${url}:`, error.message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
async function testGeneratedUrl(url, headers) {
|
const testGeneratedUrl = async (url, headers) => {
|
||||||
try {
|
try {
|
||||||
console.log(`Testing generated URL: ${url}`);
|
console.log(`Testing generated URL: ${url}`);
|
||||||
|
|
||||||
|
@ -22,9 +22,9 @@ async function testGeneratedUrl(url, headers) {
|
||||||
console.error(`Error while testing generated URL ${url}:`, error.message);
|
console.error(`Error while testing generated URL ${url}:`, error.message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
async function testServerResponse() {
|
const testServerResponse = async () => {
|
||||||
const endpoints = [
|
const endpoints = [
|
||||||
"http://localhost:8080/",
|
"http://localhost:8080/",
|
||||||
"http://localhost:8080/?pathtonowhere",
|
"http://localhost:8080/?pathtonowhere",
|
||||||
|
@ -45,9 +45,9 @@ async function testServerResponse() {
|
||||||
);
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
async function testCommonJSOnPage() {
|
const testCommonJSOnPage = async () => {
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
args: [
|
args: [
|
||||||
"--enable-features=NetworkService",
|
"--enable-features=NetworkService",
|
||||||
|
@ -60,16 +60,16 @@ async function testCommonJSOnPage() {
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
async function getHeaders() {
|
const getHeaders = async () => {
|
||||||
const headers = {};
|
const headers = {};
|
||||||
|
|
||||||
headers["User-Agent"] = await page.evaluate(() => navigator.userAgent);
|
headers["User-Agent"] = await page.evaluate(() => navigator.userAgent);
|
||||||
headers["Referer"] = await page.evaluate(() => window.location.href);
|
headers["Referer"] = await page.evaluate(() => window.location.href);
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
};
|
||||||
|
|
||||||
async function testRammerhead() {
|
const testRammerhead = async () => {
|
||||||
await page.goto("http://localhost:8080/?rh");
|
await page.goto("http://localhost:8080/?rh");
|
||||||
|
|
||||||
const testResults = await page.evaluate(async () => {
|
const testResults = await page.evaluate(async () => {
|
||||||
|
@ -115,7 +115,7 @@ async function testCommonJSOnPage() {
|
||||||
);
|
);
|
||||||
|
|
||||||
return rammerheadTestPassed;
|
return rammerheadTestPassed;
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ xx xx
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function testUltraviolet() {
|
const testUltraviolet = async () => {
|
||||||
await page.goto("http://localhost:8080/?q");
|
await page.goto("http://localhost:8080/?q");
|
||||||
|
|
||||||
const testResults = await page.evaluate(async () => {
|
const testResults = await page.evaluate(async () => {
|
||||||
|
@ -179,10 +179,15 @@ xx xx
|
||||||
});
|
});
|
||||||
|
|
||||||
if (window.goProx && window.goProx.ultraviolet) {
|
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 {
|
try {
|
||||||
// For the hacky URL test, keep this as example.com.
|
|
||||||
const generatedUrl = window.goProx.ultraviolet(
|
const generatedUrl = window.goProx.ultraviolet(
|
||||||
"example.com",
|
website.path,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
console.log("Generated Ultraviolet URL:", generatedUrl);
|
console.log("Generated Ultraviolet URL:", generatedUrl);
|
||||||
|
@ -193,13 +198,15 @@ xx xx
|
||||||
const testGeneratedUrlHacky = async (url) => {
|
const testGeneratedUrlHacky = async (url) => {
|
||||||
let result = false;
|
let result = false;
|
||||||
const exampleIFrame = document.createElement("iframe");
|
const exampleIFrame = document.createElement("iframe");
|
||||||
const waitForDocument = new Promise(resolve => exampleIFrame.addEventListener("load", () => {
|
const waitForDocument = new Promise(resolve => {
|
||||||
result = exampleIFrame.contentWindow.document.title === "Example Domain";
|
document.documentElement.appendChild(exampleIFrame);
|
||||||
|
exampleIFrame.addEventListener("load", () => {
|
||||||
|
result = exampleIFrame.contentWindow.document.title === website.title;
|
||||||
resolve();
|
resolve();
|
||||||
}));
|
});
|
||||||
|
});
|
||||||
exampleIFrame.src = url;
|
exampleIFrame.src = url;
|
||||||
exampleIFrame.style.display = "none";
|
exampleIFrame.style.display = "none";
|
||||||
document.documentElement.appendChild(exampleIFrame);
|
|
||||||
await waitForDocument;
|
await waitForDocument;
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
@ -227,7 +234,7 @@ xx xx
|
||||||
console.log(`Ultraviolet test result: failure`);
|
console.log(`Ultraviolet test result: failure`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
// Run tests for Rammerhead and Ultraviolet
|
// Run tests for Rammerhead and Ultraviolet
|
||||||
const rammerheadPassed = await testRammerhead();
|
const rammerheadPassed = await testRammerhead();
|
||||||
|
@ -246,6 +253,6 @@ xx xx
|
||||||
} finally {
|
} finally {
|
||||||
await browser.close();
|
await browser.close();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
testServerResponse();
|
testServerResponse();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue