Skip to content

Commit

Permalink
feature/refactoring-test (#19)
Browse files Browse the repository at this point in the history
* Add coverage and add item.spec.ts

* Add more ignores path on jest.config and add other test on login

* Add users test,login and roles with some code changes

* Add syncRolePermissions command

* Add token blacklist and fix tests

* Add docker redis and change token blacklist with redis cache

* Fix when JWT is null

* Add rate limit request

* Fix 403 error on failed request payload
  • Loading branch information
Murzbul authored Dec 25, 2020
1 parent 9716f05 commit 1de37fd
Show file tree
Hide file tree
Showing 91 changed files with 2,930 additions and 388 deletions.
48 changes: 26 additions & 22 deletions config/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class Permissions

// AUTH
static readonly AUTH_KEEP_ALIVE: string = 'authKeepAlive';
static readonly AUTH_SYNC_PERMISSIONS: string = 'authSyncPermissions';
static readonly GET_PERMISSIONS: string = 'getPermissions';

// ITEMS
static readonly ITEMS_SAVE: string = 'itemsSave';
Expand Down Expand Up @@ -36,34 +38,36 @@ class Permissions
static readonly ROLES_LIST: string = 'rolesList';
static readonly ROLES_DELETE: string = 'rolesDelete';

static permissions(): object
static permissions(): string[]
{
return [
[Permissions.AUTH_KEEP_ALIVE],
`${Permissions.AUTH_KEEP_ALIVE}`,
`${Permissions.AUTH_SYNC_PERMISSIONS}`,
`${Permissions.GET_PERMISSIONS}`,

[Permissions.ITEMS_SAVE],
[Permissions.ITEMS_UPDATE],
[Permissions.ITEMS_SHOW],
[Permissions.ITEMS_LIST],
[Permissions.ITEMS_DELETE],
`${Permissions.ITEMS_SAVE}`,
`${Permissions.ITEMS_UPDATE}`,
`${Permissions.ITEMS_SHOW}`,
`${Permissions.ITEMS_LIST}`,
`${Permissions.ITEMS_DELETE}`,

[Permissions.USERS_SAVE],
[Permissions.USERS_UPDATE],
[Permissions.USERS_SHOW],
[Permissions.USERS_LIST],
[Permissions.USERS_DELETE],
[Permissions.USERS_CHANGE_MY_PASSWORD],
[Permissions.USERS_CHANGE_USER_PASSWORD],
`${Permissions.USERS_SAVE}`,
`${Permissions.USERS_UPDATE}`,
`${Permissions.USERS_SHOW}`,
`${Permissions.USERS_LIST}`,
`${Permissions.USERS_DELETE}`,
`${Permissions.USERS_CHANGE_MY_PASSWORD}`,
`${Permissions.USERS_CHANGE_USER_PASSWORD}`,

[Permissions.ROLES_SAVE],
[Permissions.ROLES_UPDATE],
[Permissions.ROLES_SHOW],
[Permissions.ROLES_LIST],
[Permissions.ROLES_DELETE],
`${Permissions.ROLES_SAVE}`,
`${Permissions.ROLES_UPDATE}`,
`${Permissions.ROLES_SHOW}`,
`${Permissions.ROLES_LIST}`,
`${Permissions.ROLES_DELETE}`,

[Permissions.FILES_UPLOAD],
[Permissions.FILES_UPDATE],
[Permissions.FILES_DOWNLOAD]
`${Permissions.FILES_UPLOAD}`,
`${Permissions.FILES_UPDATE}`,
`${Permissions.FILES_DOWNLOAD}`
];
}
}
Expand Down
1 change: 1 addition & 0 deletions config/Roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Roles
Permissions.ALL
],
[Roles.OPERATOR]: [
Permissions.USERS_CHANGE_MY_PASSWORD,
Permissions.ITEMS_SAVE,
Permissions.ITEMS_UPDATE,
Permissions.ITEMS_SHOW,
Expand Down
7 changes: 7 additions & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
},
"default" : "DB_TYPE_DEFAULT"
},
"cache": {
"redis": {
"port": "CACHE_PORT",
"host": "CACHE_HOST",
"password": "CACHE_PASSWORD"
}
},
"filesystem": {
"s3": {
"endPoint": "S3_HOST",
Expand Down
7 changes: 7 additions & 0 deletions config/development.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
},
"default": "Mongoose"
},
"cache": {
"redis": {
"port": 6379,
"host": "redis",
"password": "ewsua132435"
}
},
"filesystem": {
"s3": {
"type": "s3",
Expand Down
9 changes: 8 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
},
"default": "Mongoose"
},
"filesystem": {
"cache": {
"redis": {
"port": 6379,
"host": "redis",
"password": "ewsua132435"
}
},
"filesystem": {
"s3": {
"type": "s3",
"endPoint": "s3",
Expand Down
63 changes: 48 additions & 15 deletions config/test.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,65 @@
{
"env": "test",
"serverPort": 8089,
"auth": {
"authorization": true
},
"dbConfig": {
"typeORM": {
"type": "mongodb",
"TypeORM": {
"type": "postgres",
"host": "db",
"port": 27017,
"port": 5432,
"database": "experience",
"username": "experience",
"password": "experience",
"synchronize": true,
"migrationsRun": false,
"logging": true,
"entities": [
"./dist/src/Infrastructure/Entities/**/*.js"
"src/Infrastructure/Schema/TypeORM/*.ts"
],
"migrations": [
"./dist/src/Infrastructure/Migrations/**/*.js"
"src/Infrastructure/Migrations/TypeORM/**/*.ts"
],
"subscribers": [
"./dist/src/Infrastructure/Subscribers/**/*.js"
"src/Infrastructure/Subscribers/TypeORM/**/*.ts"
],
"cli": {
"entitiesDir": "./src/Infrastructure/Entities",
"migrationsDir": "./src/Infrastructure/Migrations",
"subscribersDir": "./src/Infrastructure/Subscribers"
"entitiesDir": "/src/Infrastructure/Entities/TypeORM",
"migrationsDir": "/src/Infrastructure/Migrations",
"subscribersDir": "/src/Infrastructure/Subscribers"
}
},
"default": "typeORM"
"Mongoose": {
"host": "db",
"port": 27017,
"database": "experience",
"username": "experience",
"password": "experience"
},
"default": "Mongoose"
},
"cache": {
"redis": {
"port": 6379,
"host": "redis",
"password": "ewsua132435"
}
},
"filesystem": {
"s3": {
"type": "s3",
"endPoint": "s3",
"accessKey": "minio",
"secretKey": "12345678",
"useSSL": false,
"port": 9000,
"bucket": "experience"
},
"local": {
"type": "local"
},
"default": "s3"
},
"encryption": {
"bcrypt": {
Expand All @@ -53,7 +85,12 @@
"password": "",
"secure": false,
"senderName": "Notifications",
"senderEmailDefault": "notification@localhost.com"
"senderEmailDefault": "notification@localhost.com",
"templateDir": "Infrastructure/templates/emails"
},
"push": {
"privateKey": "BFbzNLYCWO7Ei0cmBco43ZCsEbhFAOzcfop1eHYiK8CVCBK_-xeWEWzHHlQiPEUPvuxwMHc1koGj40t2hcgiWvk",
"publicKey": "k8sGjPBnD8iabMkB6toD8payp9plozw4t4FSfjhUPhQ"
},
"url":{
"urlApi": "http://localhost:8089/api/",
Expand Down Expand Up @@ -84,10 +121,6 @@
{
"method": ["POST"],
"url": "/api/auth/changeForgotPassword"
},
{
"method": ["POST"],
"url": "/api/users"
}
]
}
5 changes: 3 additions & 2 deletions dev.init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash

npx ts-node src/command.ts addUserRole --role Admin --email user@node.com --firstName node --lastName node --password 12345678 --isSuperAdmin false
npx ts-node src/command.ts addUserRole --role SuperAdmin --email superadmin@node.com --firstName super --lastName admin --password 12345678 --isSuperAdmin true
node dist/src/command.js addUserRole --role Admin --email user@node.com --firstName node --lastName node --password 12345678 --isSuperAdmin false
node dist/src/command.js addUserRole --role SuperAdmin --email superadmin@node.com --firstName super --lastName admin --password 12345678 --isSuperAdmin true
node dist/src/command.js syncRolesPermission
40 changes: 0 additions & 40 deletions docker-compose.test.yml

This file was deleted.

20 changes: 17 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
volumes:
- .:/usr/app:cached
ports:
- "8089:8089"
- 8089:8089
networks:
- experiencenet

Expand All @@ -23,7 +23,7 @@ services:
context: docker/mongo/
dockerfile: Dockerfile
ports:
- "27017:27017"
- 27017:27017
environment:
MONGODB_ROOT_PASSWORD: 123456
MONGODB_USERNAME: experience
Expand All @@ -48,7 +48,7 @@ services:
restart: always
image: minio/minio
ports:
- "9002:9000"
- 9002:9000
environment:
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: 12345678
Expand All @@ -58,6 +58,20 @@ services:
- experiencenet
command: server /data

redis:
image: bitnami/redis:latest
restart: always
container_name: experience_redis_1
environment:
- REDIS_PASSWORD=ewsua132435 # Security reasons
- DISABLE_COMMANDS=FLUSHDB,FLUSHALL,CONFIG # Security reasons
ports:
- 6379:6379
volumes:
- data:/bitnami/redis/data
networks:
- experiencenet

networks:
experiencenet:
driver: "bridge"
Expand Down
2 changes: 1 addition & 1 deletion infraestructure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Copy your keys ssh here.
Create a file called terraform.tfvars(like a .env file) with this data.
File terraform.tfvars

do_token="token-from-account-of-digital-ocean" FINGERPRINT="fingerprint-from-sshkey-in-digital-ocean"
do_token="createToken-from-account-of-digital-ocean" FINGERPRINT="fingerprint-from-sshkey-in-digital-ocean"
18 changes: 18 additions & 0 deletions infraestructure/firewall.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ resource "digitalocean_firewall" "experience" {
source_addresses = ["0.0.0.0/0", "::/0"]
}

inbound_rule {
protocol = "tcp"
port_range = "8089"
source_addresses = ["0.0.0.0/0", "::/0"]
}

inbound_rule {
protocol = "tcp"
port_range = "9002"
source_addresses = ["0.0.0.0/0", "::/0"]
}

inbound_rule {
protocol = "tcp"
port_range = "8027"
source_addresses = ["0.0.0.0/0", "::/0"]
}

outbound_rule {
protocol = "udp"
port_range = "53"
Expand Down
3 changes: 2 additions & 1 deletion infraestructure/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ cp /tmp/id_rsa /home/experience/.ssh/id_rsa
cp /tmp/id_rsa.pub /home/experience/.ssh/id_rsa.pub
cp /tmp/config /home/experience/.ssh/config

chmod 600 ~/.ssh/id_rsa
chmod 600 /home/experience/.ssh/id_rsa
chown -R experience:experience /home/experience/.ssh

Loading

0 comments on commit 1de37fd

Please sign in to comment.