Skip to content

Commit 0569bc6

Browse files
dennisvankekemsvcAPLBotferruhcihan
authored
fix: internalrepo v2 (#996)
* fix: internalrepo v2 * fix: acl for internalrepourls * fix: api.yaml indent * feat: new tests for internalrepourls --------- Co-authored-by: svcAPLBot <174728082+svcAPLBot@users.noreply.github.com> Co-authored-by: otomi-admin <63190600+ferruhcihan@users.noreply.github.com>
1 parent 4c6da93 commit 0569bc6

5 files changed

Lines changed: 41 additions & 29 deletions

File tree

src/api.authz.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,14 +781,23 @@ describe('API authz tests', () => {
781781
.expect(200)
782782
})
783783

784-
test('team member can get internal repository urls', async () => {
784+
test('team member can get own internal repository urls', async () => {
785785
jest.spyOn(otomiStack, 'getInternalRepoUrls').mockResolvedValue([])
786+
786787
await agent
787-
.get(`/v1/internalRepoUrls`)
788-
.query({ teamId })
788+
.get(`/v2/teams/${teamId}/internalRepoUrls`)
789789
.set('Authorization', `Bearer ${teamMemberToken}`)
790790
.expect(200)
791791
})
792+
793+
test('team member cannot get other internal repository urls', async () => {
794+
jest.spyOn(otomiStack, 'getInternalRepoUrls').mockResolvedValue([])
795+
796+
await agent
797+
.get(`/v2/teams/${otherTeamId}/internalRepoUrls`)
798+
.set('Authorization', `Bearer ${teamMemberToken}`)
799+
.expect(403)
800+
})
792801
})
793802

794803
describe('Policy endpoint tests', () => {

src/api/v1/internalRepoUrls.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Debug from 'debug'
2+
import { Response } from 'express'
3+
import { OpenApiRequestExt } from 'src/otomi-models'
4+
5+
const debug = Debug('otomi:api:v2:internalRepoUrls')
6+
7+
/**
8+
* GET /v2/teams/{teamId}/internalRepoUrls
9+
* Get internal repository URLs for a team
10+
*/
11+
export const getInternalRepoUrls = async (req: OpenApiRequestExt, res: Response): Promise<void> => {
12+
const { teamId } = req.params
13+
14+
debug(`getInternalRepoUrls ${teamId}`)
15+
16+
const v = await req.otomi.getInternalRepoUrls(teamId)
17+
res.json(v)
18+
}

src/openapi/api.yaml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2753,17 +2753,14 @@ paths:
27532753
schema:
27542754
$ref: '#/components/schemas/TestRepoConnect'
27552755

2756-
/v1/internalRepoUrls:
2756+
'/v2/teams/{teamId}/internalRepoUrls':
2757+
parameters:
2758+
- $ref: '#/components/parameters/teamParams'
27572759
get:
27582760
operationId: getInternalRepoUrls
2759-
x-eov-operation-handler: v1/internalRepoUrls
2761+
x-eov-operation-handler: v2/teams/{teamId}/internalRepoUrls
2762+
description: Get internal repository URLs for a team
27602763
x-aclSchema: InternalRepoUrls
2761-
parameters:
2762-
- name: teamId
2763-
in: query
2764-
description: ID of the team
2765-
schema:
2766-
type: string
27672764
responses:
27682765
'400':
27692766
$ref: '#/components/responses/BadRequest'

src/openapi/internalRepoUrls.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
InternalRepoUrls:
22
x-acl:
3-
platformAdmin: [read-any]
4-
teamAdmin: [read-any]
5-
teamMember: [read-any]
3+
platformAdmin:
4+
- read-any
5+
teamAdmin:
6+
- read
7+
teamMember:
8+
- read
69
type: array
710
items:
811
type: string

0 commit comments

Comments
 (0)