fix enum values

This commit is contained in:
Gsk54 2023-01-25 18:13:26 +01:00
parent 02eae16665
commit d69423b342
8 changed files with 22 additions and 39 deletions

View File

@ -1,5 +1,5 @@
{
"name": "mobicoop-v3-auth",
"name": "@mobicoop/auth",
"version": "0.0.1",
"description": "Mobicoop V3 Auth Service",
"author": "sbriat",

View File

@ -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 {

View File

@ -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;

View File

@ -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',
}

View File

@ -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;

View File

@ -1,3 +1,3 @@
export enum Domain {
user = 'user',
USER = 'USER',
}

View File

@ -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(

View File

@ -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();