Skip to content

Commit

Permalink
test: add integration testing
Browse files Browse the repository at this point in the history
run server and run yarn run v1.22.19
$ jest psi.test.ts -t 'testing expected server response'
  console.error
    Error fetching data: FetchError {
      message: 'request to http://localhost:18080/breachedPasswords failed, reason: connect ECONNREFUSED 127.0.0.1:18080',
      type: 'system',
      errno: 'ECONNREFUSED',
      code: 'ECONNREFUSED'
    }

      79 |         }
      80 |     } catch (error) {
    > 81 |         console.error("Error fetching data:", error);
         |                 ^
      82 |         return { status: "error" };
      83 |     }
      84 | }

      at app/psi.ts:81:17
      at step (app/psi.ts:33:23)
      at Object.throw (app/psi.ts:14:53)
      at rejected (app/psi.ts:6:65)

  console.error
    Error fetching data: FetchError {
      message: 'request to http://localhost:18080/breachedPasswords failed, reason: connect ECONNREFUSED 127.0.0.1:18080',
      type: 'system',
      errno: 'ECONNREFUSED',
      code: 'ECONNREFUSED'
    }

      79 |         }
      80 |     } catch (error) {
    > 81 |         console.error("Error fetching data:", error);
         |                 ^
      82 |         return { status: "error" };
      83 |     }
      84 | }

      at app/psi.ts:81:17
      at step (app/psi.ts:33:23)
      at Object.throw (app/psi.ts:14:53)
      at rejected (app/psi.ts:6:65)

info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. from frontend
  • Loading branch information
ni-jessica committed Dec 8, 2023
1 parent 4368acd commit a8c51ba
Show file tree
Hide file tree
Showing 4 changed files with 1,516 additions and 46 deletions.
1 change: 1 addition & 0 deletions frontend/app/psi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { base64 } from "rfc4648";

const sodium = require("libsodium-wrappers-sumo");
const fetch = require("node-fetch");

type ServerResponse = {
userPassword: string;
Expand Down
9 changes: 6 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"test": "jest psi.test.ts",
"test:integration": "jest psi.test.ts -t 'testing expected server response' "
},
"dependencies": {
"@emotion/react": "^11.11.1",
Expand All @@ -15,7 +17,7 @@
"@mui/material": "^5.14.12",
"libsodium-wrappers-sumo": "^0.7.13",
"next": "^13.5.4",
"node-fetch": "^2.6.7",
"node-fetch": "2",
"react": "^18",
"react-dom": "^18",
"react-password-checklist": "^1.5.0",
Expand All @@ -25,12 +27,13 @@
"@types/jest": "^29.5.10",
"@types/libsodium-wrappers-sumo": "^0.7.8",
"@types/node": "^20",
"@types/node-fetch": "^2.6.7",
"@types/node-fetch": "^2.6.9",
"@types/react": "^18",
"@types/react-dom": "^18",
"autoprefixer": "^10",
"eslint": "^8",
"eslint-config-next": "13.5.4",
"jest": "^29.7.0",
"postcss": "^8",
"tailwindcss": "^3",
"ts-jest": "^29.1.1",
Expand Down
30 changes: 23 additions & 7 deletions frontend/tests/psi.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applySeed, hashToPoint } from "../app/psi";
import { applySeed, hashToPoint, checkSecurity } from "../app/psi";
const sodium = require("libsodium-wrappers-sumo");

beforeAll(async () => {
Expand All @@ -14,12 +14,28 @@ describe("testing applySeed", () => {
// apply the seed
const [seededPassword, seedInverse] = applySeed(password);
// apply the inverse to the seeded password
const inversedSeededPassword = sodium.crypto_scalarmult_ristretto255(
seedInverse,
seededPassword
);

const inversedSeededPassword =
sodium.crypto_scalarmult_ristretto255(
seedInverse,
seededPassword
);

// check that the seeded+inversed password is the same as the hashed password
expect(Buffer.compare(inversedSeededPassword, hashedPassword)).toBe(0);
expect(
Buffer.compare(inversedSeededPassword, hashedPassword)
).toBe(0);
});
});

describe("testing expected server response", () => {
test("sending breached password should return fail status", async () => {
const password = "TestPass1&";
const response = await checkSecurity(password);
expect(response.status).toBe("fail");
});
test("sending non-breach password should return success status", async () => {
const password = "NiniIsTheBest!4";
const response = await checkSecurity(password);
expect(response.status).toBe("success");
});
});
Loading

0 comments on commit a8c51ba

Please sign in to comment.