Files
Harrison HealeyandGitHub daec1283e5 MM-69003 Mostly share ESLint config between web app and E2E tests (#36767)
* Switch Cypress to use shared ESLint config

* Run --fix in Cypress

* Manually fix remaining lint issues in Cypress

* Switch Playwright to use shared ESLint config

* Run --fix in Playwright

* Manually fix remaining lint issues in Playwright

* Install and cache web app deps during Cypress CI builds

This also caches the types and client package. That isn't needed currently
since it uses prepackaged versions of those, but I imagine we might change
that at some point.

* Run e2e-tests-check when ESLint plugin is updated

* Change E2E test GHA caching to cache all of web app node_modules

* Fix mismatch between cache save and restore

* Try bumping cache keys

* Copy step to install dependencies to server.run_cypress.sh

I don't know how this must've worked before, but if this fixes the issue,
it seems like neither Cypress nor Playwright actually use the cached
depenendencies.

* Try disabling caching entirely for Cypress tests

* Try bypassing makefile?

* Try also manually building dependencies in run_specs.sh

I don't know why this appears to duplicate run_cypress.sh and
run_playwright.sh, both of which are called run_test.sh which
might not be used any more as best I can tell.

* Try installing the web app dependencies in yet another place

* Disable the extra steps in server.prepare.sh specifically for Cypress

* Revert changes to update cache key and disable web app depenedency cache on Cypress builds
2026-06-09 20:50:58 +00:00

126 lines
4.6 KiB
TypeScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
// ***************************************************************
// - [#] indicates a test step (e.g. # Go to a page)
// - [*] indicates an assertion (e.g. * Check the title)
// - Use element ID when selecting an element. Create one if none.
// ***************************************************************
// Stage: @prod
// Group: @channels @system_console @user_management
import type {Team} from '@mattermost/types/teams';
import type {UserProfile} from '@mattermost/types/users';
describe('Deactivated user', () => {
let testUser: UserProfile;
let adminUser: UserProfile;
let testTeam: Team;
let personalAccessToken: string;
before(() => {
// # Set up admin user and team
cy.apiInitSetup({loginAfter: true, promoteNewUserAsAdmin: true}).then(({user, team}) => {
adminUser = user;
testTeam = team;
// # Enable Personal Access Token And User Deactivation
cy.apiUpdateConfig({
ServiceSettings: {
EnableUserAccessTokens: true,
},
TeamSettings: {
EnableUserDeactivation: true,
},
});
});
});
it('should not allow API access with PAT after user deactivation', () => {
// # Login as admin
cy.apiLogin(adminUser);
// # Create a new user
cy.apiCreateUser().then(({user}) => {
testUser = user;
// # Add user to team
cy.apiAddUserToTeam(testTeam.id, user.id);
// # Grant user permission to create personal access tokens
cy.apiPatchUserRoles(testUser.id, ['system_user', 'system_user_access_token']);
// # Logout admin
cy.apiLogout();
// # Login as the test user
cy.apiLogin(testUser);
// # Navigate to the home page
cy.visit('/');
// # Create a personal access token as the test user
const tokenName = 'token' + Date.now();
// # Generate a personal access token via API
cy.apiAccessToken(testUser.id, tokenName).then((token) => {
personalAccessToken = token.token!;
// # Replace the auth cookie with the PAT
cy.setCookie('MMAUTHTOKEN', personalAccessToken);
// # Reload the page to use the PAT for authentication
cy.visit('/');
// * Verify the auth cookie has been set with the PAT
cy.getCookie('MMAUTHTOKEN').
should('have.property', 'value', personalAccessToken);
// * Verify we're still logged in using the PAT
cy.get('#sidebarItem_town-square').should('be.visible');
// # Make an API request using the PAT
cy.request({
headers: {
Authorization: `Bearer ${personalAccessToken}`,
},
url: '/api/v4/users/me',
method: 'GET',
}).then((response) => {
// * Verify the request was successful
expect(response.status).to.equal(200);
// * Verify the response contains the correct user ID
expect(response.body.id).to.equal(testUser.id);
});
// # Use an admin client to deactivate the user
cy.makeClient({user: adminUser}).then((client) => {
// # Deactivate the test user
client.updateUserActive(testUser.id, false).then(() => {
// # Try to use the PAT after user deactivation
cy.request({
headers: {
Authorization: `Bearer ${personalAccessToken}`,
},
url: '/api/v4/users/me',
method: 'GET',
failOnStatusCode: false,
}).then((response) => {
// * Verify the request fails with 401 Unauthorized
expect(response.status).to.equal(401);
});
// # Try to navigate back to the channel
cy.visit(`/${testTeam.name}/channels/town-square`);
// * Verify we are redirect to the login page
cy.url().should('include', '/login');
});
});
});
});
});
});