summaryrefslogtreecommitdiffstats
path: root/dom/credentialmanagement/identity/tests/mochitest/server_manifest.sjs
blob: 20d5aa058f392a01023fefbac99d1c41c9abd785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

Cu.importGlobalProperties(["URLSearchParams"]);

function handleRequest(request, response) {
  let params = new URLSearchParams(request.queryString);
  let test = params.get("set_test");
  if (test === null) {
    test = getState("test");
  } else {
    setState("test", test);
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setStatusLine(request.httpVersion, 200, "OK");
    return;
  }

  if (request.hasHeader("Cookie")) {
    response.setStatusLine(request.httpVersion, 400, "Bad Request");
    return;
  }
  if (request.hasHeader("Origin") && request.getHeader("Origin") != "null") {
    response.setStatusLine(request.httpVersion, 400, "Bad Request");
    return;
  }
  if (request.hasHeader("Referer")) {
    response.setStatusLine(request.httpVersion, 400, "Bad Request");
    return;
  }

  response.setHeader("Access-Control-Allow-Origin", "*");
  response.setHeader("Content-Type", "application/json");
  let content = {
    accounts_endpoint:
      "https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/server_TESTNAME_accounts.sjs",
    client_metadata_endpoint:
      "https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/server_metadata.json",
    id_assertion_endpoint:
      "https://example.net/tests/dom/credentialmanagement/identity/tests/mochitest/server_TESTNAME_idtoken.sjs",
  };
  let bodyFormat = JSON.stringify(content);
  let body = bodyFormat.replaceAll("TESTNAME", test);
  response.setStatusLine(request.httpVersion, 200, "OK");
  response.write(body);
}