From d69423b3428b9d9318bb6fb97397279067a3a414 Mon Sep 17 00:00:00 2001 From: Gsk54 Date: Wed, 25 Jan 2023 18:13:26 +0100 Subject: [PATCH] fix enum values --- package.json | 2 +- .../adapters/primaries/authentication.proto | 9 ++------- .../adapters/primaries/authorization.proto | 16 ++-------------- .../authorization/domain/dtos/action.enum.ts | 10 +++++----- .../domain/dtos/decision.request.ts | 6 +++--- .../authorization/domain/dtos/domain.enum.ts | 2 +- .../tests/unit/decision.usecase.spec.ts | 4 ++-- .../tests/unit/opa.decision-maker.spec.ts | 12 ++++++------ 8 files changed, 22 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 5c02f7d..7591906 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "mobicoop-v3-auth", + "name": "@mobicoop/auth", "version": "0.0.1", "description": "Mobicoop V3 Auth Service", "author": "sbriat", diff --git a/src/modules/authentication/adapters/primaries/authentication.proto b/src/modules/authentication/adapters/primaries/authentication.proto index 42c9afc..9b16d3a 100644 --- a/src/modules/authentication/adapters/primaries/authentication.proto +++ b/src/modules/authentication/adapters/primaries/authentication.proto @@ -17,16 +17,11 @@ message AuthenticationByUsernamePassword { string password = 2; } -enum Type { - EMAIL = 0; - PHONE = 1; -} - message Authentication { string uuid = 1; string username = 2; string password = 3; - Type type = 4; + string type = 4; } message Password { @@ -37,7 +32,7 @@ message Password { message Username { string uuid = 1; string username = 2; - Type type = 3; + string type = 3; } message Uuid { diff --git a/src/modules/authorization/adapters/primaries/authorization.proto b/src/modules/authorization/adapters/primaries/authorization.proto index 6e9fc61..679febd 100644 --- a/src/modules/authorization/adapters/primaries/authorization.proto +++ b/src/modules/authorization/adapters/primaries/authorization.proto @@ -8,23 +8,11 @@ service AuthorizationService { message AuthorizationRequest { string uuid = 1; - Domain domain = 2; - Action action = 3; + string domain = 2; + string action = 3; repeated Item context = 4; } -enum Domain { - user = 0; -} - -enum Action { - create = 0; - read = 1; - update = 2; - delete = 3; - list = 4; -} - message Item { string name = 1; string value = 2; diff --git a/src/modules/authorization/domain/dtos/action.enum.ts b/src/modules/authorization/domain/dtos/action.enum.ts index 4a3955b..178455b 100644 --- a/src/modules/authorization/domain/dtos/action.enum.ts +++ b/src/modules/authorization/domain/dtos/action.enum.ts @@ -1,7 +1,7 @@ export enum Action { - create = 'create', - read = 'read', - update = 'update', - delete = 'delete', - list = 'list', + CREATE = 'CREATE', + READ = 'READ', + UPDATE = 'UPDATE', + DELETE = 'DELETE', + LIST = 'LIST', } diff --git a/src/modules/authorization/domain/dtos/decision.request.ts b/src/modules/authorization/domain/dtos/decision.request.ts index 2dfa6ea..adfe51b 100644 --- a/src/modules/authorization/domain/dtos/decision.request.ts +++ b/src/modules/authorization/domain/dtos/decision.request.ts @@ -1,4 +1,4 @@ -import { IsArray, IsNotEmpty, IsString } from 'class-validator'; +import { IsArray, IsEnum, IsNotEmpty, IsString } from 'class-validator'; import { ContextItem } from './context-item'; import { Action } from './action.enum'; import { Domain } from './domain.enum'; @@ -8,11 +8,11 @@ export class DecisionRequest { @IsNotEmpty() uuid: string; - @IsString() + @IsEnum(Domain) @IsNotEmpty() domain: Domain; - @IsString() + @IsEnum(Action) @IsNotEmpty() action: Action; diff --git a/src/modules/authorization/domain/dtos/domain.enum.ts b/src/modules/authorization/domain/dtos/domain.enum.ts index 6cb9b92..9d09c7d 100644 --- a/src/modules/authorization/domain/dtos/domain.enum.ts +++ b/src/modules/authorization/domain/dtos/domain.enum.ts @@ -1,3 +1,3 @@ export enum Domain { - user = 'user', + USER = 'USER', } diff --git a/src/modules/authorization/tests/unit/decision.usecase.spec.ts b/src/modules/authorization/tests/unit/decision.usecase.spec.ts index ce6cc23..7d647da 100644 --- a/src/modules/authorization/tests/unit/decision.usecase.spec.ts +++ b/src/modules/authorization/tests/unit/decision.usecase.spec.ts @@ -41,8 +41,8 @@ describe('DecisionUseCase', () => { it('should validate an authorization', async () => { const decisionRequest: DecisionRequest = new DecisionRequest(); decisionRequest.uuid = 'bb281075-1b98-4456-89d6-c643d3044a91'; - decisionRequest.domain = Domain.user; - decisionRequest.action = Action.create; + decisionRequest.domain = Domain.USER; + decisionRequest.action = Action.CREATE; decisionRequest.context = [new ContextItem('context1', 'value1')]; expect( decisionUseCase.execute( diff --git a/src/modules/authorization/tests/unit/opa.decision-maker.spec.ts b/src/modules/authorization/tests/unit/opa.decision-maker.spec.ts index 52c85e2..40cdedd 100644 --- a/src/modules/authorization/tests/unit/opa.decision-maker.spec.ts +++ b/src/modules/authorization/tests/unit/opa.decision-maker.spec.ts @@ -72,8 +72,8 @@ describe('OpaDecisionMaker', () => { it('should return a truthy authorization', async () => { const authorization = await opaDecisionMaker.decide( 'bb281075-1b98-4456-89d6-c643d3044a91', - Domain.user, - Action.read, + Domain.USER, + Action.READ, [], ); expect(authorization.allow).toBeTruthy(); @@ -81,8 +81,8 @@ describe('OpaDecisionMaker', () => { it('should return a falsy authorization', async () => { const authorization = await opaDecisionMaker.decide( 'bb281075-1b98-4456-89d6-c643d3044a91', - Domain.user, - Action.read, + Domain.USER, + Action.READ, [], ); expect(authorization.allow).toBeFalsy(); @@ -90,8 +90,8 @@ describe('OpaDecisionMaker', () => { it('should return a falsy authorization when an error happens', async () => { const authorization = await opaDecisionMaker.decide( 'bb281075-1b98-4456-89d6-c643d3044a91', - Domain.user, - Action.read, + Domain.USER, + Action.READ, [], ); expect(authorization.allow).toBeFalsy();