Skip to content

Commit

Permalink
Version 2.0.2
Browse files Browse the repository at this point in the history
Version 2.0.2
  • Loading branch information
DonVietnam authored Sep 11, 2022
2 parents b1f380b + a4a30cb commit 1c2e5b9
Show file tree
Hide file tree
Showing 32 changed files with 1,309 additions and 952 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ on:
- opened
- edited
- reopened
- closed
- synchronize
- converted_to_draft
- ready_for_review
- locked
- unlocked
- review_requested
- review_request
branches: [ master ]
workflow_dispatch:
jobs:
Expand All @@ -20,3 +28,9 @@ jobs:
run: npm i
- run: npm run lint
- run: npm run test
- run: npm run docker
- run: npm install -g forever
- run: PGHOST=localhost PGUSER=test_user PGDATABASE=test_db PGPASSWORD=test_password PGPORT=5432 forever start ./src/index.js
- run: docker ps -a
- run: npm run integration
- run: forever stopall
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [2.0.1] - 2022-09-08

### Added

- Integration tests for Auth module.

### Changed

- Fix bug when Auth.login method crashed when no user found in database.
- Fix bug when user could change password for every another user with Auth.changePassword method.
- Set minimum username length to 2 and minimum password length to 8 in Auth module.
- Split tests into Unit and Integration tests.

## [2.0.1] - 2022-09-08

### Changed

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

[unreleased]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.1...master
[unreleased]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.2...master
[2.0.2]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/web-soft-llc/web-soft-server/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/web-soft-llc/web-soft-server/compare/v.1.0.2...v2.0.0
[1.0.2]: https://github.com/web-soft-llc/web-soft-server/compare/v.1.0.1...v.1.0.2
Expand Down
11 changes: 5 additions & 6 deletions lib/auth-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ module.exports = {
properties: {
username: {
type: 'string',
minLength: 2,
description: 'Имя пользователя.'
},
password: {
description: 'Пароль.',
minLength: 8,
type: 'string'
}
}
Expand Down Expand Up @@ -103,19 +105,16 @@ module.exports = {
public: false,
description: 'Смена пароля текущего пользователя.',
params: {
required: ['username', 'oldPassword', 'newPassword'],
required: ['oldPassword', 'newPassword'],
properties: {
username: {
description: 'Имя пользователя.',
type: 'string'
},
oldPassword: {
description: 'Старый пароль.',
type: 'string'
},
newPassword: {
description: 'Новый пароль.',
type: 'string'
type: 'string',
minLength: 8
}
}
},
Expand Down
8 changes: 4 additions & 4 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Auth {
const session = context.session;
if (session.username !== username) {
const user = await userService.getByUsername(username);
if (await security.validatePassword(password, user.password)) {
if (user.password && (await security.validatePassword(password, user.password))) {
await context.startSession(user);
} else {
throw new ConnectionError(ERRORS.AUTHENTICATION_FAILED);
Expand All @@ -33,12 +33,12 @@ class Auth {
return { username, role, createdTime };
}

async changePassword({ username, oldPassword, newPassword }, context) {
async changePassword({ oldPassword, newPassword }, context) {
const user = await context.user;
if (await security.validatePassword(oldPassword, user.password)) {
const newHashPassword = await security.hashPassword(newPassword);
await userService.updatePassword(username, newHashPassword);
return { username, role: user.role, createdTime: user.createdTime };
await userService.updatePassword(user.username, newHashPassword);
return { username: user.username, role: user.role, createdTime: user.createdTime };
} else {
throw new ConnectionError(ERRORS.AUTHENTICATION_FAILED);
}
Expand Down
60 changes: 47 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "DonVietnam",
"email": "[email protected]"
},
"version": "2.0.1",
"version": "2.0.2",
"description": "Server for web-soft-projects.",
"license": "MIT",
"keywords": [
Expand Down Expand Up @@ -37,16 +37,19 @@
"start": "node index.js",
"dev": "nodemon --signal SIGTERM --exec \"node src/index.js\"",
"dev-docker": "docker volume create pgdata && docker compose up -d && npm run dev",
"docker": "docker volume create pgdata && docker compose up -d",
"certs": "bash ./certs.sh",
"lint": "eslint --ignore-path .eslintignore .",
"fix": "eslint --fix --ignore-path .eslintignore .",
"test": "jest test"
"test": "jest test/unit",
"integration": "cross-env PGHOST=localhost PGUSER=test_user PGDATABASE=test_db PGPASSWORD=test_password PGPORT=5432 HOST=localhost PORT=8000 jest test/integration"
},
"engines": {
"node": ">=16"
},
"devDependencies": {
"@types/node": "^16.11.7",
"cross-env": "^7.0.3",
"eslint": "^7.8.1",
"eslint-config-prettier": "^8.3.0",
"jest": "^27.3.1",
Expand Down
6 changes: 1 addition & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const fs = require('fs');
const { Server, logger, AuthModule } = require('../index');
const modules = require('./modules');

const key = fs.readFileSync('./certs/localhost.key');
const cert = fs.readFileSync('./certs/localhost.crt');

const start = async () => {
try {
const server = new Server({ host: '0.0.0.0', port: 443, cors: false, key, cert, secure: true });
const server = new Server({ host: '0.0.0.0', port: 8000, cors: false });
server.start({ ...modules, auth: AuthModule });
} catch (error) {
logger.fatal(error);
Expand Down
Loading

0 comments on commit 1c2e5b9

Please sign in to comment.