Skip to content

Commit

Permalink
fix: "Allow Password Change for OAuth Users" setting is not honored i…
Browse files Browse the repository at this point in the history
…n the "Forgot Password" flow (#32398)
  • Loading branch information
matheusbsilva137 authored May 20, 2024
1 parent 61e31aa commit 6ac3607
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 4 deletions.
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 } });

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: ['[email protected]'] }),
});
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: ['[email protected]'] }),
});
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

0 comments on commit 6ac3607

Please sign in to comment.