Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: install of cucumber tests suite #24

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ jobs:
run: yarn test:ci
env:
REDIS_URL: redis://localhost:6767
IDP_MILO_CONSEILLER_AUTHORIZATION_URL: ${{ secrets.IDP_MILO_CONSEILLER_AUTHORIZATION_URL }}
IDP_MILO_CONSEILLER_CLIENT_ID: ${{ secrets.IDP_MILO_CONSEILLER_CLIENT_ID }}
IDP_MILO_CONSEILLER_CLIENT_SECRET: ${{ secrets.IDP_MILO_CONSEILLER_CLIENT_SECRET }}
IDP_MILO_CONSEILLER_ISSUER: ${{ secrets.IDP_MILO_CONSEILLER_ISSUER }}
IDP_MILO_CONSEILLER_JWKS: ${{ secrets.IDP_MILO_CONSEILLER_JWKS }}
IDP_MILO_CONSEILLER_REDIRECT_URI: ${{ secrets.IDP_MILO_CONSEILLER_REDIRECT_URI }}
IDP_MILO_CONSEILLER_SCOPES: ${{ secrets.IDP_MILO_CONSEILLER_SCOPES }}
IDP_MILO_CONSEILLER_TOKEN_URL: ${{ secrets.IDP_MILO_CONSEILLER_TOKEN_URL }}
IDP_MILO_CONSEILLER_USERINFO: ${{ secrets.IDP_MILO_CONSEILLER_USERINFO }}
TEST_MILO_CONSEILLER_OFFLINE_TOKEN: ${{ secrets.TEST_MILO_CONSEILLER_OFFLINE_TOKEN }}
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
Expand Down
2 changes: 1 addition & 1 deletion .vault

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions cucumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

module.exports = {
default: {
paths: ['test/integration/features/*.feature'],
requireModule: ['ts-node/register' /*'tsconfig-paths/register'*/],
require: ['test/integration/steps-definitions/*.ts']
}
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"cover:report": "nyc report --reporter=lcovonly",
"test": "yarn cover && yarn cover:report",
"test:ci": "nyc --reporter=lcovonly mocha 'test/**/*.test.ts' --exit --timeout 10000",
"test:cucumber": "cucumber-js",
"generate-key-pair": "node scripts/generate-key-pair.mjs",
"release:patch": "scripts/release-version.sh patch",
"release:minor": "scripts/release-version.sh minor",
Expand All @@ -33,12 +34,14 @@
"@nestjs/platform-express": "^10.3.2",
"@nestjs/schematics": "^10.1.0",
"@nestjs/swagger": "^7.3.0",
"@nestjs/terminus": "^10.2.3",
"@types/express": "^4.17.21",
"@types/luxon": "^3.4.2",
"@types/mocha": "^10.0.6",
"@types/node": "^20.11.16",
"@types/oidc-provider": "^8.4.4",
"@types/sanitize-html": "^2.11.0",
"@types/uuid": "^9.0.8",
"ioredis": "^5.3.2",
"joi": "^17.12.2",
"jose": "^5.2.4",
Expand All @@ -62,20 +65,24 @@
"uuid": "9.0.1"
},
"devDependencies": {
"@cucumber/cucumber": "^10.8.0",
"@cucumber/messages": "24.1.0",
"@cucumber/pretty-formatter": "^1.0.1",
"@nestjs/testing": "^10.3.8",
"@salesforce/ts-sinon": "^1.4.19",
"@swc/cli": "^0.3.9",
"@swc/core": "^1.4.0",
"@types/chai-as-promised": "^7.1.8",
"@types/dirty-chai": "^2.0.4",
"@types/sinon": "^17.0.3",
"@types/sinon-chai": "^3.2.12",
"@types/supertest": "^6.0.2",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"chai": "^4.4.1",
"chai-as-promised": "^7.1.2",
"chai-exclude": "^2.1.0",
"cucumber-tsflow": "^4.4.4",
"dirty-chai": "^2.0.1",
"dotvault": "^0.0.9",
"eslint": "^7.32.0",
Expand Down
9 changes: 9 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { Controller, Get } from '@nestjs/common'
import { HealthCheck, HealthCheckService } from '@nestjs/terminus'
import { HealthCheckResult } from '@nestjs/terminus/dist/health-check/health-check-result.interface'

@Controller()
export class AppController {
constructor(private health: HealthCheckService) {}

@Get()
getHello(): string {
return 'Hello world!'
}
@Get('health')
@HealthCheck()
check(): Promise<HealthCheckResult> {
return this.health.check([])
}
}
3 changes: 3 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { MiloConseillerModule } from './idp/milo-conseiller/milo-conseiller.module'
import { MiloJeuneModule } from './idp/milo-jeune/milo-jeune.module'
import { configureLoggerModule } from './logger.module'
import { TerminusModule } from '@nestjs/terminus'

@Module({
imports: [
Expand All @@ -15,6 +16,7 @@
cache: true,
load: [configuration]
}),
TerminusModule,
configureLoggerModule(),
FrancetravailJeuneModule,
FrancetravailConseillerModule,
Expand All @@ -23,4 +25,5 @@
],
controllers: [AppController]
})

