Add tests for mapping Active Directory entries
Signed-off-by: Mathias Åhsberg <mathias.ahsberg@resurs.se>
This commit is contained in:
@@ -26,7 +26,7 @@ import {
|
||||
LDAP_UUID_ANNOTATION,
|
||||
} from './constants';
|
||||
import { readLdapGroups, readLdapUsers, resolveRelations } from './read';
|
||||
import { DefaultLdapVendor } from './vendors';
|
||||
import { ActiveDirectoryVendor, DefaultLdapVendor } from './vendors';
|
||||
|
||||
function user(data: RecursivePartial<UserEntity>): UserEntity {
|
||||
return merge(
|
||||
@@ -54,7 +54,9 @@ function group(data: RecursivePartial<GroupEntity>): GroupEntity {
|
||||
);
|
||||
}
|
||||
|
||||
function searchEntry(attributes: Record<string, string[]>): SearchEntry {
|
||||
function searchEntry(
|
||||
attributes: Record<string, string[] | Buffer[]>,
|
||||
): SearchEntry {
|
||||
return {
|
||||
raw: Object.entries(attributes).reduce((obj, [key, values]) => {
|
||||
obj[key] = values;
|
||||
@@ -69,11 +71,10 @@ describe('readLdapUsers', () => {
|
||||
getVendor: jest.fn(),
|
||||
} as any;
|
||||
|
||||
beforeEach(() => client.getVendor.mockResolvedValue(DefaultLdapVendor));
|
||||
|
||||
afterEach(() => jest.resetAllMocks());
|
||||
|
||||
it('transfers all attributes', async () => {
|
||||
it('transfers all attributes from a default ldap vendor', async () => {
|
||||
client.getVendor.mockResolvedValue(DefaultLdapVendor);
|
||||
client.search.mockResolvedValue([
|
||||
searchEntry({
|
||||
uid: ['uid-value'],
|
||||
@@ -125,6 +126,79 @@ describe('readLdapUsers', () => {
|
||||
new Map([['dn-value', new Set(['x', 'y', 'z'])]]),
|
||||
);
|
||||
});
|
||||
|
||||
it('transfers all attributes from Microsoft Active Directory', async () => {
|
||||
client.getVendor.mockResolvedValue(ActiveDirectoryVendor);
|
||||
client.search.mockResolvedValue([
|
||||
searchEntry({
|
||||
uid: ['uid-value'],
|
||||
description: ['description-value'],
|
||||
cn: ['cn-value'],
|
||||
mail: ['mail-value'],
|
||||
avatarUrl: ['avatarUrl-value'],
|
||||
memberOf: ['x', 'y', 'z'],
|
||||
distinguishedName: ['dn-value'],
|
||||
objectGUID: [
|
||||
Buffer.from([
|
||||
68,
|
||||
2,
|
||||
125,
|
||||
190,
|
||||
209,
|
||||
0,
|
||||
94,
|
||||
73,
|
||||
133,
|
||||
33,
|
||||
230,
|
||||
174,
|
||||
234,
|
||||
195,
|
||||
160,
|
||||
152,
|
||||
]),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
const config: UserConfig = {
|
||||
dn: 'ddd',
|
||||
options: {},
|
||||
map: {
|
||||
rdn: 'uid',
|
||||
name: 'uid',
|
||||
description: 'description',
|
||||
displayName: 'cn',
|
||||
email: 'mail',
|
||||
picture: 'avatarUrl',
|
||||
memberOf: 'memberOf',
|
||||
},
|
||||
};
|
||||
const { users, userMemberOf } = await readLdapUsers(client, config);
|
||||
expect(users).toEqual([
|
||||
expect.objectContaining({
|
||||
metadata: {
|
||||
name: 'uid-value',
|
||||
description: 'description-value',
|
||||
annotations: {
|
||||
[LDAP_DN_ANNOTATION]: 'dn-value',
|
||||
[LDAP_RDN_ANNOTATION]: 'uid-value',
|
||||
[LDAP_UUID_ANNOTATION]: 'be7d0244-00d1-495e-8521-e6aeeac3a098',
|
||||
},
|
||||
},
|
||||
spec: {
|
||||
profile: {
|
||||
displayName: 'cn-value',
|
||||
email: 'mail-value',
|
||||
picture: 'avatarUrl-value',
|
||||
},
|
||||
memberOf: [],
|
||||
},
|
||||
}),
|
||||
]);
|
||||
expect(userMemberOf).toEqual(
|
||||
new Map([['dn-value', new Set(['x', 'y', 'z'])]]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('readLdapGroups', () => {
|
||||
@@ -133,11 +207,10 @@ describe('readLdapGroups', () => {
|
||||
getVendor: jest.fn(),
|
||||
} as any;
|
||||
|
||||
beforeEach(() => client.getVendor.mockResolvedValue(DefaultLdapVendor));
|
||||
|
||||
afterEach(() => jest.resetAllMocks());
|
||||
|
||||
it('transfers all attributes', async () => {
|
||||
it('transfers all attributes from a default ldap vendor', async () => {
|
||||
client.getVendor.mockResolvedValue(DefaultLdapVendor);
|
||||
client.search.mockResolvedValue([
|
||||
searchEntry({
|
||||
cn: ['cn-value'],
|
||||
@@ -199,6 +272,88 @@ describe('readLdapGroups', () => {
|
||||
new Map([['dn-value', new Set(['x', 'y', 'z'])]]),
|
||||
);
|
||||
});
|
||||
it('transfers all attributes from Microsoft Active Directory', async () => {
|
||||
client.getVendor.mockResolvedValue(ActiveDirectoryVendor);
|
||||
client.search.mockResolvedValue([
|
||||
searchEntry({
|
||||
cn: ['cn-value'],
|
||||
description: ['description-value'],
|
||||
tt: ['type-value'],
|
||||
mail: ['mail-value'],
|
||||
avatarUrl: ['avatarUrl-value'],
|
||||
memberOf: ['x', 'y', 'z'],
|
||||
member: ['e', 'f', 'g'],
|
||||
distinguishedName: ['dn-value'],
|
||||
objectGUID: [
|
||||
Buffer.from([
|
||||
68,
|
||||
2,
|
||||
125,
|
||||
190,
|
||||
209,
|
||||
0,
|
||||
94,
|
||||
73,
|
||||
133,
|
||||
33,
|
||||
230,
|
||||
174,
|
||||
234,
|
||||
195,
|
||||
160,
|
||||
152,
|
||||
]),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
const config: GroupConfig = {
|
||||
dn: 'ddd',
|
||||
options: {},
|
||||
map: {
|
||||
rdn: 'cn',
|
||||
name: 'cn',
|
||||
description: 'description',
|
||||
displayName: 'cn',
|
||||
email: 'mail',
|
||||
picture: 'avatarUrl',
|
||||
type: 'tt',
|
||||
memberOf: 'memberOf',
|
||||
members: 'member',
|
||||
},
|
||||
};
|
||||
const { groups, groupMember, groupMemberOf } = await readLdapGroups(
|
||||
client,
|
||||
config,
|
||||
);
|
||||
expect(groups).toEqual([
|
||||
expect.objectContaining({
|
||||
metadata: {
|
||||
name: 'cn-value',
|
||||
description: 'description-value',
|
||||
annotations: {
|
||||
[LDAP_DN_ANNOTATION]: 'dn-value',
|
||||
[LDAP_RDN_ANNOTATION]: 'cn-value',
|
||||
[LDAP_UUID_ANNOTATION]: 'be7d0244-00d1-495e-8521-e6aeeac3a098',
|
||||
},
|
||||
},
|
||||
spec: {
|
||||
type: 'type-value',
|
||||
profile: {
|
||||
displayName: 'cn-value',
|
||||
email: 'mail-value',
|
||||
picture: 'avatarUrl-value',
|
||||
},
|
||||
children: [],
|
||||
},
|
||||
}),
|
||||
]);
|
||||
expect(groupMember).toEqual(
|
||||
new Map([['dn-value', new Set(['e', 'f', 'g'])]]),
|
||||
);
|
||||
expect(groupMemberOf).toEqual(
|
||||
new Map([['dn-value', new Set(['x', 'y', 'z'])]]),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveRelations', () => {
|
||||
|
||||
Reference in New Issue
Block a user