Skip to content

Commit

Permalink
Added changes to fix code duplication issues and security flaws
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Mario committed Apr 14, 2024
1 parent 257db61 commit 57b44f3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 0 additions & 2 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ describe('Gateway Service with token mock', () => {
it('should forward record request to record service', async () => {
const response = await request(app)
.get('/record/testuser').set('token', 'valorDelToken');
console.log(response)
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('record', "undefined");
});
Expand All @@ -113,7 +112,6 @@ describe('Gateway Service without token mock', () => {
it('should not verify the token', async () => {
const response = await request(app)
.get('/record/testuser');
console.log(response)
expect(response.statusCode).toBe(200);
expect(response.body).toHaveProperty('record', "undefined");
});
Expand Down
4 changes: 3 additions & 1 deletion users/authservice/auth-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ app.post('/login', async (req, res) => {
return
}

const { email, username, password } = req.body;
const email = req.body.email.toString();
const username = req.body.username.toString();
const password = req.body.password.toString();

let user;
if(username) //Can log in with both

Check failure

Code scanning / SonarCloud

NoSQL operations should not be vulnerable to injection attacks High

Change this code to not construct database queries directly from user-controlled data. See more on SonarCloud
Expand Down
4 changes: 2 additions & 2 deletions users/userservice/user-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ app.post('/adduser', async (req, res) => {
}

//Check there is not a user with the same name
const userUsername = await User.findOne({username: req.body.username});
const userUsername = await User.findOne({username: req.body.username.toString()});

//Check there is not a user with the same name
const userEmail = await User.findOne({email: req.body.email});
const userEmail = await User.findOne({email: req.body.email.toString()});

Check failure

Code scanning / SonarCloud

NoSQL operations should not be vulnerable to injection attacks High

Change this code to not construct database queries directly from user-controlled data. See more on SonarCloud

if(userUsername)
return res.status(400).json({error : "Username already in use"})
Expand Down
4 changes: 2 additions & 2 deletions users/userservice/user-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('User Service', () => {
const newUser = {
email: '[email protected]',
username: 'testuser',
password: 'testpassword'
password: 'test'
};

const response = await request(app).post('/adduser').send(newUser);
Expand All @@ -53,7 +53,7 @@ describe('User Service', () => {
const newUser = {
email: '[email protected]',
username: 'testuser2',
password: 'testpassword'
password: 'password'
};

const response = await request(app).post('/adduser').send(newUser);
Expand Down

0 comments on commit 57b44f3

Please sign in to comment.