Check failure on line 28 in src/app.module.ts

View workflow job for this annotation

GitHub Actions / test (20.11.0)

Delete `⏎`
export class AppModule {}
22 changes: 20 additions & 2 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
/* eslint-disable */
import * as Joi from 'joi'
import { configurationSchema } from './configuration.schema'
import { User } from '../domain/user'

type ClientIdentifier = 'web' | 'app' | 'api' | 'swagger'
type Client = Record<ClientIdentifier, unknown>
export enum IdpConfigIdentifier {
enum IdpConfigIdentifier {
MILO_CONSEILLER = 'miloConseiller',
MILO_JEUNE = 'miloJeune',
FT_CONSEILLER = 'francetravailConseiller',
FT_JEUNE = 'francetravailJeune'
}
export function getIdpConfigIdentifier(
type: User.Type,
structure: User.Structure
): IdpConfigIdentifier {
switch (structure) {
case User.Structure.MILO:
if (type === User.Type.JEUNE) return IdpConfigIdentifier.MILO_JEUNE
return IdpConfigIdentifier.MILO_CONSEILLER
case User.Structure.POLE_EMPLOI:
case User.Structure.POLE_EMPLOI_AIJ:
case User.Structure.POLE_EMPLOI_BRSA:
if (type === User.Type.JEUNE) return IdpConfigIdentifier.FT_JEUNE
return IdpConfigIdentifier.FT_CONSEILLER
}
}
export interface IdpConfig {
issuer: string
realm?: string
Expand Down Expand Up @@ -48,7 +64,9 @@ export default () => {
port: process.env.PORT ? parseInt(process.env.PORT, 10) : 5050,
publicAddress:
process.env.PUBLIC_ADDRESS ||
`http://localhost:${process.env.PORT ? parseInt(process.env.PORT, 10) : 5050}`,
`http://localhost:${
process.env.PORT ? parseInt(process.env.PORT, 10) : 5050
}`,
cors: {
allowedOrigins: process.env.CORS_ALLOWED_ORIGINS
? JSON.parse(process.env.CORS_ALLOWED_ORIGINS)
Expand Down
12 changes: 7 additions & 5 deletions src/idp/common/idp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ConfigService } from '@nestjs/config'
import { Request, Response } from 'express'
import { ClientAuthMethod, InteractionResults } from 'oidc-provider'
import { BaseClient, Issuer } from 'openid-client'
import { IdpConfig, IdpConfigIdentifier } from '../../config/configuration'
import { IdpConfig, getIdpConfigIdentifier } from '../../config/configuration'
import {
ContextKeyType,
ContextStorage
Expand All @@ -28,7 +28,6 @@ export abstract class IdpService {
idpName: string,
userType: User.Type,
userStructure: User.Structure,
idpConfigIdentifier: IdpConfigIdentifier,
private readonly contextStorage: ContextStorage,
private readonly configService: ConfigService,
private readonly oidcService: OidcService,
Expand All @@ -39,7 +38,10 @@ export abstract class IdpService {
this.idpName = idpName
this.userType = userType
this.userStructure = userStructure
this.idp = this.configService.get('idps')[idpConfigIdentifier]!
this.idp =
this.configService.get('idps')[
getIdpConfigIdentifier(userType, userStructure)
]!

const issuerConfig = {
issuer: this.idp.issuer,
Expand Down Expand Up @@ -107,7 +109,7 @@ export abstract class IdpService {
}
const accountId = Account.fromAccountToAccountId(account)

this.tokenService.setToken(account, 'access_token', {
await this.tokenService.setToken(account, 'access_token', {
token: tokenSet.access_token!,
expiresIn: tokenSet.expires_in || this.idp.accessTokenMaxAge,
scope: tokenSet.scope
Expand All @@ -117,7 +119,7 @@ export abstract class IdpService {
try {
refreshExpiresIn = tokenSet.refresh_expires_in as number
} catch (e) {}
this.tokenService.setToken(account, 'refresh_token', {
await this.tokenService.setToken(account, 'refresh_token', {
token: tokenSet.refresh_token,
expiresIn: refreshExpiresIn || this.idp.refreshTokenMaxAge,
scope: tokenSet.scope
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdpConfigIdentifier } from '../../config/configuration'
import { ContextStorage } from '../../context-storage/context-storage.provider'
import { User } from '../../domain/user'
import { OidcService } from '../../oidc-provider/oidc.service'
Expand All @@ -21,7 +20,6 @@ export class FrancetravailConseillerAIJService extends IdpService {
'FrancetravailConseillerAIJService',
User.Type.CONSEILLER,
User.Structure.POLE_EMPLOI_AIJ,
IdpConfigIdentifier.FT_CONSEILLER,
context,
configService,
oidcService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdpConfigIdentifier } from '../../config/configuration'
import { ContextStorage } from '../../context-storage/context-storage.provider'
import { User } from '../../domain/user'
import { OidcService } from '../../oidc-provider/oidc.service'
Expand All @@ -21,7 +20,6 @@ export class FrancetravailConseillerBRSAService extends IdpService {
'FrancetravailConseillerBRSAService',
User.Type.CONSEILLER,
User.Structure.POLE_EMPLOI_BRSA,
IdpConfigIdentifier.FT_CONSEILLER,
context,
configService,
oidcService,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdpConfigIdentifier } from '../../config/configuration'
import { ContextStorage } from '../../context-storage/context-storage.provider'
import { User } from '../../domain/user'
import { OidcService } from '../../oidc-provider/oidc.service'
Expand All @@ -21,7 +20,6 @@ export class FrancetravailConseillerCEJService extends IdpService {
'FrancetravailConseillerCEJService',
User.Type.CONSEILLER,
User.Structure.POLE_EMPLOI,
IdpConfigIdentifier.FT_CONSEILLER,
context,
configService,
oidcService,
Expand Down
2 changes: 0 additions & 2 deletions src/idp/francetravail-jeune/francetravail-aij.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdpConfigIdentifier } from '../../config/configuration'
import { ContextStorage } from '../../context-storage/context-storage.provider'
import { User } from '../../domain/user'
import { OidcService } from '../../oidc-provider/oidc.service'
Expand All @@ -21,7 +20,6 @@ export class FrancetravailAIJService extends IdpService {
'FrancetravailAIJService',
User.Type.JEUNE,
User.Structure.POLE_EMPLOI_AIJ,
IdpConfigIdentifier.FT_JEUNE,
context,
configService,
oidcService,
Expand Down
2 changes: 0 additions & 2 deletions src/idp/francetravail-jeune/francetravail-brsa.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdpConfigIdentifier } from '../../config/configuration'
import { ContextStorage } from '../../context-storage/context-storage.provider'
import { User } from '../../domain/user'
import { OidcService } from '../../oidc-provider/oidc.service'
Expand All @@ -21,7 +20,6 @@ export class FrancetravailBRSAService extends IdpService {
'FrancetravailBRSAService',
User.Type.JEUNE,
User.Structure.POLE_EMPLOI_BRSA,
IdpConfigIdentifier.FT_JEUNE,
context,
configService,
oidcService,
Expand Down
2 changes: 0 additions & 2 deletions src/idp/francetravail-jeune/francetravail-jeune.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdpConfigIdentifier } from '../../config/configuration'
import { ContextStorage } from '../../context-storage/context-storage.provider'
import { User } from '../../domain/user'
import { OidcService } from '../../oidc-provider/oidc.service'
Expand All @@ -21,7 +20,6 @@ export class FrancetravailJeuneCEJService extends IdpService {
'FrancetravailJeuneCEJService',
User.Type.JEUNE,
User.Structure.POLE_EMPLOI,
IdpConfigIdentifier.FT_JEUNE,
context,
configService,
oidcService,
Expand Down
2 changes: 0 additions & 2 deletions src/idp/milo-conseiller/milo-conseiller.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdpConfigIdentifier } from '../../config/configuration'
import { ContextStorage } from '../../context-storage/context-storage.provider'
import { User } from '../../domain/user'
import { OidcService } from '../../oidc-provider/oidc.service'
Expand All @@ -21,7 +20,6 @@ export class MiloConseillerService extends IdpService {
'MiloConseillerService',
User.Type.CONSEILLER,
User.Structure.MILO,
IdpConfigIdentifier.MILO_CONSEILLER,
context,
configService,
oidcService,
Expand Down
2 changes: 0 additions & 2 deletions src/idp/milo-jeune/milo-jeune.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Injectable } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { IdpConfigIdentifier } from '../../config/configuration'
import { ContextStorage } from '../../context-storage/context-storage.provider'
import { User } from '../../domain/user'
import { OidcService } from '../../oidc-provider/oidc.service'
Expand All @@ -21,7 +20,6 @@ export class MiloJeuneService extends IdpService {
'MiloJeuneService',
User.Type.JEUNE,
User.Structure.MILO,
IdpConfigIdentifier.MILO_JEUNE,
context,
configService,
oidcService,
Expand Down
8 changes: 6 additions & 2 deletions src/logger.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,16 @@ export const configureLoggerModule = (): DynamicModule =>

export interface LogError {
message: string
err: Error
err?: Error | string
}

export function buildError(message: string, error: Error): LogError {
return {
message,
err: error
err: isEnumerable(error) ? error : error.stack
}
}

function isEnumerable(error: Error): boolean {
return Boolean(Object.keys(error).length)
}
2 changes: 1 addition & 1 deletion src/oidc-provider/oidc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
client_id: clients.api.id,
client_secret: clients.api.secret,
grant_types: [tokenExchangeGrantType],
response_types: []
response_types: [],

Check failure on line 69 in src/oidc-provider/oidc.service.ts

View workflow job for this annotation

GitHub Actions / test (20.11.0)

Delete `,`
},
{
client_id: clients.web.id,
Expand Down
Loading
Loading