-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(auth): implemented NextAuth with dummy provider
- Loading branch information
Showing
21 changed files
with
1,285 additions
and
999 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Created on Sun Oct 29 2023 | ||
* Author: Connor Doman | ||
*/ | ||
|
||
import { extractConfigFile } from "@lib/config"; | ||
|
||
describe("Config Library Tests", () => { | ||
it("extractConfigFile works for valid config file", async () => { | ||
const config = await extractConfigFile("extractConfigFile.test.json", "./__tests__/test-configs"); | ||
expect(config).toEqual({ | ||
tests: [ | ||
{ | ||
id: 1, | ||
name: "Test Extract Config File", | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it("extractConfigFile works for invalid config file", async () => { | ||
const config = await extractConfigFile("invalidConfigFile.test.json", "./__tests__/test-configs"); | ||
expect(config).toEqual({}); | ||
}); | ||
|
||
it("extractConfigFile works for non-existent config file", async () => { | ||
const config = await extractConfigFile("nonExistentConfigFile.test.json", "./__tests__/test-configs"); | ||
expect(config).toEqual({}); | ||
}); | ||
|
||
it("extractConfigFile works for non-existent config directory", async () => { | ||
const config = await extractConfigFile("nonExistentConfigFile.test.json", "./__tests__/non-existent-dir"); | ||
expect(config).toEqual({}); | ||
}); | ||
}); |
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,41 @@ | ||
/* | ||
* Created on Sun Oct 29 2023 | ||
* Author: Connor Doman | ||
*/ | ||
|
||
import { extractConfigFile } from "@lib/config"; | ||
import { DummyAuthenticator } from "@lib/dummy-authenticator"; | ||
|
||
describe("Dummy Authenticator", () => { | ||
it("works for valid credentials", async () => { | ||
const dummyAuthenticator = new DummyAuthenticator(); | ||
const credentials = { email: "johnny@example.com", password: "password" }; | ||
DummyAuthenticator.configDirectory = "./conf/"; | ||
const user = await dummyAuthenticator.authorize(credentials, {} as any); | ||
expect(user).toEqual({ | ||
id: "1", | ||
email: "johnny@example.com", | ||
}); | ||
}); | ||
|
||
it("fails for invalid credentials", async () => { | ||
const dummyAuthenticator = new DummyAuthenticator(); | ||
const credentials = { email: "johnny@example.com", password: "wrongpassword" }; | ||
DummyAuthenticator.configDirectory = "./conf/"; | ||
const user = await dummyAuthenticator.authorize(credentials, {} as any); | ||
expect(user).toEqual(null); | ||
}); | ||
|
||
it("contains 'credentials' profile name", () => { | ||
const dummyAuthenticator = new DummyAuthenticator(); | ||
expect(dummyAuthenticator.name).toEqual("credentials"); | ||
}); | ||
|
||
it("contains correct credentials profile", () => { | ||
const dummyAuthenticator = new DummyAuthenticator(); | ||
expect(dummyAuthenticator.credentials).toEqual({ | ||
email: { label: "Email", type: "text", placeholder: "Email" }, | ||
password: { label: "Password", type: "password" }, | ||
}); | ||
}); | ||
}); |
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
8 changes: 8 additions & 0 deletions
8
app/front-end/__tests__/test-configs/extractConfigFile.test.json
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,8 @@ | ||
{ | ||
"tests": [ | ||
{ | ||
"id": 1, | ||
"name": "Test Extract Config File" | ||
} | ||
] | ||
} |
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,25 @@ | ||
# PrivacyPal Configuration | ||
|
||
## Users | ||
|
||
User data for basic authentication is stored in `./user.properties.json` in the form of: | ||
|
||
```typescript | ||
interface PrivacyPalUser { | ||
id: string; | ||
email: string; | ||
password: string; | ||
} | ||
|
||
interface PrivacyPalUserProperties { | ||
users: PrivacyPalUser[]; | ||
} | ||
``` | ||
|
||
Where `password` is a base64 encoded `bcrypt` hash of the user's password: | ||
|
||
```typescript | ||
const password = btoa(await bcrypt.hash(userPassword, 10)); | ||
``` | ||
|
||
The sample file features a user with the email `johnny@example.com` and password `password`. |
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,9 @@ | ||
{ | ||
"users": [ | ||
{ | ||
"id": "1", | ||
"email": "johnny@example.com", | ||
"hashedPassword": "JDJiJDEwJDQwR0psSWo3Q08zcEhTVkpTVTNhbU9QQmZlYWl1dk1SL2dTMlZCclAuOGIuMjdiZFJTYjVp" | ||
} | ||
] | ||
} |
Oops, something went wrong.