Skip to content

Commit 7fea2ad

Browse files
committed
Merge branch 'develop' into new/omnichannel-source-fields
2 parents dbbcaf4 + e34af8d commit 7fea2ad

File tree

28 files changed

+39465
-40106
lines changed

28 files changed

+39465
-40106
lines changed

.github/workflows/build_and_test.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,6 @@ jobs:
117117

118118
- run: meteor npm run translation-check
119119

120-
- name: Launch MongoDB
121-
uses: wbari/[email protected]
122-
with:
123-
mongoDBVersion: "4.0"
124-
125-
- run: meteor npm run testunit
126-
127120
- run: meteor npm run typecheck
128121

129122
- name: Build Storybook to sanity check components
@@ -192,7 +185,7 @@ jobs:
192185
strategy:
193186
matrix:
194187
node-version: ["12.22.1"]
195-
mongodb-version: ["3.4", "3.6", "4.0", "4.2"]
188+
mongodb-version: ["3.6", "4.0", "4.2", "4.4","5.0"]
196189

197190
steps:
198191
- name: Launch MongoDB
@@ -249,7 +242,10 @@ jobs:
249242
run: |
250243
npm install
251244
252-
- name: Test
245+
- name: Unit Test
246+
run: npm run testunit
247+
248+
- name: E2E Test
253249
env:
254250
TEST_MODE: "true"
255251
MONGO_URL: mongodb://localhost:27017/rocketchat

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
meteor npm run lint && \
2-
meteor npm run testunit -- --exclude app/models/server/models/Sessions.tests.js
2+
meteor npm run testunit

app/meteor-accounts-saml/server/definition/ISAMLGlobalSettings.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export interface ISAMLGlobalSettings {
44
mailOverwrite: boolean;
55
immutableProperty: string;
66
defaultUserRole: string;
7-
roleAttributeName: string;
8-
roleAttributeSync: boolean;
97
userDataFieldMap: string;
108
usernameNormalize: string;
119
channelsAttributeUpdate: boolean;

app/meteor-accounts-saml/server/definition/IServiceProviderOptions.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ export interface IServiceProviderOptions {
99
customAuthnContext: string;
1010
authnContextComparison: string;
1111
defaultUserRole: string;
12-
roleAttributeName: string;
13-
roleAttributeSync: boolean;
1412
allowedClockDrift: number;
1513
signatureValidationType: string;
1614
identifierFormat: string;

app/meteor-accounts-saml/server/lib/SAML.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class SAML {
7272
}
7373

7474
public static insertOrUpdateSAMLUser(userObject: ISAMLUser): {userId: string; token: string} {
75-
const { roleAttributeSync, generateUsername, immutableProperty, nameOverwrite, mailOverwrite, channelsAttributeUpdate } = SAMLUtils.globalSettings;
75+
const { generateUsername, immutableProperty, nameOverwrite, mailOverwrite, channelsAttributeUpdate } = SAMLUtils.globalSettings;
7676

7777
let customIdentifierMatch = false;
7878
let customIdentifierAttributeName: string | null = null;
@@ -103,8 +103,8 @@ export class SAML {
103103
address: email,
104104
verified: settings.get('Accounts_Verify_Email_For_External_Accounts'),
105105
}));
106-
const globalRoles = userObject.roles;
107106

107+
const { roles } = userObject;
108108
let { username } = userObject;
109109

110110
const active = !settings.get('Accounts_ManuallyApproveNewUsers');
@@ -113,7 +113,7 @@ export class SAML {
113113
const newUser: Record<string, any> = {
114114
name: userObject.fullName,
115115
active,
116-
globalRoles,
116+
globalRoles: roles,
117117
emails,
118118
services: {
119119
saml: {
@@ -184,8 +184,8 @@ export class SAML {
184184
updateData.name = userObject.fullName;
185185
}
186186

187-
if (roleAttributeSync) {
188-
updateData.roles = globalRoles;
187+
if (roles) {
188+
updateData.roles = roles;
189189
}
190190

191191
if (userObject.channels && channelsAttributeUpdate === true) {
@@ -216,7 +216,7 @@ export class SAML {
216216
res.writeHead(200);
217217
res.write(serviceProvider.generateServiceProviderMetadata());
218218
res.end();
219-
} catch (err) {
219+
} catch (err: any) {
220220
showErrorMessage(res, err);
221221
}
222222
}
@@ -300,7 +300,7 @@ export class SAML {
300300

301301
redirect(url);
302302
});
303-
} catch (e) {
303+
} catch (e: any) {
304304
SystemLogger.error(e);
305305
redirect();
306306
}
@@ -472,7 +472,7 @@ export class SAML {
472472
}
473473
}
474474
}
475-
} catch (err) {
475+
} catch (err: any) {
476476
SystemLogger.error(err);
477477
}
478478
}

app/meteor-accounts-saml/server/lib/Utils.ts

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import zlib from 'zlib';
2+
import { EventEmitter } from 'events';
23

34
import _ from 'underscore';
45

@@ -7,31 +8,28 @@ import { ISAMLUser } from '../definition/ISAMLUser';
78
import { ISAMLGlobalSettings } from '../definition/ISAMLGlobalSettings';
89
import { IUserDataMap, IAttributeMapping } from '../definition/IAttributeMapping';
910
import { StatusCode } from './constants';
10-
11-
// @ToDo remove this ts-ignore someday
12-
// @ts-ignore skip checking if Logger exists to avoid having to import the Logger class here (it would bring a lot of baggage with its dependencies, affecting the unit tests)
13-
type NullableLogger = Logger | null;
11+
import { Logger } from '../../../../server/lib/logger/Logger';
1412

