test.mjs 768 B

123456789101112131415161718192021222324252627282930313233
  1. async function testWithUserAgent(userAgent) {
  2. const statusCode = await fetch(
  3. "https://relayd.local.cetacean.club:3004/reqmeta",
  4. {
  5. headers: {
  6. "User-Agent": userAgent,
  7. },
  8. },
  9. ).then((resp) => resp.status);
  10. return statusCode;
  11. }
  12. const codes = {
  13. allow: await testWithUserAgent("ALLOW"),
  14. challenge: await testWithUserAgent("CHALLENGE"),
  15. deny: await testWithUserAgent("DENY"),
  16. };
  17. const expected = {
  18. allow: 200,
  19. challenge: 401,
  20. deny: 403,
  21. };
  22. console.log("ALLOW: ", codes.allow);
  23. console.log("CHALLENGE:", codes.challenge);
  24. console.log("DENY: ", codes.deny);
  25. if (JSON.stringify(codes) !== JSON.stringify(expected)) {
  26. throw new Error(
  27. `wanted ${JSON.stringify(expected)}, got: ${JSON.stringify(codes)}`,
  28. );
  29. }