Skip to content

Commit

Permalink
891 be sso implement blocked user status functionality (#1042)
Browse files Browse the repository at this point in the history
* implementing blocked user status functionallity

* changelog and version updated

* updated config dev service version

* fixing conflict

* fixing prettier error

* dni of the blockedUser test fixed

* Update login.test.ts

* Update login.test.ts

* added middleware functionality

* Update validate.test.ts

* update users/getMe and dashboard/users/list

* fixing minor tests issues

* console log deleted

---------

Co-authored-by: roche-tan <rochelyn.rallestan@gmail.com>
  • Loading branch information
MiguelKummetz and roche-tan authored Mar 14, 2024
1 parent c2023f6 commit 571c712
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 208 deletions.
6 changes: 6 additions & 0 deletions services/sso/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [1.16.0] - 2024-03-12

### Added

- User `Blocked` status functionality

## [1.15.1] - 2024-03-07

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion services/sso/db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ BEGIN
CREATE TYPE USER_ROLE AS ENUM ('ADMIN', 'REGISTERED', 'MENTOR');
END IF;
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'user_status') THEN
CREATE TYPE USER_STATUS AS ENUM ('ACTIVE', 'INACTIVE');
CREATE TYPE USER_STATUS AS ENUM ('ACTIVE', 'INACTIVE', 'BLOCKED');
END IF;
END
$$;
Expand Down
3 changes: 3 additions & 0 deletions services/sso/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ paths:
enum:
- ACTIVE
- INACTIVE
- BLOCKED
itineraryId:
type: string
required:
Expand Down Expand Up @@ -635,6 +636,7 @@ paths:
enum:
- ACTIVE
- INACTIVE
- BLOCKED
required: false
description: Status to filter by
example: ACTIVE
Expand Down Expand Up @@ -685,6 +687,7 @@ paths:
enum:
- ACTIVE
- INACTIVE
- BLOCKED
createdAt:
type: string
example: 21/02/2024
Expand Down
4 changes: 2 additions & 2 deletions services/sso/package-lock.json

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

2 changes: 1 addition & 1 deletion services/sso/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sso-service",
"version": "1.15.1",
"version": "1.16.0",
"description": "",
"directories": {
"test": "test"
Expand Down
71 changes: 35 additions & 36 deletions services/sso/src/__tests__/auth/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,69 @@ import { server, testUserData } from '../globalSetup'
import { pathRoot } from '../../routes/routes'
import { tokenSchema } from '../../schemas/tokens/tokenSchema'

const route = `${pathRoot.v1.auth}/login`

describe('Testing authentication endpoint', () => {
it('should succeed with correct credentials', async () => {
const response = await supertest(server)
.post(`${pathRoot.v1.auth}/login`)
.send({
dni: testUserData.admin.dni,
password: testUserData.admin.password,
})
const response = await supertest(server).post(route).send({
dni: testUserData.admin.dni,
password: testUserData.admin.password,
})
expect(response.status).toBe(200)
expect(tokenSchema.safeParse(response.body).success).toBeTruthy()
})

it('should succeed with correct credentials and uppercase DNI', async () => {
const response = await supertest(server)
.post(`${pathRoot.v1.auth}/login`)
.send({
dni: testUserData.admin.dni.toUpperCase(),
password: testUserData.admin.password,
})
const response = await supertest(server).post(route).send({
dni: testUserData.admin.dni.toUpperCase(),
password: testUserData.admin.password,
})
expect(response.status).toBe(200)
expect(tokenSchema.safeParse(response.body).success).toBeTruthy()
})

it('should succeed with correct credentials and lowercase DNI', async () => {
const response = await supertest(server)
.post(`${pathRoot.v1.auth}/login`)
.send({
dni: testUserData.admin.dni.toLowerCase(),
password: testUserData.admin.password,
})
const response = await supertest(server).post(route).send({
dni: testUserData.admin.dni.toLowerCase(),
password: testUserData.admin.password,
})
expect(response.status).toBe(200)
expect(tokenSchema.safeParse(response.body).success).toBeTruthy()
})

it('should fail with incorrect password', async () => {
const response = await supertest(server)
.post(`${pathRoot.v1.auth}/login`)
.send({
dni: testUserData.admin.dni,
password: 'wrong password',
})
const response = await supertest(server).post(route).send({
dni: testUserData.admin.dni,
password: 'wrong password',
})
expect(response.status).toBe(401)
expect(response.body.message).toBe('Invalid Credentials')
})

it('should fail with user not found', async () => {
const response = await supertest(server)
.post(`${pathRoot.v1.auth}/login`)
.send({
dni: '92149467J',
password: 'password1',
})
const response = await supertest(server).post(route).send({
dni: '92149467J',
password: 'password1',
})
expect(response.status).toBe(401)
expect(response.body.message).toBe('Invalid Credentials')
})
})

it('should fail if user not active', async () => {
const response = await supertest(server)
.post(`${pathRoot.v1.auth}/login`)
.send({
dni: testUserData.inactiveUser.dni,
password: testUserData.inactiveUser.password,
})
const response = await supertest(server).post(route).send({
dni: testUserData.inactiveUser.dni,
password: testUserData.inactiveUser.password,
})
expect(response.status).toBe(403)
expect(response.body.message).toBe('Only active users can login')
})

it('should fail if user is blocked', async () => {
const response = await supertest(server).post(route).send({
dni: testUserData.blockedUser.dni,
password: testUserData.blockedUser.password,
})
expect(response.status).toBe(403)
expect(response.body.message).toBe('The user is Blocked')
})
Loading

0 comments on commit 571c712

Please sign in to comment.