1513
let providerList: Array<IServiceProviderOptions> = [];
1614
let debug = false;
1715
let relayState: string | null = null;
18-
let logger: NullableLogger = null;
16+
let logger: Logger | undefined;
1917

2018
const globalSettings: ISAMLGlobalSettings = {
2119
generateUsername: false,
2220
nameOverwrite: false,
2321
mailOverwrite: false,
2422
immutableProperty: 'EMail',
2523
defaultUserRole: 'user',
26-
roleAttributeName: '',
27-
roleAttributeSync: false,
2824
userDataFieldMap: '{"username":"username", "email":"email", "cn": "name"}',
2925
usernameNormalize: 'None',
3026
channelsAttributeUpdate: false,
3127
includePrivateChannelsInUpdate: false,
3228
};
3329

3430
export class SAMLUtils {
31+
public static events: EventEmitter;
32+
3533
public static get isDebugging(): boolean {
3634
return debug;
3735
}
@@ -53,8 +51,7 @@ export class SAMLUtils {
5351
}
5452

5553
public static getServiceProviderOptions(providerName: string): IServiceProviderOptions | undefined {
56-
this.log(providerName);
57-
this.log(providerList);
54+
this.log(providerName, providerList);
5855

5956
return _.find(providerList, (providerOptions) => providerOptions.provider === providerName);
6057
}
@@ -63,7 +60,7 @@ export class SAMLUtils {
6360
providerList = list;
6461
}
6562

66-
public static setLoggerInstance(instance: NullableLogger): void {
63+
public static setLoggerInstance(instance: Logger): void {
6764
logger = instance;
6865
}
6966

@@ -74,7 +71,6 @@ export class SAMLUtils {
7471
globalSettings.generateUsername = Boolean(samlConfigs.generateUsername);
7572
globalSettings.nameOverwrite = Boolean(samlConfigs.nameOverwrite);
7673
globalSettings.mailOverwrite = Boolean(samlConfigs.mailOverwrite);
77-
globalSettings.roleAttributeSync = Boolean(samlConfigs.roleAttributeSync);
7874
globalSettings.channelsAttributeUpdate = Boolean(samlConfigs.channelsAttributeUpdate);
7975
globalSettings.includePrivateChannelsInUpdate = Boolean(samlConfigs.includePrivateChannelsInUpdate);
8076

@@ -90,10 +86,6 @@ export class SAMLUtils {
9086
globalSettings.defaultUserRole = samlConfigs.defaultUserRole;
9187
}
9288

93-
if (samlConfigs.roleAttributeName && typeof samlConfigs.roleAttributeName === 'string') {
94-
globalSettings.roleAttributeName = samlConfigs.roleAttributeName;
95-
}
96-
9789
if (samlConfigs.userDataFieldMap && typeof samlConfigs.userDataFieldMap === 'string') {
9890
globalSettings.userDataFieldMap = samlConfigs.userDataFieldMap;
9991
}
@@ -139,15 +131,15 @@ export class SAMLUtils {
139131
return newTemplate;
140132
}
141133

142-
public static log(...args: Array<any>): void {
134+
public static log(obj: any, ...args: Array<any>): void {
143135
if (debug && logger) {
144-
logger.debug(...args);
136+
logger.debug(obj, ...args);
145137
}
146138
}
147139

148-
public static error(...args: Array<any>): void {
140+
public static error(obj: any, ...args: Array<any>): void {
149141
if (logger) {
150-
logger.error(...args);
142+
logger.error(obj, ...args);
151143
}
152144
}
153145

@@ -421,7 +413,7 @@ export class SAMLUtils {
421413
public static mapProfileToUserObject(profile: Record<string, any>): ISAMLUser {
422414
const userDataMap = this.getUserDataMapping();
423415
SAMLUtils.log('parsed userDataMap', userDataMap);
424-
const { defaultUserRole = 'user', roleAttributeName } = this.globalSettings;
416+
const { defaultUserRole = 'user' } = this.globalSettings;
425417

426418
if (userDataMap.identifier.type === 'custom') {
427419
if (!userDataMap.identifier.attribute) {
@@ -470,15 +462,6 @@ export class SAMLUtils {
470462
userObject.username = this.normalizeUsername(profileUsername);
471463
}
472464

473-
if (roleAttributeName && profile[roleAttributeName]) {
474-
let value = profile[roleAttributeName] || '';
475-
if (typeof value === 'string') {
476-
value = value.split(',');
477-
}
478-
479-
userObject.roles = this.ensureArray<string>(value);
480-
}
481-
482465
if (profile.language) {
483466
userObject.language = profile.language;
484467
}
@@ -498,6 +481,10 @@ export class SAMLUtils {
498481
}
499482
}
500483

484+
this.events.emit('mapUser', { profile, userObject });
485+
501486
return userObject;
502487
}
503488
}
489+
490+
SAMLUtils.events = new EventEmitter();

app/meteor-accounts-saml/server/lib/parsers/Response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export class ResponseParser {
342342

343343
private validateNotBeforeNotOnOrAfterAssertions(element: Element): boolean {
344344
const sysnow = new Date();
345-
const allowedclockdrift = this.serviceProviderOptions.allowedClockDrift;
345+
const allowedclockdrift = this.serviceProviderOptions.allowedClockDrift || 0;
346346

347347
const now = new Date(sysnow.getTime() + allowedclockdrift);
348348

0 commit comments

Comments
 (0)