diff --git a/.changeset/lucky-ducks-join.md b/.changeset/lucky-ducks-join.md new file mode 100644 index 0000000000000..e64661b0841b0 --- /dev/null +++ b/.changeset/lucky-ducks-join.md @@ -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 diff --git a/apps/meteor/client/startup/customOAuth.ts b/apps/meteor/client/startup/customOAuth.ts index 1b9060f84e3a7..5796814444cfc 100644 --- a/apps/meteor/client/startup/customOAuth.ts +++ b/apps/meteor/client/startup/customOAuth.ts @@ -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, { diff --git a/apps/meteor/tests/e2e/config/global-setup.ts b/apps/meteor/tests/e2e/config/global-setup.ts index 6e2d750d59385..d273ffc831080 100644 --- a/apps/meteor/tests/e2e/config/global-setup.ts +++ b/apps/meteor/tests/e2e/config/global-setup.ts @@ -1,3 +1,4 @@ +import addCustomOAuth from '../fixtures/addCustomOAuth'; import injectInitialData from '../fixtures/inject-initial-data'; import insertApp from '../fixtures/insert-apps'; @@ -5,4 +6,6 @@ export default async function (): Promise { await injectInitialData(); await insertApp(); + + await addCustomOAuth(); } diff --git a/apps/meteor/tests/e2e/fixtures/addCustomOAuth.ts b/apps/meteor/tests/e2e/fixtures/addCustomOAuth.ts new file mode 100644 index 0000000000000..10a80a7710a9e --- /dev/null +++ b/apps/meteor/tests/e2e/fixtures/addCustomOAuth.ts @@ -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 { + 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 }); +} diff --git a/apps/meteor/tests/e2e/oauth.spec.ts b/apps/meteor/tests/e2e/oauth.spec.ts index 8d53fa9503b43..c93dc5a4f7dbe 100644 --- a/apps/meteor/tests/e2e/oauth.spec.ts +++ b/apps/meteor/tests/e2e/oauth.spec.ts @@ -19,6 +19,19 @@ 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); @@ -26,5 +39,13 @@ test.describe('OAuth', () => { 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(); + }); }); }); diff --git a/apps/meteor/tests/e2e/page-objects/auth.ts b/apps/meteor/tests/e2e/page-objects/auth.ts index 51290d46f9ccb..8d5fe1edad20b 100644 --- a/apps/meteor/tests/e2e/page-objects/auth.ts +++ b/apps/meteor/tests/e2e/page-objects/auth.ts @@ -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"]'); }