add testing and root group discovery
Signed-off-by: Hghtwr <johannes.sonner@outlook.com>
This commit is contained in:
@@ -30,6 +30,7 @@ import {
|
||||
some_endpoint,
|
||||
unhealthy_endpoint,
|
||||
userID,
|
||||
single_group_response,
|
||||
} from './mocks';
|
||||
|
||||
const httpHandlers = [
|
||||
@@ -71,6 +72,9 @@ const httpHandlers = [
|
||||
return res(ctx.set('x-next-page', ''), ctx.json(all_groups_response));
|
||||
}),
|
||||
|
||||
rest.get(`${apiBaseUrl}/groups/group1`, (_req, res, ctx) => {
|
||||
return res(ctx.set('x-next-page', ''), ctx.json(single_group_response));
|
||||
}),
|
||||
rest.get(`${apiBaseUrl}/groups/42`, (_, res, ctx) => {
|
||||
return res(ctx.status(500), ctx.json({ error: 'Internal Server Error' }));
|
||||
}),
|
||||
@@ -78,6 +82,10 @@ const httpHandlers = [
|
||||
return res(ctx.json(all_self_hosted_group1_members));
|
||||
}),
|
||||
|
||||
rest.get(`${apiBaseUrlSaas}/groups/group1`, (_req, res, ctx) => {
|
||||
return res(ctx.set('x-next-page', ''), ctx.json(single_group_response));
|
||||
}),
|
||||
|
||||
rest.get(`${apiBaseUrlSaas}/groups/group1/members/all`, (_req, res, ctx) => {
|
||||
return res(ctx.json(all_saas_users_response));
|
||||
}),
|
||||
|
||||
@@ -1037,6 +1037,13 @@ export const all_saas_users_response: MockObject[] = [
|
||||
},
|
||||
];
|
||||
|
||||
export const single_group_response: GitLabGroup = {
|
||||
id: 1,
|
||||
name: 'group1',
|
||||
description: 'description1',
|
||||
full_path: 'group1',
|
||||
};
|
||||
|
||||
export const all_groups_response: GitLabGroup[] = [
|
||||
{
|
||||
id: 1,
|
||||
@@ -1111,7 +1118,7 @@ export const expectedSaasGroup: MockObject[] = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'group1',
|
||||
description: 'description1',
|
||||
description: '',
|
||||
full_path: 'path/group1',
|
||||
parent_id: 123,
|
||||
},
|
||||
@@ -2495,7 +2502,7 @@ export const expected_group_members_group_org_scan_entities: MockObject[] = [
|
||||
name: 'JohnDoe',
|
||||
},
|
||||
spec: {
|
||||
memberOf: ['subgroup1'],
|
||||
memberOf: ['subgroup1', 'group1'],
|
||||
profile: {
|
||||
displayName: 'John Doe',
|
||||
email: 'john.doe@company.com',
|
||||
@@ -2530,6 +2537,30 @@ export const expected_group_members_group_org_scan_entities: MockObject[] = [
|
||||
},
|
||||
locationKey: 'GitlabOrgDiscoveryEntityProvider:test-id',
|
||||
},
|
||||
{
|
||||
entity: {
|
||||
apiVersion: 'backstage.io/v1alpha1',
|
||||
kind: 'Group',
|
||||
metadata: {
|
||||
annotations: {
|
||||
'backstage.io/managed-by-location': 'url:https://example.com/group1',
|
||||
'backstage.io/managed-by-origin-location':
|
||||
'url:https://example.com/group1',
|
||||
'example.com/team-path': 'group1',
|
||||
},
|
||||
name: 'group1',
|
||||
description: 'description1',
|
||||
},
|
||||
spec: {
|
||||
children: [],
|
||||
profile: {
|
||||
displayName: 'group1',
|
||||
},
|
||||
type: 'team',
|
||||
},
|
||||
},
|
||||
locationKey: 'GitlabOrgDiscoveryEntityProvider:test-id',
|
||||
},
|
||||
];
|
||||
|
||||
export const all_self_hosted_group1_members: MockObject[] = [
|
||||
|
||||
@@ -166,6 +166,16 @@ export class GitLabClient {
|
||||
return this.pagedRequest(`/groups`, options);
|
||||
}
|
||||
|
||||
async getGroupByPath(
|
||||
groupPath: string,
|
||||
options?: CommonListOptions,
|
||||
): Promise<GitLabGroup> {
|
||||
return this.nonPagedRequest(
|
||||
`/groups/${encodeURIComponent(groupPath)}`,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
async listDescendantGroups(
|
||||
groupPath: string,
|
||||
): Promise<PagedResponse<GitLabGroup>> {
|
||||
|
||||
+3
@@ -366,6 +366,7 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
if (this.gitLabClient.isSelfManaged() && this.config.restrictUsersToGroup) {
|
||||
groups = (await this.gitLabClient.listDescendantGroups(this.config.group))
|
||||
.items;
|
||||
groups.push(await this.gitLabClient.getGroupByPath(this.config.group));
|
||||
users = paginated<GitLabUser>(
|
||||
options =>
|
||||
this.gitLabClient.listGroupMembers(this.config.group, options), // calls /groups/<groupId>/members
|
||||
@@ -395,10 +396,12 @@ export class GitlabOrgDiscoveryEntityProvider implements EntityProvider {
|
||||
else {
|
||||
groups = (await this.gitLabClient.listDescendantGroups(this.config.group))
|
||||
.items;
|
||||
groups.push(await this.gitLabClient.getGroupByPath(this.config.group));
|
||||
const rootGroupSplit = this.config.group.split('/');
|
||||
const rootGroup = this.config.restrictUsersToGroup
|
||||
? rootGroupSplit[rootGroupSplit.length - 1]
|
||||
: rootGroupSplit[0];
|
||||
|
||||
users = paginated<GitLabUser>(
|
||||
options =>
|
||||
this.gitLabClient.listSaaSUsers(
|
||||
|
||||
Reference in New Issue
Block a user