mirror of
https://github.com/QuiteAFancyEmerald/Holy-Unblocker.git
synced 2025-05-14 04:20:00 -04:00
broken test script for u
This commit is contained in:
parent
2e17d5ace7
commit
fe11e628f6
2 changed files with 140 additions and 14 deletions
|
@ -29,6 +29,7 @@
|
||||||
"helmet": "^7.1.0",
|
"helmet": "^7.1.0",
|
||||||
"mime-types": "^2.1.35",
|
"mime-types": "^2.1.35",
|
||||||
"node-fetch": "^3.3.2",
|
"node-fetch": "^3.3.2",
|
||||||
|
"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.1.0",
|
"wisp-server-node": "^1.1.0",
|
||||||
"ws": "^8.18.0"
|
"ws": "^8.18.0"
|
||||||
|
|
153
test.js
153
test.js
|
@ -1,21 +1,146 @@
|
||||||
const axios = require("axios");
|
const axios = require('axios');
|
||||||
|
const puppeteer = require('puppeteer');
|
||||||
|
|
||||||
|
async function testEndpoint(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) {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(url);
|
||||||
|
return response.status === 200;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error while testing generated URL ${url}:`, error.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function testServerResponse() {
|
async function testServerResponse() {
|
||||||
try {
|
const endpoints = [
|
||||||
const response = await axios.get("http://localhost:8080/?pathtonowhere");
|
'http://localhost:8080/',
|
||||||
if (response.status === 200) {
|
'http://localhost:8080/?pathtonowhere',
|
||||||
console.log("Server responded with status code 200. Test passed.");
|
'http://localhost:8080/?browse',
|
||||||
process.exit(0); // Exit with success
|
'http://localhost:8080/?rh',
|
||||||
} else {
|
'http://localhost:8080/?q'
|
||||||
console.error(
|
];
|
||||||
`Expected status code 200 but received ${response.status}. Test failed.`
|
|
||||||
);
|
const results = await Promise.all(endpoints.map(testEndpoint));
|
||||||
process.exit(1); // Exit with failure
|
const allPassed = results.every(result => result);
|
||||||
}
|
|
||||||
} catch (error) {
|
if (allPassed) {
|
||||||
console.error("Error while testing server response:", error.message);
|
console.log('All endpoints responded with status code 200. Test passed.');
|
||||||
|
await testCommonJSOnPage();
|
||||||
|
} else {
|
||||||
|
console.error('One or more endpoints failed to respond with status code 200. Test failed.');
|
||||||
process.exit(1); // Exit with failure
|
process.exit(1); // Exit with failure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function testCommonJSOnPage() {
|
||||||
|
const browser = await puppeteer.launch({ headless: false });
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Function to test Rammerhead with "?rh"
|
||||||
|
async function testRammerhead() {
|
||||||
|
await page.goto('http://localhost:8080/?rh');
|
||||||
|
|
||||||
|
const testResults = await page.evaluate(async () => {
|
||||||
|
const results = {};
|
||||||
|
|
||||||
|
// Wait for the DOM content to be fully loaded and goProx to be available
|
||||||
|
await new Promise(resolve => {
|
||||||
|
if (document.readyState === 'complete') {
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
window.addEventListener('load', resolve);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (window.goProx) {
|
||||||
|
// Test rammerhead with google.com
|
||||||
|
try {
|
||||||
|
const rammerheadUrl = await window.goProx.rammerhead('google.com', false);
|
||||||
|
results.rammerhead = rammerheadUrl ? rammerheadUrl : 'failure';
|
||||||
|
} catch (e) {
|
||||||
|
results.rammerhead = 'failure: ' + e.message;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
results.goProx = 'not defined';
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Rammerhead test results:', testResults);
|
||||||
|
|
||||||
|
const rammerheadTestPassed = testResults.rammerhead !== 'failure' && await testGeneratedUrl(testResults.rammerhead);
|
||||||
|
|
||||||
|
console.log(`Rammerhead test result: ${rammerheadTestPassed ? 'success' : 'failure'}`);
|
||||||
|
|
||||||
|
return rammerheadTestPassed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to test Ultraviolet with "?q"
|
||||||
|
async function testUltraviolet() {
|
||||||
|
await page.goto('http://localhost:8080/?q');
|
||||||
|
|
||||||
|
const testResults = await page.evaluate(async () => {
|
||||||
|
const results = {};
|
||||||
|
|
||||||
|
// Wait for the DOM content to be fully loaded and goProx to be available
|
||||||
|
await new Promise(resolve => {
|
||||||
|
if (document.readyState === 'complete') {
|
||||||
|
resolve();
|
||||||
|
} else {
|
||||||
|
window.addEventListener('load', resolve);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (window.goProx) {
|
||||||
|
// Test ultraviolet with google.com
|
||||||
|
try {
|
||||||
|
const uvUrl = window.goProx.ultraviolet('google.com', false);
|
||||||
|
results.ultraviolet = uvUrl ? uvUrl : 'failure';
|
||||||
|
} catch (e) {
|
||||||
|
results.ultraviolet = 'failure: ' + e.message;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
results.goProx = 'not defined';
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Ultraviolet test results:', testResults);
|
||||||
|
|
||||||
|
const uvTestPassed = testResults.ultraviolet !== 'failure' && await testGeneratedUrl(testResults.ultraviolet);
|
||||||
|
|
||||||
|
console.log(`Ultraviolet test result: ${uvTestPassed ? 'success' : 'failure'}`);
|
||||||
|
|
||||||
|
return uvTestPassed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run tests for Rammerhead and Ultraviolet
|
||||||
|
const rammerheadPassed = await testRammerhead();
|
||||||
|
const ultravioletPassed = await testUltraviolet();
|
||||||
|
|
||||||
|
if (rammerheadPassed && ultravioletPassed) {
|
||||||
|
console.log('Both tests passed.');
|
||||||
|
} else {
|
||||||
|
console.error('Tests failed.');
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error in testCommonJSOnPage:', error.message);
|
||||||
|
} finally {
|
||||||
|
await browser.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
testServerResponse();
|
testServerResponse();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue