Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lucky-ducks-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed an issue where the login button for Custom OAuth services would not work if any non-custom login service was also available
2 changes: 1 addition & 1 deletion apps/meteor/client/startup/customOAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Meteor.startup(() => {
loginServices.onLoad((services) => {
for (const service of services) {
if (!('custom' in service && service.custom)) {
return;
continue;
}

new CustomOAuth(service.service, {
Expand Down
3 changes: 3 additions & 0 deletions apps/meteor/tests/e2e/config/global-setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import addCustomOAuth from '../fixtures/addCustomOAuth';
import injectInitialData from '../fixtures/inject-initial-data';
import insertApp from '../fixtures/insert-apps';

export default async function (): Promise<void> {
await injectInitialData();

await insertApp();

await addCustomOAuth();
}
18 changes: 18 additions & 0 deletions apps/meteor/tests/e2e/fixtures/addCustomOAuth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { request } from '@playwright/test';

import { BASE_API_URL } from '../config/constants';
import { Users } from './userStates';

export default async function addCustomOAuth(): Promise<void> {
const api = await request.newContext();

const headers = {
'X-Auth-Token': Users.admin.data.loginToken,
'X-User-Id': Users.admin.data.username,
};

await api.post(`${BASE_API_URL}/settings.addCustomOAuth`, { data: { name: 'Test' }, headers });
await api.post(`${BASE_API_URL}/settings/Accounts_OAuth_Custom-Test`, { data: { value: false }, headers });
await api.post(`${BASE_API_URL}/settings/Accounts_OAuth_Custom-Test-url`, { data: { value: 'https://rocket.chat' }, headers });
await api.post(`${BASE_API_URL}/settings/Accounts_OAuth_Custom-Test-login_style`, { data: { value: 'redirect' }, headers });
}
21 changes: 21 additions & 0 deletions apps/meteor/tests/e2e/oauth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,33 @@ test.describe('OAuth', () => {
await expect(poRegistration.btnLoginWithGoogle).toBeVisible();
});

await test.step('expect Custom OAuth button to be visible', async () => {
await expect((await setSettingValueById(api, 'Accounts_OAuth_Custom-Test', true)).status()).toBe(200);
await page.waitForTimeout(5000);
await page.goto('/home');

await expect(poRegistration.btnLoginWithCustomOAuth).toBeVisible();
});

await test.step('expect redirect to the configured URL.', async () => {
await poRegistration.btnLoginWithCustomOAuth.click();
await expect(page).toHaveURL(/https\:\/\/(www)?\.rocket\.chat/);
});

await test.step('expect OAuth button to not be visible', async () => {
await expect((await setSettingValueById(api, 'Accounts_OAuth_Google', false)).status()).toBe(200);
await page.waitForTimeout(5000);

await page.goto('/home');
await expect(poRegistration.btnLoginWithGoogle).not.toBeVisible();
});

await test.step('expect Custom OAuth button to not be visible', async () => {
await expect((await setSettingValueById(api, 'Accounts_OAuth_Custom-Test', false)).status()).toBe(200);
await page.waitForTimeout(5000);

await page.goto('/home');
await expect(poRegistration.btnLoginWithCustomOAuth).not.toBeVisible();
});
});
});
4 changes: 4 additions & 0 deletions apps/meteor/tests/e2e/page-objects/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export class Registration {
return this.page.locator('role=button[name="Sign in with Google"]');
}

get btnLoginWithCustomOAuth(): Locator {
return this.page.locator('role=button[name="Sign in with Test"]');
}

get goToRegister(): Locator {
return this.page.locator('role=link[name="Create an account"]');
}
Expand Down