Merge branch 'fixEnums' into 'main'
fix enum values See merge request v3/services/auth!7
This commit is contained in:
commit
ee820a2e84
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"name": "mobicoop-v3-auth",
|
"name": "@mobicoop/auth",
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"description": "Mobicoop V3 Auth Service",
|
"description": "Mobicoop V3 Auth Service",
|
||||||
"author": "sbriat",
|
"author": "sbriat",
|
||||||
|
|
|
@ -17,16 +17,11 @@ message AuthenticationByUsernamePassword {
|
||||||
string password = 2;
|
string password = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Type {
|
|
||||||
EMAIL = 0;
|
|
||||||
PHONE = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Authentication {
|
message Authentication {
|
||||||
string uuid = 1;
|
string uuid = 1;
|
||||||
string username = 2;
|
string username = 2;
|
||||||
string password = 3;
|
string password = 3;
|
||||||
Type type = 4;
|
string type = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Password {
|
message Password {
|
||||||
|
@ -37,7 +32,7 @@ message Password {
|
||||||
message Username {
|
message Username {
|
||||||
string uuid = 1;
|
string uuid = 1;
|
||||||
string username = 2;
|
string username = 2;
|
||||||
Type type = 3;
|
string type = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Uuid {
|
message Uuid {
|
||||||
|
|
|
@ -8,23 +8,11 @@ service AuthorizationService {
|
||||||
|
|
||||||
message AuthorizationRequest {
|
message AuthorizationRequest {
|
||||||
string uuid = 1;
|
string uuid = 1;
|
||||||
Domain domain = 2;
|
string domain = 2;
|
||||||
Action action = 3;
|
string action = 3;
|
||||||
repeated Item context = 4;
|
repeated Item context = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Domain {
|
|
||||||
user = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum Action {
|
|
||||||
create = 0;
|
|
||||||
read = 1;
|
|
||||||
update = 2;
|
|
||||||
delete = 3;
|
|
||||||
list = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Item {
|
message Item {
|
||||||
string name = 1;
|
string name = 1;
|
||||||
string value = 2;
|
string value = 2;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
export enum Action {
|
export enum Action {
|
||||||
create = 'create',
|
CREATE = 'CREATE',
|
||||||
read = 'read',
|
READ = 'READ',
|
||||||
update = 'update',
|
UPDATE = 'UPDATE',
|
||||||
delete = 'delete',
|
DELETE = 'DELETE',
|
||||||
list = 'list',
|
LIST = 'LIST',
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 { ContextItem } from './context-item';
|
||||||
import { Action } from './action.enum';
|
import { Action } from './action.enum';
|
||||||
import { Domain } from './domain.enum';
|
import { Domain } from './domain.enum';
|
||||||
|
@ -8,11 +8,11 @@ export class DecisionRequest {
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
uuid: string;
|
uuid: string;
|
||||||
|
|
||||||
@IsString()
|
@IsEnum(Domain)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
domain: Domain;
|
domain: Domain;
|
||||||
|
|
||||||
@IsString()
|
@IsEnum(Action)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
action: Action;
|
action: Action;
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
export enum Domain {
|
export enum Domain {
|
||||||
user = 'user',
|
USER = 'USER',
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,8 @@ describe('DecisionUseCase', () => {
|
||||||
it('should validate an authorization', async () => {
|
it('should validate an authorization', async () => {
|
||||||
const decisionRequest: DecisionRequest = new DecisionRequest();
|
const decisionRequest: DecisionRequest = new DecisionRequest();
|
||||||
decisionRequest.uuid = 'bb281075-1b98-4456-89d6-c643d3044a91';
|
decisionRequest.uuid = 'bb281075-1b98-4456-89d6-c643d3044a91';
|
||||||
decisionRequest.domain = Domain.user;
|
decisionRequest.domain = Domain.USER;
|
||||||
decisionRequest.action = Action.create;
|
decisionRequest.action = Action.CREATE;
|
||||||
decisionRequest.context = [new ContextItem('context1', 'value1')];
|
decisionRequest.context = [new ContextItem('context1', 'value1')];
|
||||||
expect(
|
expect(
|
||||||
decisionUseCase.execute(
|
decisionUseCase.execute(
|
||||||
|
|
|
@ -72,8 +72,8 @@ describe('OpaDecisionMaker', () => {
|
||||||
it('should return a truthy authorization', async () => {
|
it('should return a truthy authorization', async () => {
|
||||||
const authorization = await opaDecisionMaker.decide(
|
const authorization = await opaDecisionMaker.decide(
|
||||||
'bb281075-1b98-4456-89d6-c643d3044a91',
|
'bb281075-1b98-4456-89d6-c643d3044a91',
|
||||||
Domain.user,
|
Domain.USER,
|
||||||
Action.read,
|
Action.READ,
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
expect(authorization.allow).toBeTruthy();
|
expect(authorization.allow).toBeTruthy();
|
||||||
|
@ -81,8 +81,8 @@ describe('OpaDecisionMaker', () => {
|
||||||
it('should return a falsy authorization', async () => {
|
it('should return a falsy authorization', async () => {
|
||||||
const authorization = await opaDecisionMaker.decide(
|
const authorization = await opaDecisionMaker.decide(
|
||||||
'bb281075-1b98-4456-89d6-c643d3044a91',
|
'bb281075-1b98-4456-89d6-c643d3044a91',
|
||||||
Domain.user,
|
Domain.USER,
|
||||||
Action.read,
|
Action.READ,
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
expect(authorization.allow).toBeFalsy();
|
expect(authorization.allow).toBeFalsy();
|
||||||
|
@ -90,8 +90,8 @@ describe('OpaDecisionMaker', () => {
|
||||||
it('should return a falsy authorization when an error happens', async () => {
|
it('should return a falsy authorization when an error happens', async () => {
|
||||||
const authorization = await opaDecisionMaker.decide(
|
const authorization = await opaDecisionMaker.decide(
|
||||||
'bb281075-1b98-4456-89d6-c643d3044a91',
|
'bb281075-1b98-4456-89d6-c643d3044a91',
|
||||||
Domain.user,
|
Domain.USER,
|
||||||
Action.read,
|
Action.READ,
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
expect(authorization.allow).toBeFalsy();
|
expect(authorization.allow).toBeFalsy();
|
||||||
|
|
Loading…
Reference in New Issue