Skip to content

Commit

Permalink
Merge pull request #16 from criteo-forks/capitalization
Browse files Browse the repository at this point in the history
Always consider lower case groups
  • Loading branch information
clems4ever authored Feb 4, 2019
2 parents 9b32af6 + fe60662 commit cbb58e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
37 changes: 37 additions & 0 deletions src/authorizations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
import { expect } from 'chai';
import { FilterTaskAdmins } from './authorizations';
import { CheckUserAuthorizations } from './authorizations';

describe('authorizations', function() {

describe('CheckUserAuthorizations', function() {
describe('when groups are matching', function() {
it('should authorize', function(done) {
const userCN = 'foo';
const userLdapGroups = ['CN=bar', 'CN=agroup'];
const admins_constraints = [['bar'], ['agroup']];
const superAdmins = ['superadmingroup'];

const promise = CheckUserAuthorizations(userCN, userLdapGroups, admins_constraints, superAdmins);
promise.then(() => done(), done);
});
});
describe('when groups are not matching', function() {
it('should authorize', function(done) {
const userCN = 'foo';
const userLdapGroups = ['CN=bar'];
const admins_constraints = [['bar'], ['agroup']];
const superAdmins = ['superadmingroup'];

const promise = CheckUserAuthorizations(userCN, userLdapGroups, admins_constraints, superAdmins);
promise.then(() => done('Should not authorize'), (err) => done());
});
});
describe('when capitalization is different', function() {
it('should authorize anyway', function(done) {
const userCN = 'foo';
const userLdapGroups = ['CN=bar', 'CN=aGroupWithCap'];
const admins_constraints = [['bar'], ['agroupwithcap']];
const superAdmins = ['superadmingroup'];

const promise = CheckUserAuthorizations(userCN, userLdapGroups, admins_constraints, superAdmins);
promise.then(() => done(), done);
});
});
});

describe('FilterTaskAdmins', function() {
describe('per app admins is disabled', function() {
it('should return empty array', function() {
Expand Down
4 changes: 2 additions & 2 deletions src/authorizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function extractCN(groups: string[]): string[] {
return groups.map((m: string) => {
const matches = m.match(/^(CN|cn)=([a-zA-Z0-9_-]+)/m);
return (matches.length > 1) ? matches[2] : undefined;
}).filter(m => m !== undefined);
}).filter(m => m !== undefined).map(m => m.toLowerCase());
}

// TODO: integrate all public methods in one authorizer class
Expand All @@ -47,7 +47,7 @@ export function CheckUserAuthorizations(
userCN: string,
userLdapGroups: string[],
admins_constraints: string[][],
superAdmins: string[]) {
superAdmins: string[]): Bluebird<void> {

const userGroups = extractCN(userLdapGroups);
const userAndGroups = [userCN].concat(userGroups);
Expand Down

0 comments on commit cbb58e2

Please sign in to comment.