Browse Source

更新测试用例

Pchen0 3 hours ago
parent
commit
4efde31d6b
1 changed files with 31 additions and 0 deletions
  1. 31 0
      scripts/proxy-u-xxoo365-test.js

+ 31 - 0
scripts/proxy-u-xxoo365-test.js

@@ -23,6 +23,8 @@ const axios = require('axios')
 const HttpsProxyAgent = require('https-proxy-agent')
 const HttpsProxyAgent = require('https-proxy-agent')
 
 
 const QG_GET_URL = 'https://share.proxy.qg.net/get'
 const QG_GET_URL = 'https://share.proxy.qg.net/get'
+const DEFAULT_BROWSER_UA =
+    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36'
 
 
 function readConfig() {
 function readConfig() {
     const cfgPath = path.join(__dirname, '..', 'config.json')
     const cfgPath = path.join(__dirname, '..', 'config.json')
@@ -43,6 +45,33 @@ function normalizeMethod() {
     return m === 'HEAD' ? 'HEAD' : 'GET'
     return m === 'HEAD' ? 'HEAD' : 'GET'
 }
 }
 
 
+function buildBrowserHeaders(url, method) {
+    const u = new URL(url)
+    const ua = String(process.env.TEST_UA || DEFAULT_BROWSER_UA).trim()
+    const acceptLang = String(process.env.TEST_ACCEPT_LANGUAGE || 'zh-CN,zh;q=0.9,en;q=0.8').trim()
+    const accept =
+        method === 'HEAD'
+            ? String(process.env.TEST_ACCEPT || '*/*').trim()
+            : String(
+                  process.env.TEST_ACCEPT ||
+                      'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8'
+              ).trim()
+    return {
+        Accept: accept,
+        'Accept-Language': acceptLang,
+        'Cache-Control': 'no-cache',
+        Pragma: 'no-cache',
+        DNT: '1',
+        'Sec-Fetch-Dest': 'document',
+        'Sec-Fetch-Mode': 'navigate',
+        'Sec-Fetch-Site': 'none',
+        'Sec-Fetch-User': '?1',
+        'Upgrade-Insecure-Requests': '1',
+        'User-Agent': ua,
+        Referer: String(process.env.TEST_REFERER || `${u.origin}/`).trim()
+    }
+}
+
 function toProxyUrl(server, user, pass) {
 function toProxyUrl(server, user, pass) {
     const [host, portRaw] = String(server || '').trim().split(':')
     const [host, portRaw] = String(server || '').trim().split(':')
     const port = Number(portRaw)
     const port = Number(portRaw)
@@ -94,6 +123,7 @@ async function probe(label, requestConfig) {
     const timeout = Number(process.env.TEST_TIMEOUT_MS || 20000)
     const timeout = Number(process.env.TEST_TIMEOUT_MS || 20000)
     const url = buildTargetUrl()
     const url = buildTargetUrl()
     const method = normalizeMethod()
     const method = normalizeMethod()
+    const headers = buildBrowserHeaders(url, method)
     const t0 = Date.now()
     const t0 = Date.now()
     console.log(`\n=== ${label} ===`)
     console.log(`\n=== ${label} ===`)
     console.log('REQUEST:', method, url)
     console.log('REQUEST:', method, url)
@@ -104,6 +134,7 @@ async function probe(label, requestConfig) {
             method,
             method,
             timeout,
             timeout,
             validateStatus: () => true,
             validateStatus: () => true,
+            headers,
             ...requestConfig
             ...requestConfig
         })
         })
         const ms = Date.now() - t0
         const ms = Date.now() - t0