mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
[MM-47303] Migrate /enterprise/extend_session/not_extended_when_disabled e2e tests to TypeScript (#28465)
This commit is contained in:
parent
b4f337f191
commit
2aaa38b368
8 changed files with 65 additions and 42 deletions
|
|
@ -19,7 +19,7 @@ export function verifyExtendedSession(testUser, sessionLengthInDays, channelUrl)
|
|||
|
||||
// # Post a message to a channel
|
||||
const now = Date.now();
|
||||
cy.postMessage(now);
|
||||
cy.postMessage(`${now}`);
|
||||
|
||||
// # Update user session which is to expire 20 sec from now
|
||||
const soonToExpire = getExpirationFromNow(thirtySeconds);
|
||||
|
|
@ -53,7 +53,7 @@ export function verifyExtendedSession(testUser, sessionLengthInDays, channelUrl)
|
|||
|
||||
// # Post multiple times to check that the session continues and doesn't redirect to login page
|
||||
Cypress._.times(20, (i) => {
|
||||
cy.postMessage(i);
|
||||
cy.postMessage(`${i}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
// Group: @channels @enterprise @not_cloud @extend_session
|
||||
|
||||
import {UserProfile} from '@mattermost/types/users';
|
||||
import {verifyExtendedSession, verifyNotExtendedSession} from './helpers';
|
||||
|
||||
describe('Extended Session Length', () => {
|
||||
|
|
@ -16,10 +17,11 @@ describe('Extended Session Length', () => {
|
|||
const setting = {
|
||||
ServiceSettings: {
|
||||
SessionLengthWebInHours: sessionLengthInHours,
|
||||
ExtendSessionLengthWithActivity: false,
|
||||
},
|
||||
};
|
||||
let emailUser;
|
||||
let offTopicUrl;
|
||||
let emailUser: UserProfile;
|
||||
let offTopicUrl: string;
|
||||
|
||||
before(() => {
|
||||
cy.shouldNotRunOnCloudEdition();
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
// Group: @channels @enterprise @not_cloud @extend_session @ldap
|
||||
|
||||
import {UserProfile} from '@mattermost/types/users';
|
||||
import ldapUsers from '../../../../../fixtures/ldap_users.json';
|
||||
|
||||
import {verifyExtendedSession, verifyNotExtendedSession} from './helpers';
|
||||
|
|
@ -18,10 +19,11 @@ describe('Extended Session Length', () => {
|
|||
const setting = {
|
||||
ServiceSettings: {
|
||||
SessionLengthWebInHours: sessionLengthInHours,
|
||||
ExtendSessionLengthWithActivity: false,
|
||||
},
|
||||
};
|
||||
let testLdapUser;
|
||||
let offTopicUrl;
|
||||
let testLdapUser: UserProfile;
|
||||
let offTopicUrl: string;
|
||||
|
||||
before(() => {
|
||||
cy.shouldNotRunOnCloudEdition();
|
||||
|
|
@ -14,9 +14,11 @@
|
|||
|
||||
// Group: @channels @enterprise @not_cloud @extend_session @ldap @saml @keycloak
|
||||
|
||||
import {UserProfile} from '@mattermost/types/users';
|
||||
import {getKeycloakServerSettings} from '../../../../../utils/config';
|
||||
|
||||
import {verifyExtendedSession, verifyNotExtendedSession} from './helpers';
|
||||
import {LdapUser} from 'tests/support/ldap_server_commands';
|
||||
|
||||
describe('Extended Session Length', () => {
|
||||
const sessionLengthInDays = 1;
|
||||
|
|
@ -24,13 +26,14 @@ describe('Extended Session Length', () => {
|
|||
const sessionConfig = {
|
||||
ServiceSettings: {
|
||||
SessionLengthSSOInDays: sessionLengthInDays,
|
||||
ExtendSessionLengthWithActivity: false,
|
||||
},
|
||||
};
|
||||
|
||||
let testTeamId;
|
||||
let testSamlUser;
|
||||
let offTopicUrl;
|
||||
let samlLdapUser;
|
||||
let testTeamId: string;
|
||||
let testSamlUser: UserProfile;
|
||||
let offTopicUrl: string;
|
||||
let samlLdapUser: LdapUser;
|
||||
|
||||
before(() => {
|
||||
cy.shouldNotRunOnCloudEdition();
|
||||
|
|
@ -43,6 +43,6 @@ declare namespace Cypress {
|
|||
* @example
|
||||
* cy.apiSyncLDAPUser();
|
||||
*/
|
||||
apiSyncLDAPUser(): Chainable<UserProfile>;
|
||||
apiSyncLDAPUser({ldapUser = {}, bypassTutorial = true}): Chainable<UserProfile>;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
function delayRequestToRoutes(routes = [], delay = 0) {
|
||||
import {ChainableT} from 'tests/types';
|
||||
|
||||
function delayRequestToRoutes(routes: string[] = [], delay = 0) {
|
||||
cy.on('window:before:load', (win) => addDelay(win, routes, delay));
|
||||
}
|
||||
|
||||
|
|
@ -9,7 +11,7 @@ Cypress.Commands.add('delayRequestToRoutes', delayRequestToRoutes);
|
|||
|
||||
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
const addDelay = (win, routes, delay) => {
|
||||
const addDelay = (win, routes: string[], delay: number) => {
|
||||
const fetch = win.fetch;
|
||||
cy.stub(win, 'fetch').callsFake((...args) => {
|
||||
for (let i = 0; i < routes.length; i++) {
|
||||
|
|
@ -54,7 +56,8 @@ const mockWebsocketsFn = (win) => {
|
|||
}
|
||||
},
|
||||
connect() {
|
||||
this.wrappedSocket = new RealWebSocket(...args);
|
||||
const [param1, restOfParams] = args;
|
||||
this.wrappedSocket = new RealWebSocket(param1, restOfParams);
|
||||
this.wrappedSocket.onopen = this.onopen;
|
||||
this.wrappedSocket.onmessage = this.onmessage;
|
||||
this.wrappedSocket.onerror = this.onerror;
|
||||
|
|
@ -70,7 +73,7 @@ declare global {
|
|||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace Cypress {
|
||||
interface Chainable {
|
||||
delayRequestToRoutes: typeof delayRequestToRoutes;
|
||||
delayRequestToRoutes(routes: string[], delay: number): ChainableT<void>;
|
||||
mockWebsockets: typeof mockWebsockets;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// See LICENSE.txt for license information.
|
||||
|
||||
import {ChainableT} from 'tests/types';
|
||||
import {LdapUser} from './ldap_server_commands';
|
||||
import * as TIMEOUTS from '../fixtures/timeouts';
|
||||
|
||||
const {
|
||||
|
|
@ -36,8 +37,8 @@ function keycloakGetAccessTokenAPI(): ChainableT<string> {
|
|||
data: 'grant_type=password&username=mmuser&password=mostest&client_id=admin-cli',
|
||||
}).then((response: any) => {
|
||||
expect(response.status).to.equal(200);
|
||||
const token = response.data.access_token;
|
||||
return cy.wrap(token as string);
|
||||
const token: string = response.data.access_token;
|
||||
return cy.wrap(token);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +53,7 @@ Cypress.Commands.add('keycloakGetAccessTokenAPI', keycloakGetAccessTokenAPI);
|
|||
* @example
|
||||
* cy.keycloakCreateUserAPI('abcde', {firstName: 'test', lastName: 'test', email: 'test', username: 'test', enabled: true,});
|
||||
*/
|
||||
function keycloakCreateUserAPI(accessToken: string, user: any = {}) {
|
||||
function keycloakCreateUserAPI(accessToken: string, user: any = {}): ChainableT {
|
||||
const profile = buildProfile(user);
|
||||
return cy.task('keycloakRequest', {
|
||||
baseUrl,
|
||||
|
|
@ -152,7 +153,6 @@ function keycloakDeleteUserAPI(accessToken: string, userId: string): ChainableT
|
|||
expect(response.data).is.empty;
|
||||
});
|
||||
}
|
||||
|
||||
Cypress.Commands.add('keycloakDeleteUserAPI', keycloakDeleteUserAPI);
|
||||
|
||||
/**
|
||||
|
|
@ -179,7 +179,6 @@ function keycloakUpdateUserAPI(accessToken: string, userId: string, data: any):
|
|||
expect(response.data).is.empty;
|
||||
});
|
||||
}
|
||||
|
||||
Cypress.Commands.add('keycloakUpdateUserAPI', keycloakUpdateUserAPI);
|
||||
|
||||
/**
|
||||
|
|
@ -191,7 +190,7 @@ Cypress.Commands.add('keycloakUpdateUserAPI', keycloakUpdateUserAPI);
|
|||
* @example
|
||||
* cy.keycloakDeleteSessionAPI('abcde', '12345');
|
||||
*/
|
||||
function keycloakDeleteSessionAPI(accessToken: string, sessionId: string): ChainableT<any> {
|
||||
function keycloakDeleteSessionAPI(accessToken: string, sessionId: string): ChainableT {
|
||||
return cy.task('keycloakRequest', {
|
||||
baseUrl,
|
||||
path: `sessions/${sessionId}`,
|
||||
|
|
@ -293,7 +292,7 @@ Cypress.Commands.add('keycloakResetUsers', keycloakResetUsers);
|
|||
* @example
|
||||
* cy.keycloakCreateUser({firstName: 'test', lastName: 'test', email: 'test', username: 'test', enabled: true});
|
||||
*/
|
||||
function keycloakCreateUser(accessToken, user: any): ChainableT {
|
||||
function keycloakCreateUser(accessToken: string, user: any): ChainableT {
|
||||
return cy.keycloakCreateUserAPI(accessToken, user).then(() => {
|
||||
cy.keycloakGetUserAPI(accessToken, user.email).then((newId) => {
|
||||
cy.keycloakResetPasswordAPI(accessToken, newId, user.password).then(() => {
|
||||
|
|
@ -304,9 +303,15 @@ function keycloakCreateUser(accessToken, user: any): ChainableT {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
Cypress.Commands.add('keycloakCreateUser', keycloakCreateUser);
|
||||
|
||||
/**
|
||||
* keycloakCreateUsers is a command that creates keycloak users.
|
||||
* @param {User[]} users - an array of users
|
||||
*
|
||||
* @example
|
||||
* cy.keycloakCreateUsers(users);
|
||||
*/
|
||||
function keycloakCreateUsers(users = []) {
|
||||
return cy.keycloakGetAccessTokenAPI().then((accessToken) => {
|
||||
return users.forEach((user) => {
|
||||
|
|
@ -317,7 +322,15 @@ function keycloakCreateUsers(users = []) {
|
|||
|
||||
Cypress.Commands.add('keycloakCreateUsers', keycloakCreateUsers);
|
||||
|
||||
function keycloakUpdateUser(userEmail, data): ChainableT {
|
||||
/**
|
||||
* keycloakUpdateUser is a command that updates a keycloak user data.
|
||||
* @param {string} userEmail - the user email
|
||||
* @param {any} data - the user data to update
|
||||
*
|
||||
* @example
|
||||
* cy.keycloakUpdateUser('user@example.com', {firstName: 'test', lastName: 'test'});
|
||||
*/
|
||||
function keycloakUpdateUser(userEmail: string, data: any) {
|
||||
return cy.keycloakGetAccessTokenAPI().then((accessToken) => {
|
||||
return cy.keycloakGetUserAPI(accessToken, userEmail).then((userId) => {
|
||||
return cy.keycloakUpdateUserAPI(accessToken, userId, data);
|
||||
|
|
@ -375,7 +388,7 @@ Cypress.Commands.add('checkKeycloakLoginPage', checkKeycloakLoginPage);
|
|||
* @example
|
||||
* cy.doKeycloakLogin();
|
||||
*/
|
||||
function doKeycloakLogin(user) {
|
||||
function doKeycloakLogin(user: LdapUser) {
|
||||
cy.apiLogout();
|
||||
cy.visit('/login');
|
||||
cy.findByText('SAML').click();
|
||||
|
|
@ -418,7 +431,7 @@ declare global {
|
|||
keycloakSuspendUser(userEmail: string): ChainableT<void>;
|
||||
keycloakUnsuspendUser: typeof keycloakUnsuspendUser;
|
||||
checkKeycloakLoginPage: typeof checkKeycloakLoginPage;
|
||||
doKeycloakLogin(user): ChainableT<void>;
|
||||
doKeycloakLogin(user: LdapUser): ChainableT<void>;
|
||||
verifyKeycloakLoginFailed: typeof verifyKeycloakLoginFailed;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,17 @@ import {getRandomId} from '../utils';
|
|||
|
||||
const ldapTmpFolder = 'ldap_tmp';
|
||||
|
||||
export interface LdapUser {
|
||||
username: string;
|
||||
password: string;
|
||||
email: string;
|
||||
firstname: string;
|
||||
lastname: string;
|
||||
ldapfirstname: string;
|
||||
ldaplastname: string;
|
||||
keycloakId: string;
|
||||
}
|
||||
|
||||
function modifyLDAPUsers(filename: string) {
|
||||
cy.exec(`ldapmodify -x -D "cn=admin,dc=mm,dc=test,dc=com" -w mostest -H ldap://${Cypress.env('ldapServer')}:${Cypress.env('ldapPort')} -f tests/fixtures/${filename} -c`, {failOnNonZeroExit: false});
|
||||
}
|
||||
|
|
@ -18,7 +29,7 @@ function resetLDAPUsers() {
|
|||
|
||||
Cypress.Commands.add('resetLDAPUsers', resetLDAPUsers);
|
||||
|
||||
function createLDAPUser({prefix = 'ldap', user = undefined} = {}): ChainableT<LdapUser> {
|
||||
function createLDAPUser({prefix = 'ldap', user = null} = {}): ChainableT<LdapUser> {
|
||||
const ldapUser = user || generateLDAPUser(prefix);
|
||||
const data = generateContent(ldapUser);
|
||||
const filename = `new_user_${Date.now()}.ldif`;
|
||||
|
|
@ -27,13 +38,13 @@ function createLDAPUser({prefix = 'ldap', user = undefined} = {}): ChainableT<Ld
|
|||
cy.task('writeToFile', ({filename, fixturesFolder: ldapTmpFolder, data}));
|
||||
|
||||
return cy.ldapAdd(filePath).then(() => {
|
||||
return cy.wrap(ldapUser as LdapUser);
|
||||
return cy.wrap<LdapUser>(ldapUser);
|
||||
});
|
||||
}
|
||||
|
||||
Cypress.Commands.add('createLDAPUser', createLDAPUser);
|
||||
|
||||
function updateLDAPUser(user: LdapUser): ChainableT<LdapUser> {
|
||||
function updateLDAPUser(user: Partial<LdapUser>) {
|
||||
const data = generateContent(user, true);
|
||||
const filename = `update_user_${Date.now()}.ldif`;
|
||||
const filePath = `tests/fixtures/${ldapTmpFolder}/${filename}`;
|
||||
|
|
@ -81,7 +92,7 @@ function getLDAPCredentials() {
|
|||
return {host, bindDn, password};
|
||||
}
|
||||
|
||||
export function generateLDAPUser(prefix = 'ldap') {
|
||||
export function generateLDAPUser(prefix = 'ldap'): LdapUser {
|
||||
const randomId = getRandomId();
|
||||
const username = `${prefix}user${randomId}`;
|
||||
|
||||
|
|
@ -97,7 +108,7 @@ export function generateLDAPUser(prefix = 'ldap') {
|
|||
};
|
||||
}
|
||||
|
||||
function generateContent(user: Partial<LdapUser>, isUpdate = false) {
|
||||
function generateContent(user: Partial<LdapUser> = {}, isUpdate = false) {
|
||||
let deleteContent = '';
|
||||
if (isUpdate) {
|
||||
deleteContent = `dn: uid=${user.username},ou=e2etest,dc=mm,dc=test,dc=com
|
||||
|
|
@ -124,17 +135,6 @@ userPassword: Password1
|
|||
`;
|
||||
}
|
||||
|
||||
export interface LdapUser {
|
||||
username: string;
|
||||
password: string;
|
||||
email: string;
|
||||
firstname: string;
|
||||
lastname: string;
|
||||
ldapfirstname: string;
|
||||
ldaplastname: string;
|
||||
keycloakId: string;
|
||||
}
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
namespace Cypress {
|
||||
|
|
|
|||
Loading…
Reference in a new issue