Skip to content

Commit 2a88281

Browse files
committed
Merge remote-tracking branch 'origin/main' into dependabot/npm_and_yarn/npm-dependencies-04ade640ba
2 parents b47e8bf + f45fe84 commit 2a88281

File tree

3 files changed

+110
-6
lines changed

3 files changed

+110
-6
lines changed

src/middleware/jwt.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { mockDeep } from 'jest-mock-extended'
12
import { JWT } from 'src/otomi-models'
23
import OtomiStack from 'src/otomi-stack'
3-
import { getUser } from './jwt'
4-
import * as getValuesSchemaModule from '../utils'
54
import { loadSpec } from '../app'
6-
import { mockDeep } from 'jest-mock-extended'
75
import { Git } from '../git'
6+
import * as getValuesSchemaModule from '../utils'
7+
import { getUser } from './jwt'
88

99
const email = '[email protected]'
1010
const platformAdminGroups = ['platform-admin', 'all-teams-admin']
@@ -64,7 +64,7 @@ describe('JWT claims mapping', () => {
6464
})
6565

6666
test("Non existing team groups should not be added to the user's list of teams", async () => {
67-
const extraneousTeamsList = [...multiTeamUser, 'nonexisting']
67+
const extraneousTeamsList = [...multiTeamUser, 'nonexist']
6868
await Promise.all(extraneousTeamsList.map(async (teamId) => otomiStack.createTeam({ name: teamId }, false)))
6969
const user = getUser(multiTeamJWT, otomiStack)
7070
expect(user.teams).toEqual(multiTeamUser)

src/otomi-stack.test.ts

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from 'src/otomi-models'
1212
import OtomiStack from 'src/otomi-stack'
1313
import { loadSpec } from './app'
14-
import { PublicUrlExists } from './error'
14+
import { PublicUrlExists, ValidationError } from './error'
1515
import { Git } from './git'
1616
import { RepoService } from './services/RepoService'
1717
import { TeamConfigService } from './services/TeamConfigService'
@@ -208,6 +208,109 @@ describe('Data validation', () => {
208208
expect(createItemSpy.mock.calls[0][0].spec.password).toEqual(myPassword)
209209
createItemSpy.mockRestore()
210210
})
211+
212+
test('should throw ValidationError when team name exceeds 9 characters', async () => {
213+
const teamData: AplTeamSettingsRequest = {
214+
kind: 'AplTeamSettingSet',
215+
metadata: {
216+
name: 'verylongteamname',
217+
labels: {
218+
'apl.io/teamId': 'verylongteamname',
219+
},
220+
},
221+
spec: {},
222+
}
223+
224+
await expect(otomiStack.createAplTeam(teamData, false)).rejects.toThrow(
225+
new ValidationError('Team name must not exceed 9 characters'),
226+
)
227+
})
228+
229+
test('should not throw ValidationError when team name is exactly 9 characters', async () => {
230+
const teamSettings = {
231+
kind: 'AplTeamSettingSet',
232+
metadata: {
233+
name: 'ninechars',
234+
labels: {
235+
'apl.io/teamId': 'ninechars',
236+
},
237+
},
238+
spec: {},
239+
status: {},
240+
}
241+
242+
const createItemSpy = jest.spyOn(otomiStack.repoService, 'createTeamConfig').mockReturnValue({
243+
builds: [],
244+
codeRepos: [],
245+
workloads: [],
246+
services: [],
247+
sealedsecrets: [],
248+
backups: [],
249+
projects: [],
250+
netpols: [],
251+
settings: teamSettings,
252+
apps: [],
253+
policies: [],
254+
workloadValues: [],
255+
} as TeamConfig)
256+
257+
const teamData: AplTeamSettingsRequest = {
258+
kind: 'AplTeamSettingSet',
259+
metadata: {
260+
name: 'ninechars',
261+
labels: {
262+
'apl.io/teamId': 'ninechars',
263+
},
264+
},
265+
spec: {},
266+
}
267+
268+
await expect(otomiStack.createAplTeam(teamData, false)).resolves.not.toThrow()
269+
createItemSpy.mockRestore()
270+
})
271+
272+
test('should not throw ValidationError when team name is less than 9 characters', async () => {
273+
const teamSettings = {
274+
kind: 'AplTeamSettingSet',
275+
metadata: {
276+
name: 'short',
277+
labels: {
278+
'apl.io/teamId': 'short',
279+
},
280+
},
281+
spec: {},
282+
status: {},
283+
}
284+
285+
const createItemSpy = jest.spyOn(otomiStack.repoService, 'createTeamConfig').mockReturnValue({
286+
builds: [],
287+
codeRepos: [],
288+
workloads: [],
289+
services: [],
290+
sealedsecrets: [],
291+
backups: [],
292+
projects: [],
293+
netpols: [],
294+
settings: teamSettings,
295+
apps: [],
296+
policies: [],
297+
workloadValues: [],
298+
} as TeamConfig)
299+
300+
const teamData: AplTeamSettingsRequest = {
301+
kind: 'AplTeamSettingSet',
302+
metadata: {
303+
name: 'short',
304+
labels: {
305+
'apl.io/teamId': 'short',
306+
},
307+
},
308+
spec: {},
309+
}
310+
311+
await expect(otomiStack.createAplTeam(teamData, false)).resolves.not.toThrow()
312+
createItemSpy.mockRestore()
313+
})
211314
})
212315

213316
describe('Work with values', () => {

src/otomi-stack.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CoreV1Api, KubeConfig, User as k8sUser, V1ObjectReference } from '@kubernetes/client-node'
1+
import { CoreV1Api, User as k8sUser, KubeConfig, V1ObjectReference } from '@kubernetes/client-node'
22
import Debug from 'debug'
33

44
import { getRegions, ObjectStorageKeyRegions } from '@linode/api-v4'
@@ -689,6 +689,7 @@ export default class OtomiStack {
689689

690690
async createAplTeam(data: AplTeamSettingsRequest, deploy = true): Promise<AplTeamSettingsResponse> {
691691
const teamName = data.metadata.name
692+
if (teamName.length > 9) throw new ValidationError('Team name must not exceed 9 characters')
692693

693694
if (isEmpty(data.spec.password)) {
694695
debug(`creating password for team '${teamName}'`)

0 commit comments

Comments
 (0)