fix: Users should not be redirected to disabled authentication providers (#5055

* fix: Users should not be redirected to disabled authentication providers
Re-enabled tests in plugin directory

* Fix plugin http tests
This commit is contained in:
Tom Moor
2023-03-18 09:17:54 -04:00
committed by GitHub
parent 6dd4afccaf
commit 41f97b0563
7 changed files with 60 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ import sharedEnv from "@shared/env";
import SigninEmail from "@server/emails/templates/SigninEmail";
import WelcomeEmail from "@server/emails/templates/WelcomeEmail";
import env from "@server/env";
import { AuthenticationProvider } from "@server/models";
import { buildUser, buildGuestUser, buildTeam } from "@server/test/factories";
import { getTestServer } from "@server/test/support";
@@ -33,6 +34,42 @@ describe("email", () => {
spy.mockRestore();
});
it("should respond with success and email to be sent when user has SSO but disabled", async () => {
const spy = jest.spyOn(SigninEmail, "schedule");
const team = await buildTeam({
subdomain: "example",
});
const user = await buildUser({
teamId: team.id,
});
// Disable all the auth providers
await AuthenticationProvider.update(
{
enabled: false,
},
{
where: {
enabled: true,
},
}
);
const res = await server.post("/auth/email", {
body: {
email: user.email,
},
headers: {
host: "example.localoutline.com",
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.success).toEqual(true);
expect(spy).toHaveBeenCalled();
spy.mockRestore();
});
it("should not send email when user is on another subdomain but respond with success", async () => {
env.URL = sharedEnv.URL = "http://localoutline.com";
env.SUBDOMAINS_ENABLED = sharedEnv.SUBDOMAINS_ENABLED = true;