Skip to content

Commit 1c2e5b9

Browse files
authored
Version 2.0.2
Version 2.0.2
2 parents b1f380b + a4a30cb commit 1c2e5b9

32 files changed

+1309
-952
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ on:
55
- opened
66
- edited
77
- reopened
8+
- closed
9+
- synchronize
10+
- converted_to_draft
11+
- ready_for_review
12+
- locked
13+
- unlocked
14+
- review_requested
15+
- review_request
816
branches: [ master ]
917
workflow_dispatch:
1018
jobs:
@@ -20,3 +28,9 @@ jobs:
2028
run: npm i
2129
- run: npm run lint
2230
- run: npm run test
31+
- run: npm run docker
32+
- run: npm install -g forever
33+
- run: PGHOST=localhost PGUSER=test_user PGDATABASE=test_db PGPASSWORD=test_password PGPORT=5432 forever start ./src/index.js
34+
- run: docker ps -a
35+
- run: npm run integration
36+
- run: forever stopall

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [2.0.1] - 2022-09-08
1111

12+
### Added
13+
14+
- Integration tests for Auth module.
15+
16+
### Changed
17+
18+
- Fix bug when Auth.login method crashed when no user found in database.
19+
- Fix bug when user could change password for every another user with Auth.changePassword method.
20+
- Set minimum username length to 2 and minimum password length to 8 in Auth module.
21+
- Split tests into Unit and Integration tests.
22+
23+
## [2.0.1] - 2022-09-08
24+
1225
### Changed
1326

1427
- Fix bug when SessionService.restoreSession method pass empty token to database.
@@ -68,7 +81,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6881
- Logger service.
6982
- Introspection module.
7083

71-
[unreleased]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.1...master
84+
[unreleased]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.2...master
85+
[2.0.2]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.1...v2.0.2
7286
[2.0.1]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.0...v2.0.1
7387
[2.0.0]: https://github.com/web-soft-llc/web-soft-server/compare/v.1.0.2...v2.0.0
7488
[1.0.2]: https://github.com/web-soft-llc/web-soft-server/compare/v.1.0.1...v.1.0.2

lib/auth-module.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ module.exports = {
1111
properties: {
1212
username: {
1313
type: 'string',
14+
minLength: 2,
1415
description: 'Имя пользователя.'
1516
},
1617
password: {
1718
description: 'Пароль.',
19+
minLength: 8,
1820
type: 'string'
1921
}
2022
}
@@ -103,19 +105,16 @@ module.exports = {
103105
public: false,
104106
description: 'Смена пароля текущего пользователя.',
105107
params: {
106-
required: ['username', 'oldPassword', 'newPassword'],
108+
required: ['oldPassword', 'newPassword'],
107109
properties: {
108-
username: {
109-
description: 'Имя пользователя.',
110-
type: 'string'
111-
},
112110
oldPassword: {
113111
description: 'Старый пароль.',
114112
type: 'string'
115113
},
116114
newPassword: {
117115
description: 'Новый пароль.',
118-
type: 'string'
116+
type: 'string',
117+
minLength: 8
119118
}
120119
}
121120
},

lib/auth.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Auth {
1515
const session = context.session;
1616
if (session.username !== username) {
1717
const user = await userService.getByUsername(username);
18-
if (await security.validatePassword(password, user.password)) {
18+
if (user.password && (await security.validatePassword(password, user.password))) {
1919
await context.startSession(user);
2020
} else {
2121
throw new ConnectionError(ERRORS.AUTHENTICATION_FAILED);
@@ -33,12 +33,12 @@ class Auth {
3333
return { username, role, createdTime };
3434
}
3535

36-
async changePassword({ username, oldPassword, newPassword }, context) {
36+
async changePassword({ oldPassword, newPassword }, context) {
3737
const user = await context.user;
3838
if (await security.validatePassword(oldPassword, user.password)) {
3939
const newHashPassword = await security.hashPassword(newPassword);
40-
await userService.updatePassword(username, newHashPassword);
41-
return { username, role: user.role, createdTime: user.createdTime };
40+
await userService.updatePassword(user.username, newHashPassword);
41+
return { username: user.username, role: user.role, createdTime: user.createdTime };
4242
} else {
4343
throw new ConnectionError(ERRORS.AUTHENTICATION_FAILED);
4444
}

package-lock.json

Lines changed: 47 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "DonVietnam",
55
"email": "don.vietnam.js@gmail.com"
66
},
7-
"version": "2.0.1",
7+
"version": "2.0.2",
88
"description": "Server for web-soft-projects.",
99
"license": "MIT",
1010
"keywords": [
@@ -37,16 +37,19 @@
3737
"start": "node index.js",
3838
"dev": "nodemon --signal SIGTERM --exec \"node src/index.js\"",
3939
"dev-docker": "docker volume create pgdata && docker compose up -d && npm run dev",
40+
"docker": "docker volume create pgdata && docker compose up -d",
4041
"certs": "bash ./certs.sh",
4142
"lint": "eslint --ignore-path .eslintignore .",
4243
"fix": "eslint --fix --ignore-path .eslintignore .",
43-
"test": "jest test"
44+
"test": "jest test/unit",
45+
"integration": "cross-env PGHOST=localhost PGUSER=test_user PGDATABASE=test_db PGPASSWORD=test_password PGPORT=5432 HOST=localhost PORT=8000 jest test/integration"
4446
},
4547
"engines": {
4648
"node": ">=16"
4749
},
4850
"devDependencies": {
4951
"@types/node": "^16.11.7",
52+
"cross-env": "^7.0.3",
5053
"eslint": "^7.8.1",
5154
"eslint-config-prettier": "^8.3.0",
5255
"jest": "^27.3.1",

src/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
const fs = require('fs');
21
const { Server, logger, AuthModule } = require('../index');
32
const modules = require('./modules');
43

5-
const key = fs.readFileSync('./certs/localhost.key');
6-
const cert = fs.readFileSync('./certs/localhost.crt');
7-
84
const start = async () => {
95
try {
10-
const server = new Server({ host: '0.0.0.0', port: 443, cors: false, key, cert, secure: true });
6+
const server = new Server({ host: '0.0.0.0', port: 8000, cors: false });
117
server.start({ ...modules, auth: AuthModule });
128
} catch (error) {
139
logger.fatal(error);

0 commit comments

Comments
 (0)