forked from sinamics/ztnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
72 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ describe("organization api validation", () => { | |
.mockResolvedValue({ id: "newUserId", name: "Ztnet", email: "[email protected]" }); | ||
|
||
mockRequest.headers["x-ztnet-auth"] = "not valid token"; | ||
mockRequest.query = {}; | ||
|
||
await GET_userOrganization( | ||
mockRequest as NextApiRequest, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
import createUserHandler, { POST_createUser } from "~/pages/api/v1/user"; | ||
import createUserHandler from "~/pages/api/v1/user"; | ||
import { prisma } from "~/server/db"; | ||
import { appRouter } from "~/server/api/root"; | ||
import { API_TOKEN_SECRET, encrypt, generateInstanceSecret } from "~/utils/encryption"; | ||
|
@@ -18,7 +18,12 @@ jest.mock("~/server/api/root", () => ({ | |
})), | ||
}, | ||
})); | ||
|
||
jest.mock("~/utils/rateLimit", () => ({ | ||
__esModule: true, | ||
default: () => ({ | ||
check: jest.fn().mockResolvedValue(true), | ||
}), | ||
})); | ||
jest.mock("~/server/api/trpc"); | ||
|
||
jest.mock("~/server/db", () => ({ | ||
|
@@ -126,9 +131,19 @@ describe("createUserHandler", () => { | |
}), | ||
})); | ||
|
||
mockRequest.method = "POST"; | ||
mockRequest.headers["x-ztnet-auth"] = "not defined"; | ||
mockRequest.body = { | ||
email: "[email protected]", | ||
password: "password123", | ||
name: "Ztnet", | ||
}; | ||
|
||
await createUserHandler( | ||
mockRequest as NextApiRequest, | ||
mockResponse as NextApiResponse, | ||
); | ||
|
||
await POST_createUser(mockRequest as NextApiRequest, mockResponse as NextApiResponse); | ||
expect(mockResponse.status).toHaveBeenCalledWith(200); | ||
|
||
// Check if the response is as expected | ||
|
@@ -166,6 +181,7 @@ describe("createUserHandler", () => { | |
method: "POST", | ||
headers: { "x-ztnet-auth": tokenWithIdHash }, | ||
body: { email: "[email protected]", password: "password123", name: "Test User" }, | ||
query: {}, | ||
} as unknown as NextApiRequest; | ||
|
||
const res = { | ||
|
@@ -208,7 +224,9 @@ describe("createUserHandler", () => { | |
|
||
it("should allow only POST method", async () => { | ||
const methods = ["GET", "PUT", "DELETE", "PATCH", "OPTIONS", "HEAD"]; | ||
const req = {} as NextApiRequest; | ||
const req = { | ||
query: {}, | ||
} as NextApiRequest; | ||
const res = createMockRes(); | ||
|
||
for (const method of methods) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { z } from "zod"; | ||
|
||
// This regular expression (regex) is used to validate a password based on the following criteria: | ||
// - The password must be at least 6 characters long. | ||
// - The password must contain at least two of the following three character types: | ||
// - Lowercase letters (a-z) | ||
// - Uppercase letters (A-Z) | ||
// - Digits (0-9) | ||
export const mediumPassword = new RegExp( | ||
"^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})", | ||
); | ||
|
||
// create a zod password schema | ||
export const passwordSchema = (errorMessage: string) => | ||
z | ||
.string() | ||
.max(40, { message: "Password must not exceed 40 characters" }) | ||
.refine((val) => mediumPassword.test(val), { | ||
message: errorMessage, | ||
}) | ||
.optional(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters