All files / src/test-routes error-with-secrets.ts

0% Statements 0/9
100% Branches 0/0
0% Functions 0/3
0% Lines 0/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 47 48 49 50 51 52 53 54 55 56 57                                                                                                                 
import { app, json } from "../api";
 
app.category("vanilla", () => {
  // Returns an error response with secrets and PII in the headers and body.
  app.get("/secrets/error", "ErrorWithSecrets", (req) => {
    return {
      status: 403,
      testSuccessful: true,
      headers: {
        // Following headers should be redacted.
        "x-ms-pii": "true",
 
        // Following headers should not be redacted.
        "x-ms-request-id": "5e123516-834e-4222-9e80-353108d33357",
        "x-ms-version": "2022-02-01",
      },
      body: json({
        error: {
          code: "Unauthorized",
          message: "The user 'user@contoso.com' is unauthorized.",
          details: [
            {
              code: "UnauthorizedSharedKey",
              innererror: "Shared key 1c88a67921784300a462b2cb61da2339 is not permitted access.",
            },
          ],
          token: "1c88a67921784300a462b2cb61da2339",
        },
        primaryKey: "1c88a67921784300a462b2cb61da2339",
        connectionString: "Key1=1c88a67921784300a462b2cb61da2339",
      }),
    };
  });
 
  app.post("/secrets/[:]create", "RequestWithSecrets", (req) => {
    req.expect.containsHeader("authorization", "SharedKey 1c88a67921784300a462b2cb61da2339");
    req.expect.containsQueryParam("key", "1c88a67921784300a462b2cb61da2339");
    req.expect.bodyEquals({ key: "1c88a67921784300a462b2cb61da2339" });
 
    return {
      status: 200,
      headers: {
        // Following headers should be redacted.
        "x-ms-pii": "true",
 
        // Following headers should not be redacted.
        "x-ms-request-id": "49997f20-3cee-4c0c-92ff-572acbbed13d",
        "x-ms-version": "2022-02-01",
      },
      body: json({
        key: "1c88a67921784300a462b2cb61da2339",
        value: "secret",
      }),
    };
  });
});