From f8f92f823673d422f639964b5474359f022c466e Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Wed, 14 Aug 2024 00:45:16 +0530 Subject: [PATCH 1/8] configure Accounts package to use valid clientStorage --- apps/meteor/client/startup/accounts.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/meteor/client/startup/accounts.ts b/apps/meteor/client/startup/accounts.ts index 3be110bc0a09..60f2de02bde0 100644 --- a/apps/meteor/client/startup/accounts.ts +++ b/apps/meteor/client/startup/accounts.ts @@ -2,6 +2,7 @@ import { Accounts } from 'meteor/accounts-base'; import { Meteor } from 'meteor/meteor'; import { Tracker } from 'meteor/tracker'; +import { settings } from '../../app/settings/client'; import { mainReady } from '../../app/ui-utils/client'; import { sdk } from '../../app/utils/client/lib/SDKClient'; import { t } from '../../app/utils/lib/i18n'; @@ -24,3 +25,15 @@ Accounts.onEmailVerificationLink((token: string) => { }); }); }); + +Meteor.startup(() => { + Tracker.autorun(() => { + const forgetUserSessionOnWindowClose = settings.get('Accounts_ForgetUserSessionOnWindowClose'); + + if (forgetUserSessionOnWindowClose === undefined) { + return; + } + + Accounts.config({ clientStorage: forgetUserSessionOnWindowClose ? 'session' : 'local' }); + }); +}); From 142a904b1e43c6e244a051c92c2d7d598af20805 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Wed, 14 Aug 2024 00:45:37 +0530 Subject: [PATCH 2/8] add e2e tests --- ...account-forgetSessionOnWindowClose.spec.ts | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts diff --git a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts new file mode 100644 index 000000000000..7f96b8e3d2ef --- /dev/null +++ b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts @@ -0,0 +1,57 @@ +import { DEFAULT_USER_CREDENTIALS } from './config/constants'; +import { Registration } from './page-objects'; +import { test, expect } from './utils/test'; + +test.describe.serial('Forget session on window close setting', () => { + let poRegistration: Registration; + + test.beforeEach(async ({ page }) => { + poRegistration = new Registration(page); + + await page.goto('/home'); + }); + + test.describe('Setting off', async () => { + test.beforeAll(async ({ api }) => { + expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false })).status()).toBe(200); + }); + + test.afterAll(async ({ api }) => { + expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true })).status()).toBe(200); + }); + + test('Login using credentials and reload to stay logged in', async ({ page }) => { + await poRegistration.username.type('user1'); + await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password); + await poRegistration.btnLogin.click(); + + await expect(page.locator('[data-qa-id="homepage-welcome-text"]')).toBeVisible(); + + await page.reload(); + + await expect(page.locator('[data-qa-id="homepage-welcome-text"]')).toBeVisible(); + }); + }); + + test.describe('Setting on', async () => { + test.beforeAll(async ({ api }) => { + expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true })).status()).toBe(200); + }); + + test.afterAll(async ({ api }) => { + expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false })).status()).toBe(200); + }); + + test('Login using credentials and reload to get logged out', async ({ page }) => { + await poRegistration.username.type('user1'); + await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password); + await poRegistration.btnLogin.click(); + + await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible(); + + await page.reload(); + + await expect(page.locator('role=button[name="Login"]')).toBeVisible(); + }); + }); +}); From 291c54d41c124e84d65a8f4bcf73ac4bda85074c Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Wed, 14 Aug 2024 02:24:38 +0530 Subject: [PATCH 3/8] weird TS issue: add account-base config definition --- apps/meteor/definition/externals/meteor/accounts-base.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/meteor/definition/externals/meteor/accounts-base.d.ts b/apps/meteor/definition/externals/meteor/accounts-base.d.ts index 3f0b148120e7..31b70f7b7154 100644 --- a/apps/meteor/definition/externals/meteor/accounts-base.d.ts +++ b/apps/meteor/definition/externals/meteor/accounts-base.d.ts @@ -42,6 +42,8 @@ declare module 'meteor/accounts-base' { function _clearAllLoginTokens(userId: string | null): void; + function config(options: { clientStorage: 'session' | 'local' }): void; + class ConfigError extends Error {} class LoginCancelledError extends Error { From 627410bfc348a463e9efb0925046694544ccb4bf Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Wed, 14 Aug 2024 02:53:16 +0530 Subject: [PATCH 4/8] add cs --- .changeset/two-bikes-crash.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/two-bikes-crash.md diff --git a/.changeset/two-bikes-crash.md b/.changeset/two-bikes-crash.md new file mode 100644 index 000000000000..dec30a0c219b --- /dev/null +++ b/.changeset/two-bikes-crash.md @@ -0,0 +1,7 @@ +--- +'@rocket.chat/meteor': minor +--- + +Fixed an issue related to setting Accounts_ForgetUserSessionOnWindowClose, this setting was not working as expected. + +The new meteor 2.16 release introduced a new option to configure the Accounts package and choose between the local storage or session storage. They also changed how Meteor.\_localstorage works internally. Due to these changes in Meteor, our setting to use session storage wasn't working as expected. This PR fixes this issue and configures the Accounts package according to the workspace settings. From d37859dcd56f7637f8a79551cdba72d232e267d5 Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Wed, 14 Aug 2024 03:08:34 +0530 Subject: [PATCH 5/8] improve e2e tests locators --- .../tests/e2e/account-forgetSessionOnWindowClose.spec.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts index 7f96b8e3d2ef..88f74181ce7b 100644 --- a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts +++ b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts @@ -25,14 +25,15 @@ test.describe.serial('Forget session on window close setting', () => { await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password); await poRegistration.btnLogin.click(); - await expect(page.locator('[data-qa-id="homepage-welcome-text"]')).toBeVisible(); + await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible(); await page.reload(); - await expect(page.locator('[data-qa-id="homepage-welcome-text"]')).toBeVisible(); - }); + await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible(); + }) }); + test.describe('Setting on', async () => { test.beforeAll(async ({ api }) => { expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true })).status()).toBe(200); @@ -52,6 +53,6 @@ test.describe.serial('Forget session on window close setting', () => { await page.reload(); await expect(page.locator('role=button[name="Login"]')).toBeVisible(); - }); + }) }); }); From 90f16a26ba1a2db869ab814790816eeec7b089cb Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Wed, 14 Aug 2024 03:40:43 +0530 Subject: [PATCH 6/8] fix lint --- .../tests/e2e/account-forgetSessionOnWindowClose.spec.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts index 88f74181ce7b..27325e3ccc82 100644 --- a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts +++ b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts @@ -30,10 +30,9 @@ test.describe.serial('Forget session on window close setting', () => { await page.reload(); await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible(); - }) + }); }); - test.describe('Setting on', async () => { test.beforeAll(async ({ api }) => { expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true })).status()).toBe(200); @@ -53,6 +52,6 @@ test.describe.serial('Forget session on window close setting', () => { await page.reload(); await expect(page.locator('role=button[name="Login"]')).toBeVisible(); - }) + }); }); }); From e5711673616164e60ee9c30a677b26a8b9f8238b Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Wed, 14 Aug 2024 19:15:53 +0530 Subject: [PATCH 7/8] fix review --- .changeset/two-bikes-crash.md | 2 +- .../e2e/account-forgetSessionOnWindowClose.spec.ts | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.changeset/two-bikes-crash.md b/.changeset/two-bikes-crash.md index dec30a0c219b..a120435e4a48 100644 --- a/.changeset/two-bikes-crash.md +++ b/.changeset/two-bikes-crash.md @@ -1,5 +1,5 @@ --- -'@rocket.chat/meteor': minor +'@rocket.chat/meteor': patch --- Fixed an issue related to setting Accounts_ForgetUserSessionOnWindowClose, this setting was not working as expected. diff --git a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts index 27325e3ccc82..d454ac41edb6 100644 --- a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts +++ b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts @@ -13,11 +13,7 @@ test.describe.serial('Forget session on window close setting', () => { test.describe('Setting off', async () => { test.beforeAll(async ({ api }) => { - expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false })).status()).toBe(200); - }); - - test.afterAll(async ({ api }) => { - expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true })).status()).toBe(200); + await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false }); }); test('Login using credentials and reload to stay logged in', async ({ page }) => { @@ -35,11 +31,11 @@ test.describe.serial('Forget session on window close setting', () => { test.describe('Setting on', async () => { test.beforeAll(async ({ api }) => { - expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true })).status()).toBe(200); + await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: true }); }); test.afterAll(async ({ api }) => { - expect((await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false })).status()).toBe(200); + await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false }); }); test('Login using credentials and reload to get logged out', async ({ page }) => { From ea1c31bddb598466540cc90d8f67335071e37d4a Mon Sep 17 00:00:00 2001 From: yash-rajpal Date: Tue, 20 Aug 2024 19:06:06 +0530 Subject: [PATCH 8/8] fix tests for session storage --- .../e2e/account-forgetSessionOnWindowClose.spec.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts index d454ac41edb6..a19b0e9866da 100644 --- a/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts +++ b/apps/meteor/tests/e2e/account-forgetSessionOnWindowClose.spec.ts @@ -16,16 +16,17 @@ test.describe.serial('Forget session on window close setting', () => { await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false }); }); - test('Login using credentials and reload to stay logged in', async ({ page }) => { + test('Login using credentials and reload to stay logged in', async ({ page, context }) => { await poRegistration.username.type('user1'); await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password); await poRegistration.btnLogin.click(); await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible(); - await page.reload(); + const newPage = await context.newPage(); + await newPage.goto('/home'); - await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible(); + await expect(newPage.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible(); }); }); @@ -38,16 +39,17 @@ test.describe.serial('Forget session on window close setting', () => { await api.post('/settings/Accounts_ForgetUserSessionOnWindowClose', { value: false }); }); - test('Login using credentials and reload to get logged out', async ({ page }) => { + test('Login using credentials and reload to get logged out', async ({ page, context }) => { await poRegistration.username.type('user1'); await poRegistration.inputPassword.type(DEFAULT_USER_CREDENTIALS.password); await poRegistration.btnLogin.click(); await expect(page.locator('role=heading[name="Welcome to Rocket.Chat"]')).toBeVisible(); - await page.reload(); + const newPage = await context.newPage(); + await newPage.goto('/home'); - await expect(page.locator('role=button[name="Login"]')).toBeVisible(); + await expect(newPage.locator('role=button[name="Login"]')).toBeVisible(); }); }); });