Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "Allow Password Change for OAuth Users" setting is not honored in the "Forgot Password" flow #32398

Merged
merged 8 commits into from
May 20, 2024
5 changes: 5 additions & 0 deletions .changeset/wise-pianos-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixed issue with external users being able to reset their passwords even when the "Allow Password Change for OAuth Users" setting is disabled
2 changes: 1 addition & 1 deletion apps/meteor/server/methods/sendForgotPasswordEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Meteor.methods<ServerMethods>({

const email = to.trim().toLowerCase();

const user = await Users.findOneByEmailAddress(email, { projection: { _id: 1 } });
const user = await Users.findOneByEmailAddress(email, { projection: { _id: 1, services: 1 } });
matheusbsilva137 marked this conversation as resolved.
Show resolved Hide resolved

if (!user) {
return true;
Expand Down
25 changes: 25 additions & 0 deletions apps/meteor/tests/e2e/saml.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Users } from './fixtures/userStates';
import { Registration } from './page-objects';
import { createCustomRole, deleteCustomRole } from './utils/custom-role';
import { getUserInfo } from './utils/getUserInfo';
import { parseMeteorResponse } from './utils/parseMeteorResponse';
import { setSettingValueById } from './utils/setSettingValueById';
import { test, expect, BaseTest } from './utils/test';

Expand Down Expand Up @@ -195,6 +196,30 @@ test.describe('SAML', () => {
});
});

test('Allow password change for OAuth users', async ({ api }) => {
await test.step("should not send password reset mail if 'Allow Password Change for OAuth Users' setting is disabled", async () => {
expect((await setSettingValueById(api, 'Accounts_AllowPasswordChangeForOAuthUsers', false)).status()).toBe(200);

const response = await api.post('/method.call/sendForgotPasswordEmail', {
message: JSON.stringify({ msg: 'method', id: 'id', method: 'sendForgotPasswordEmail', params: ['samluser1@example.com'] }),
});
const mailSent = await parseMeteorResponse<boolean>(response);
expect(response.status()).toBe(200);
expect(mailSent).toBe(false);
});

await test.step("should send password reset mail if 'Allow Password Change for OAuth Users' setting is enabled", async () => {
expect((await setSettingValueById(api, 'Accounts_AllowPasswordChangeForOAuthUsers', true)).status()).toBe(200);

const response = await api.post('/method.call/sendForgotPasswordEmail', {
message: JSON.stringify({ msg: 'method', id: 'id', method: 'sendForgotPasswordEmail', params: ['samluser1@example.com'] }),
});
const mailSent = await parseMeteorResponse<boolean>(response);
expect(response.status()).toBe(200);
expect(mailSent).toBe(true);
});
});

const doLoginStep = async (page: Page, username: string, redirectUrl: string | null = '/home') => {
await test.step('expect successful login', async () => {
await poRegistration.btnLoginWithSaml.click();
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/utils/omnichannel/monitors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseMeteorResponse } from '../parseMeteorResponse';
import { BaseTest } from '../test';
import { parseMeteorResponse } from './utils';

const removeMonitor = async (api: BaseTest['api'], id: string) =>
api.post('/method.call/livechat:removeMonitor', {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/utils/omnichannel/tags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ILivechatTag } from '@rocket.chat/core-typings';

import { parseMeteorResponse } from '../parseMeteorResponse';
import { BaseTest } from '../test';
import { parseMeteorResponse } from './utils';

type CreateTagParams = {
id?: string | null;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/utils/omnichannel/units.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { faker } from '@faker-js/faker';
import { IOmnichannelBusinessUnit } from '@rocket.chat/core-typings';

import { parseMeteorResponse } from '../parseMeteorResponse';
import { BaseTest } from '../test';
import { parseMeteorResponse } from './utils';

type CreateUnitParams = {
id?: string | null;
Expand Down
Loading