Feat(authentication): username password provider (#6052)

This commit is contained in:
Philip Korsholm
2024-01-23 09:04:22 +00:00
committed by GitHub
parent 9d7ed9dbaf
commit 24bb26b81a
20 changed files with 424 additions and 44 deletions
@@ -237,6 +237,7 @@ describe("AuthenticationModuleService - AuthUser", () => {
{
id: "test",
provider_id: "manual",
entity_id: "test"
},
])
@@ -5,6 +5,7 @@ import { initialize } from "../../../../src"
import { DB_URL } from "@medusajs/pricing/integration-tests/utils"
import { MedusaModule } from "@medusajs/modules-sdk"
import { IAuthenticationModuleService } from "@medusajs/types"
import { createAuthProviders } from "../../../__fixtures__/auth-provider"
jest.setTimeout(30000)
@@ -22,6 +23,10 @@ describe("AuthenticationModuleService - AuthProvider", () => {
schema: process.env.MEDUSA_PRICING_DB_SCHEMA,
},
})
if(service.__hooks?.onApplicationStart) {
await service.__hooks.onApplicationStart()
}
})
afterEach(async () => {
@@ -30,7 +35,7 @@ describe("AuthenticationModuleService - AuthProvider", () => {
})
describe("listAuthProviders", () => {
it("should list default AuthProviders", async () => {
it("should list default AuthProviders registered by loaders", async () => {
const authProviders = await service.listAuthProviders()
const serialized = JSON.parse(JSON.stringify(authProviders))
@@ -42,4 +47,22 @@ describe("AuthenticationModuleService - AuthProvider", () => {
])
})
})
describe("authenticate", () => {
it("authenticate validates that a provider is registered in container", async () => {
await createAuthProviders(testManager, [
{
provider: "notRegistered",
name: "test",
},
])
const { success, error } = await service.authenticate("notRegistered", {})
expect(success).toBe(false)
expect(error).toEqual(
"AuthenticationProvider with for provider: notRegistered wasn't registered in the module. Have you configured your options correctly?"
)
})
})
})