Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ Plus le score est eleve, plus le module est prioritaire.
| 17 | service-chain | Metier | 5.9 | V3 | S8 | ✅ MIGRE |
| 18 | repository | Metier | 5.8 | V3 | S7-S8 | |
| 19 | cluster | Metier | 5.7 | V3 | S7 | |
| 20 | harbor (encapsulation) | Plugin | 5.6 | V4 | S9-S10 | |
| 20 | harbor (encapsulation) | Plugin | 5.6 | V4 | S9-S10 | ✅ MIGRE |
| 21 | project-service | Metier | 5.6 | V3 | S8 | |
| 22 | argocd (encapsulation) | Plugin | 5.3 | V5 | S10-S11 | |
| 23 | project-role | Metier | 5.2 | V3 | S7-S8 | |
| 24 | nexus (encapsulation) | Plugin | 5.1 | V4 | S10 | |
| 24 | nexus (encapsulation) | Plugin | 5.1 | V4 | S10 | ✅ MIGRE |
| 25 | project-member | Metier | 4.7 | V3 | S8 | |
| 26 | project-secrets | Metier | 4.6 | V4 | S9 | |
| 27 | project-bulk | Metier | 4.2 | V4 | S9-S10 | |
Expand Down Expand Up @@ -754,7 +754,7 @@ NestJS injectables.
**Fichiers** :
- `src/cpin-module/service-chain/service-chain.*.ts`
- `src/cpin-module/service-chain/open-cds-client.*.ts`
- `src/cpin-module/infrastructure/auth/` (AuthModule partage)
- `src/modules/infrastructure/auth/` (AuthModule partage)

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe('argoCDService', () => {
gitlab.listFiles.mockResolvedValue([])
vault.readProjectValues.mockResolvedValue({ secret: 'value' })

gitlab.generateCreateOrUpdateAction.mockResolvedValue(null as any)
gitlab.generateCreateOrUpdateAction.mockResolvedValue(null)

await expect(service.handleCron()).resolves.not.toThrow()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ describe('gitlab-client', () => {
name: 'Admin Auditor',
}
const gitlabUsersAllMock = gitlabMock.Users.all as MockedFunction<typeof gitlabMock.Users.all>
gitlabUsersAllMock.mockResolvedValue([makeExpandedUserSchema({ id: 1000, email: consoleUser.email, is_admin: true })])
gitlabUsersAllMock.mockResolvedValue([
makeExpandedUserSchema({ id: 1000, email: consoleUser.email, is_admin: true }),
])

await service.upsertUser({ ...gitlabUser, auditor: true }, { cpnUserId: consoleUser.id })

Expand All @@ -391,7 +393,9 @@ describe('gitlab-client', () => {
name: 'Auditor Admin',
}
const gitlabUsersAllMock = gitlabMock.Users.all as MockedFunction<typeof gitlabMock.Users.all>
gitlabUsersAllMock.mockResolvedValue([makeExpandedUserSchema({ id: 1000, email: consoleUser.email, ...({ is_auditor: true } as any) })])
gitlabUsersAllMock.mockResolvedValue([
makeExpandedUserSchema({ id: 1000, email: consoleUser.email, is_auditor: true }),
])

await service.upsertUser({ ...gitlabUser, admin: true }, { cpnUserId: consoleUser.id })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export class GitlabClientService {
this.logger.verbose(`GitLab commit created (repoId=${repo.id}, ref=${ref}, actions=${actions.length})`)
}

async generateCreateOrUpdateAction(repo: CondensedProjectSchemaWith<'id'>, ref: string, filePath: string, content: string) {
async generateCreateOrUpdateAction(repo: CondensedProjectSchemaWith<'id'>, ref: string, filePath: string, content: string): Promise<CommitAction | null> {
const file = await this.getFile(repo, filePath, ref)
if (file && !hasFileContentChanged(file, content)) {
this.logger.debug(`GitLab file is up to date; skipping commit action (repoId=${repo.id}, ref=${ref}, filePath=${filePath})`)
Expand All @@ -306,7 +306,7 @@ export class GitlabClientService {
action: file ? 'update' : 'create',
filePath,
content,
} satisfies CommitAction
}
}

async listFiles(repo: CondensedProjectSchemaWith<'id'>, options: { path?: string, recursive?: boolean, ref?: string } = {}) {
Expand Down
6 changes: 6 additions & 0 deletions apps/server-nestjs/src/modules/healthz/healthz.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ArgoCDHealthService } from '../argocd/argocd-health.service'
import { GitlabHealthService } from '../gitlab/gitlab-health.service'
import { DatabaseHealthService } from '../infrastructure/database/database-health.service'
import { KeycloakHealthService } from '../keycloak/keycloak-health.service'
import { NexusHealthService } from '../nexus/nexus-health.service'
import { RegistryHealthService } from '../registry/registry-health.service'
import { VaultHealthService } from '../vault/vault-health.service'

@Controller('api/v1/healthz')
Expand All @@ -14,6 +16,8 @@ export class HealthzController {
@Inject(KeycloakHealthService) private readonly keycloak: KeycloakHealthService,
@Inject(GitlabHealthService) private readonly gitlab: GitlabHealthService,
@Inject(VaultHealthService) private readonly vault: VaultHealthService,
@Inject(NexusHealthService) private readonly nexus: NexusHealthService,
@Inject(RegistryHealthService) private readonly registry: RegistryHealthService,
@Inject(ArgoCDHealthService) private readonly argocd: ArgoCDHealthService,
) {}

Expand All @@ -25,6 +29,8 @@ export class HealthzController {
() => this.keycloak.check('keycloak'),
() => this.gitlab.check('gitlab'),
() => this.vault.check('vault'),
() => this.nexus.check('nexus'),
() => this.registry.check('registry'),
() => this.argocd.check('argocd'),
])
}
Expand Down
4 changes: 4 additions & 0 deletions apps/server-nestjs/src/modules/healthz/healthz.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { ArgoCDModule } from '../argocd/argocd.module'
import { GitlabModule } from '../gitlab/gitlab.module'
import { DatabaseModule } from '../infrastructure/database/database.module'
import { KeycloakModule } from '../keycloak/keycloak.module'
import { NexusModule } from '../nexus/nexus.module'
import { RegistryModule } from '../registry/registry.module'
import { VaultModule } from '../vault/vault.module'
import { HealthzController } from './healthz.controller'

Expand All @@ -14,6 +16,8 @@ import { HealthzController } from './healthz.controller'
KeycloakModule,
GitlabModule,
VaultModule,
NexusModule,
RegistryModule,
ArgoCDModule,
],
controllers: [HealthzController],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export class ConfigurationService {
harborAdminPassword = process.env.HARBOR_ADMIN_PASSWORD
harborRuleTemplate = process.env.HARBOR_RULE_TEMPLATE
harborRuleCount = process.env.HARBOR_RULE_COUNT
harborRetentionCron = process.env.HARBOR_RETENTION_CRON
harborRetentionCron = process.env.HARBOR_RETENTION_CRON ?? '0 22 2 * * *'
harborRobotRotationThresholdDays = Number(process.env.HARBOR_ROBOT_ROTATION_THRESHOLD_DAYS ?? 90)

// nexus
nexusUrl = process.env.NEXUS_URL
Expand Down
78 changes: 78 additions & 0 deletions apps/server-nestjs/src/modules/nexus/nexus-client.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { faker } from '@faker-js/faker'
import { Test } from '@nestjs/testing'
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { NexusClientService } from './nexus-client.service'
import { NexusHttpClientService } from './nexus-http-client.service'

const nexusUrl = 'https://nexus.internal'

const server = setupServer()
const nexusAdminPassword = faker.internet.password()
const basicAuth = `Basic ${Buffer.from(`admin:${nexusAdminPassword}`, 'utf8').toString('base64')}`

Check warning on line 14 in apps/server-nestjs/src/modules/nexus/nexus-client.service.spec.ts

View check run for this annotation

cloud-pi-native-sonarqube / SonarQube Code Analysis

apps/server-nestjs/src/modules/nexus/nexus-client.service.spec.ts#L14

Refactor this code to not use nested template literals.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Chuis un peu d'accord avec Sonarqube sur le principe, mais bon là c'est suffisament élémentaire pour ne pas être un problème


function createNexusServiceTestingModule() {
return Test.createTestingModule({
providers: [
NexusClientService,
NexusHttpClientService,
{
provide: ConfigurationService,
useValue: {
nexusSecretExposedUrl: 'https://nexus.example',
nexusInternalUrl: nexusUrl,
nexusAdmin: 'admin',
nexusAdminPassword,
projectRootDir: 'forge',
} satisfies Partial<ConfigurationService>,
},
],
})
}

describe('nexusClientService', () => {
let service: NexusClientService

beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))

beforeEach(async () => {
const module = await createNexusServiceTestingModule().compile()
service = module.get(NexusClientService)
})

afterEach(() => server.resetHandlers())
afterAll(() => server.close())

it('should be defined', () => {
expect(service).toBeDefined()
})

it('should return null on 404 (getRepositoriesMavenHosted)', async () => {
server.use(
http.get(`${nexusUrl}/service/rest/v1/repositories/maven/hosted/:name`, ({ request }) => {
expect(request.headers.get('authorization')).toBe(basicAuth)
return HttpResponse.json({}, { status: 404 })
}),
)

await expect(service.getRepositoriesMavenHosted('missing')).resolves.toBeNull()
})

it('should send basic auth and plain text body on change-password', async () => {
server.use(
http.put(`${nexusUrl}/service/rest/v1/security/users/:userId/change-password`, async ({ request, params }) => {
expect(request.method).toBe('PUT')
expect(request.url).toBe(`${nexusUrl}/service/rest/v1/security/users/u1/change-password`)
expect(params.userId).toBe('u1')
expect(request.headers.get('authorization')).toBe(basicAuth)
expect(request.headers.get('content-type')).toContain('text/plain')
expect(await request.text()).toBe('pw123')
return new HttpResponse(null, { status: 204 })
}),
)

await service.updateSecurityUsersChangePassword('u1', 'pw123')
})
})
Loading
Loading