Support multiline LDAP filter queries
Signed-off-by: Mathias Åhsberg <mathias.ahsberg@resurs.se>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Add support for configure an LDAP query filter on multiple lines.
|
||||
@@ -172,4 +172,35 @@ describe('readLdapConfig', () => {
|
||||
];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('supports multiline ldap query filter', () => {
|
||||
const config = {
|
||||
providers: [
|
||||
{
|
||||
target: 'target',
|
||||
users: {
|
||||
dn: 'udn',
|
||||
options: {
|
||||
filter: `
|
||||
(|
|
||||
(cn=foo bar)
|
||||
(cn=bar)
|
||||
)
|
||||
`,
|
||||
},
|
||||
},
|
||||
groups: {
|
||||
dn: 'gdn',
|
||||
options: {
|
||||
filter: 'f',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
const actual = readLdapConfig(new ConfigReader(config));
|
||||
|
||||
const expected = '(|(cn=foo bar)(cn=bar))';
|
||||
expect(actual[0].users.options.filter).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -182,7 +182,7 @@ export function readLdapConfig(config: Config): LdapProviderConfig[] {
|
||||
}
|
||||
return {
|
||||
scope: c.getOptionalString('scope') as SearchOptions['scope'],
|
||||
filter: c.getOptionalString('filter'),
|
||||
filter: formatFilter(c.getOptionalString('filter')),
|
||||
attributes: c.getOptionalStringArray('attributes'),
|
||||
paged: c.getOptionalBoolean('paged'),
|
||||
};
|
||||
@@ -260,6 +260,11 @@ export function readLdapConfig(config: Config): LdapProviderConfig[] {
|
||||
};
|
||||
}
|
||||
|
||||
function formatFilter(filter?: string): string | undefined {
|
||||
// Remove extra whitespaces between blocks to support multiline filters from the configuration
|
||||
return filter?.replace(/\s*(\(|\))/g, '$1')?.trim();
|
||||
}
|
||||
|
||||
const providerConfigs = config.getOptionalConfigArray('providers') ?? [];
|
||||
return providerConfigs.map(c => {
|
||||
const newConfig = {
|
||||
|
||||
Reference in New Issue
Block a user