Skip to content

Commit

Permalink
test: add integration testing (#40)
Browse files Browse the repository at this point in the history
* test: add integration testing

* refactor: rename test folder to tests for consistency

* ci: use new test path

---------

Co-authored-by: ni-jessica <[email protected]>
  • Loading branch information
csirianni and ni-jessica authored Dec 9, 2023
1 parent b9d8751 commit 5bbe0e8
Show file tree
Hide file tree
Showing 11 changed files with 1,518 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:

- name: Run tests
working-directory: ${{github.workspace}}/backend/build
run: ./test/pdl_test
run: ./tests/pdl_test
2 changes: 1 addition & 1 deletion backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.27)
project(pdl LANGUAGES CXX)

add_subdirectory("src")
add_subdirectory("test")
add_subdirectory("tests")

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD_20)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 5bbe0e8

Please sign in to comment.