improve LDAP missing metadata.name error message

Signed-off-by: Jessica He <jhe@redhat.com>
This commit is contained in:
Jessica He
2025-04-09 16:04:06 -04:00
parent 64ddf3097d
commit e253d1d0af
3 changed files with 80 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend-module-ldap': patch
---
Improves error reporting for missing metadata.name in LDAP catalog provider.
@@ -988,6 +988,34 @@ describe('defaultUserTransformer', () => {
},
});
});
it('throws and includes message when uid (metadata.name) is missing', async () => {
const config: UserConfig = {
dn: 'ddd',
options: {},
map: {
rdn: 'uid',
name: 'uid',
displayName: 'cn',
email: 'mail',
memberOf: 'memberOf',
},
set: {},
};
const entry = searchEntry({
description: ['description-value'],
cn: ['cn-value'],
mail: ['mail-value'],
memberOf: ['x', 'y', 'z'],
});
await expect(
defaultUserTransformer(DefaultLdapVendor, config, entry),
).rejects.toThrow(
"User syncing failed: missing 'uid' attribute, consider applying a user filter to skip processing users with incomplete data.",
);
});
});
describe('defaultGroupTransformer', () => {
@@ -1073,6 +1101,38 @@ describe('defaultGroupTransformer', () => {
},
});
});
it('throws and includes message when cn (metadata.name) is missing', async () => {
const config: GroupConfig = {
dn: 'ddd',
options: {},
map: {
rdn: 'cn',
name: 'cn',
displayName: 'cn',
email: 'mail',
description: 'description',
type: 'type',
members: 'members',
memberOf: 'memberOf',
},
};
const entry = searchEntry({
description: ['description-value'],
mail: ['mail-value'],
avatarUrl: ['avatarUrl-value'],
memberOf: ['x', 'y', 'z'],
entryDN: ['dn-value'],
entryUUID: ['uuid-value'],
});
await expect(
defaultGroupTransformer(DefaultLdapVendor, config, entry),
).rejects.toThrow(
"Group syncing failed: missing 'cn' attribute, consider applying a group filter to skip processing groups with incomplete data.",
);
});
});
/**
@@ -34,6 +34,7 @@ import { LdapVendor } from './vendors';
import { GroupTransformer, UserTransformer } from './types';
import { mapStringAttr } from './util';
import { LoggerService } from '@backstage/backend-plugin-api';
import { InputError } from '@backstage/errors';
/**
* The default implementation of the transformation from an LDAP entry to a
@@ -70,6 +71,13 @@ export async function defaultUserTransformer(
mapStringAttr(entry, vendor, map.name, v => {
entity.metadata.name = v;
});
if (!entity.metadata.name) {
throw new InputError(
`User syncing failed: missing '${map.name}' attribute, consider applying a user filter to skip processing users with incomplete data.`,
);
}
mapStringAttr(entry, vendor, map.description, v => {
entity.metadata.description = v;
});
@@ -180,6 +188,13 @@ export async function defaultGroupTransformer(
mapStringAttr(entry, vendor, map.name, v => {
entity.metadata.name = v;
});
if (!entity.metadata.name) {
throw new InputError(
`Group syncing failed: missing '${map.name}' attribute, consider applying a group filter to skip processing groups with incomplete data.`,
);
}
mapStringAttr(entry, vendor, map.description, v => {
entity.metadata.description = v;
});