Merge pull request #12521 from mrooding/add-free-ipa-ldap-vendor
Add support for FreeIPA as a LDAP vendor
This commit is contained in:
@@ -23,6 +23,7 @@ import { errorString } from './util';
|
||||
import {
|
||||
ActiveDirectoryVendor,
|
||||
DefaultLdapVendor,
|
||||
FreeIpaVendor,
|
||||
LdapVendor,
|
||||
} from './vendors';
|
||||
|
||||
@@ -199,6 +200,8 @@ export class LdapClient {
|
||||
.then(root => {
|
||||
if (root && root.raw?.forestFunctionality) {
|
||||
return ActiveDirectoryVendor;
|
||||
} else if (root && root.raw?.ipaDomainLevel) {
|
||||
return FreeIpaVendor;
|
||||
}
|
||||
return DefaultLdapVendor;
|
||||
})
|
||||
|
||||
@@ -32,7 +32,11 @@ import {
|
||||
resolveRelations,
|
||||
} from './read';
|
||||
import { RecursivePartial } from './util';
|
||||
import { ActiveDirectoryVendor, DefaultLdapVendor } from './vendors';
|
||||
import {
|
||||
ActiveDirectoryVendor,
|
||||
DefaultLdapVendor,
|
||||
FreeIpaVendor,
|
||||
} from './vendors';
|
||||
|
||||
function user(data: RecursivePartial<UserEntity>): UserEntity {
|
||||
return merge(
|
||||
@@ -195,6 +199,62 @@ describe('readLdapUsers', () => {
|
||||
new Map([['dn-value', new Set(['x', 'y', 'z'])]]),
|
||||
);
|
||||
});
|
||||
|
||||
it('transfers all attributes from FreeIPA', async () => {
|
||||
client.getVendor.mockResolvedValue(FreeIpaVendor);
|
||||
client.searchStreaming.mockImplementation(async (_dn, _opts, fn) => {
|
||||
await fn(
|
||||
searchEntry({
|
||||
uid: ['uid-value'],
|
||||
description: ['description-value'],
|
||||
cn: ['cn-value'],
|
||||
mail: ['mail-value'],
|
||||
avatarUrl: ['avatarUrl-value'],
|
||||
memberOf: ['x', 'y', 'z'],
|
||||
dn: ['dn-value'],
|
||||
ipaUniqueID: ['uuid-value'],
|
||||
}),
|
||||
);
|
||||
});
|
||||
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]: 'uuid-value',
|
||||
},
|
||||
},
|
||||
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', () => {
|
||||
|
||||
@@ -63,6 +63,16 @@ export const ActiveDirectoryVendor: LdapVendor = {
|
||||
},
|
||||
};
|
||||
|
||||
export const FreeIpaVendor: LdapVendor = {
|
||||
dnAttributeName: 'dn',
|
||||
uuidAttributeName: 'ipaUniqueID',
|
||||
decodeStringAttribute: (entry, name) => {
|
||||
return decode(entry, name, value => {
|
||||
return value.toString();
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
// Decode an attribute to a consumer
|
||||
function decode(
|
||||
entry: SearchEntry,
|
||||
|
||||
Reference in New Issue
Block a user