mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
refactor: convert channels/ad_ldap files to ts (#28677)
- convert js spec files to ts - convert ldap_server_commands.js to ts fixes: 21302 Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com>
This commit is contained in:
parent
c2a0374d2c
commit
ebcde8535e
@ -14,13 +14,14 @@
|
|||||||
|
|
||||||
// Group: @channels @enterprise @ldap @saml @keycloak
|
// Group: @channels @enterprise @ldap @saml @keycloak
|
||||||
|
|
||||||
|
import {LdapUser} from 'tests/support/ldap_server_commands';
|
||||||
import {getAdminAccount} from '../../../support/env';
|
import {getAdminAccount} from '../../../support/env';
|
||||||
import {getRandomId} from '../../../utils';
|
import {getRandomId} from '../../../utils';
|
||||||
import {getKeycloakServerSettings} from '../../../utils/config';
|
import {getKeycloakServerSettings} from '../../../utils/config';
|
||||||
|
|
||||||
describe('AD / LDAP', () => {
|
describe('AD / LDAP', () => {
|
||||||
let samlLdapUser;
|
let samlLdapUser: LdapUser;
|
||||||
let testTeamId;
|
let testTeamId: string;
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.shouldNotRunOnCloudEdition();
|
cy.shouldNotRunOnCloudEdition();
|
@ -15,14 +15,14 @@
|
|||||||
// Group: @channels @enterprise @ldap @saml @keycloak
|
// Group: @channels @enterprise @ldap @saml @keycloak
|
||||||
|
|
||||||
import {getAdminAccount} from '../../../support/env';
|
import {getAdminAccount} from '../../../support/env';
|
||||||
import {generateLDAPUser} from '../../../support/ldap_server_commands';
|
import {generateLDAPUser, LdapUser} from '../../../support/ldap_server_commands';
|
||||||
import {getKeycloakServerSettings} from '../../../utils/config';
|
import {getKeycloakServerSettings} from '../../../utils/config';
|
||||||
|
|
||||||
describe('AD / LDAP', () => {
|
describe('AD / LDAP', () => {
|
||||||
const nonLDAPUser = generateLDAPUser();
|
const nonLDAPUser = generateLDAPUser();
|
||||||
|
|
||||||
let samlLdapUser;
|
let samlLdapUser: LdapUser;
|
||||||
let testTeamId;
|
let testTeamId: string;
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.createLDAPUser().then((user) => {
|
cy.createLDAPUser().then((user) => {
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
// Group: @channels @enterprise @ldap @saml @keycloak
|
// Group: @channels @enterprise @ldap @saml @keycloak
|
||||||
|
|
||||||
|
import {LdapUser} from 'tests/support/ldap_server_commands';
|
||||||
import {getAdminAccount} from '../../../support/env';
|
import {getAdminAccount} from '../../../support/env';
|
||||||
import {getRandomId} from '../../../utils';
|
import {getRandomId} from '../../../utils';
|
||||||
import {getKeycloakServerSettings} from '../../../utils/config';
|
import {getKeycloakServerSettings} from '../../../utils/config';
|
||||||
@ -22,8 +23,8 @@ describe('AD / LDAP', () => {
|
|||||||
const admin = getAdminAccount();
|
const admin = getAdminAccount();
|
||||||
const samlConfig = getKeycloakServerSettings();
|
const samlConfig = getKeycloakServerSettings();
|
||||||
|
|
||||||
let samlLdapUser;
|
let samlLdapUser: LdapUser;
|
||||||
let testTeamId;
|
let testTeamId: string;
|
||||||
|
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.shouldNotRunOnCloudEdition();
|
cy.shouldNotRunOnCloudEdition();
|
@ -22,7 +22,7 @@ declare namespace Cypress {
|
|||||||
* @param {UserProfile} admin - an admin user
|
* @param {UserProfile} admin - an admin user
|
||||||
* @returns {boolean} - true if sync run successfully
|
* @returns {boolean} - true if sync run successfully
|
||||||
*/
|
*/
|
||||||
runLdapSync(admin: {UserProfile}): boolean;
|
runLdapSync(admin: UserProfile): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getLdapSyncJobStatus is a task that runs an external request for ldap_sync job status
|
* getLdapSyncJobStatus is a task that runs an external request for ldap_sync job status
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
||||||
// See LICENSE.txt for license information.
|
|
||||||
|
|
||||||
/// <reference types="cypress" />
|
|
||||||
|
|
||||||
// ***************************************************************
|
|
||||||
// Each command should be properly documented using JSDoc.
|
|
||||||
// See https://jsdoc.app/index.html for reference.
|
|
||||||
// Basic requirements for documentation are the following:
|
|
||||||
// - Meaningful description
|
|
||||||
// - Each parameter with `@params`
|
|
||||||
// - Return value with `@returns`
|
|
||||||
// - Example usage with `@example`
|
|
||||||
// Custom command should follow naming convention of having `external` prefix, e.g. `externalActivateUser`.
|
|
||||||
// ***************************************************************
|
|
||||||
|
|
||||||
declare namespace Cypress {
|
|
||||||
interface Chainable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* addLDAPUsers is a cy.exec() wrapped as command to run ldap modify
|
|
||||||
* against a local docker installation of OpenLdap.
|
|
||||||
* @returns {string} - access token
|
|
||||||
*/
|
|
||||||
addLDAPUsers(): Chainable;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +1,24 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
import {ChainableT} from 'tests/types';
|
||||||
import {getRandomId} from '../utils';
|
import {getRandomId} from '../utils';
|
||||||
|
|
||||||
const ldapTmpFolder = 'ldap_tmp';
|
const ldapTmpFolder = 'ldap_tmp';
|
||||||
|
|
||||||
Cypress.Commands.add('modifyLDAPUsers', (filename) => {
|
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});
|
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});
|
||||||
});
|
}
|
||||||
|
|
||||||
Cypress.Commands.add('resetLDAPUsers', () => {
|
Cypress.Commands.add('modifyLDAPUsers', modifyLDAPUsers);
|
||||||
|
|
||||||
|
function resetLDAPUsers() {
|
||||||
cy.modifyLDAPUsers('ldap-reset-data.ldif');
|
cy.modifyLDAPUsers('ldap-reset-data.ldif');
|
||||||
});
|
}
|
||||||
|
|
||||||
Cypress.Commands.add('createLDAPUser', ({prefix = 'ldap', user} = {}) => {
|
Cypress.Commands.add('resetLDAPUsers', resetLDAPUsers);
|
||||||
|
|
||||||
|
function createLDAPUser({prefix = 'ldap', user = undefined} = {}): ChainableT<LdapUser> {
|
||||||
const ldapUser = user || generateLDAPUser(prefix);
|
const ldapUser = user || generateLDAPUser(prefix);
|
||||||
const data = generateContent(ldapUser);
|
const data = generateContent(ldapUser);
|
||||||
const filename = `new_user_${Date.now()}.ldif`;
|
const filename = `new_user_${Date.now()}.ldif`;
|
||||||
@ -22,11 +27,13 @@ Cypress.Commands.add('createLDAPUser', ({prefix = 'ldap', user} = {}) => {
|
|||||||
cy.task('writeToFile', ({filename, fixturesFolder: ldapTmpFolder, data}));
|
cy.task('writeToFile', ({filename, fixturesFolder: ldapTmpFolder, data}));
|
||||||
|
|
||||||
return cy.ldapAdd(filePath).then(() => {
|
return cy.ldapAdd(filePath).then(() => {
|
||||||
return cy.wrap(ldapUser);
|
return cy.wrap(ldapUser as LdapUser);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
Cypress.Commands.add('updateLDAPUser', (user) => {
|
Cypress.Commands.add('createLDAPUser', createLDAPUser);
|
||||||
|
|
||||||
|
function updateLDAPUser(user: LdapUser): ChainableT<LdapUser> {
|
||||||
const data = generateContent(user, true);
|
const data = generateContent(user, true);
|
||||||
const filename = `update_user_${Date.now()}.ldif`;
|
const filename = `update_user_${Date.now()}.ldif`;
|
||||||
const filePath = `tests/fixtures/${ldapTmpFolder}/${filename}`;
|
const filePath = `tests/fixtures/${ldapTmpFolder}/${filename}`;
|
||||||
@ -36,9 +43,11 @@ Cypress.Commands.add('updateLDAPUser', (user) => {
|
|||||||
return cy.ldapModify(filePath).then(() => {
|
return cy.ldapModify(filePath).then(() => {
|
||||||
return cy.wrap(user);
|
return cy.wrap(user);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
Cypress.Commands.add('ldapAdd', (filePath) => {
|
Cypress.Commands.add('updateLDAPUser', updateLDAPUser);
|
||||||
|
|
||||||
|
function ldapAdd(filePath: string) {
|
||||||
const {host, bindDn, password} = getLDAPCredentials();
|
const {host, bindDn, password} = getLDAPCredentials();
|
||||||
|
|
||||||
return cy.exec(
|
return cy.exec(
|
||||||
@ -47,9 +56,11 @@ Cypress.Commands.add('ldapAdd', (filePath) => {
|
|||||||
).then(({code, stdout, stderr}) => {
|
).then(({code, stdout, stderr}) => {
|
||||||
cy.log(`ldapadd code: ${code}, stdout: ${stdout}, stderr: ${stderr}`);
|
cy.log(`ldapadd code: ${code}, stdout: ${stdout}, stderr: ${stderr}`);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
Cypress.Commands.add('ldapModify', (filePath) => {
|
Cypress.Commands.add('ldapAdd', ldapAdd);
|
||||||
|
|
||||||
|
function ldapModify(filePath: string) {
|
||||||
const {host, bindDn, password} = getLDAPCredentials();
|
const {host, bindDn, password} = getLDAPCredentials();
|
||||||
|
|
||||||
return cy.exec(
|
return cy.exec(
|
||||||
@ -58,7 +69,9 @@ Cypress.Commands.add('ldapModify', (filePath) => {
|
|||||||
).then(({code, stdout, stderr}) => {
|
).then(({code, stdout, stderr}) => {
|
||||||
cy.log(`ldapmodify code: ${code}, stdout: ${stdout}, stderr: ${stderr}`);
|
cy.log(`ldapmodify code: ${code}, stdout: ${stdout}, stderr: ${stderr}`);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
Cypress.Commands.add('ldapModify', ldapModify);
|
||||||
|
|
||||||
function getLDAPCredentials() {
|
function getLDAPCredentials() {
|
||||||
const host = `ldap://${Cypress.env('ldapServer')}:${Cypress.env('ldapPort')}`;
|
const host = `ldap://${Cypress.env('ldapServer')}:${Cypress.env('ldapPort')}`;
|
||||||
@ -72,7 +85,7 @@ export function generateLDAPUser(prefix = 'ldap') {
|
|||||||
const randomId = getRandomId();
|
const randomId = getRandomId();
|
||||||
const username = `${prefix}user${randomId}`;
|
const username = `${prefix}user${randomId}`;
|
||||||
|
|
||||||
return {
|
return <LdapUser>{
|
||||||
username,
|
username,
|
||||||
password: 'Password1',
|
password: 'Password1',
|
||||||
email: `${username}@mmtest.com`,
|
email: `${username}@mmtest.com`,
|
||||||
@ -84,7 +97,7 @@ export function generateLDAPUser(prefix = 'ldap') {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateContent(user = {}, isUpdate = false) {
|
function generateContent(user: Partial<LdapUser>, isUpdate = false) {
|
||||||
let deleteContent = '';
|
let deleteContent = '';
|
||||||
if (isUpdate) {
|
if (isUpdate) {
|
||||||
deleteContent = `dn: uid=${user.username},ou=e2etest,dc=mm,dc=test,dc=com
|
deleteContent = `dn: uid=${user.username},ou=e2etest,dc=mm,dc=test,dc=com
|
||||||
@ -110,3 +123,28 @@ mail: ${user.email}
|
|||||||
userPassword: Password1
|
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 {
|
||||||
|
interface Chainable {
|
||||||
|
modifyLDAPUsers: typeof modifyLDAPUsers;
|
||||||
|
resetLDAPUsers: typeof resetLDAPUsers;
|
||||||
|
createLDAPUser: typeof createLDAPUser;
|
||||||
|
updateLDAPUser: typeof updateLDAPUser;
|
||||||
|
ldapAdd: typeof ldapAdd;
|
||||||
|
ldapModify: typeof ldapModify;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user