generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1086/security issues verified (#1521)
* add verification check before mutations * remove log * cleanup unused imports * update tests * update Update and Read tests * move vble to env file * undo secret removal --------- Co-authored-by: Brad <[email protected]> Co-authored-by: Trillium S <[email protected]>
- Loading branch information
1 parent
942b871
commit 3556bae
Showing
9 changed files
with
152 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,58 @@ | ||
const supertest = require('supertest'); | ||
const app = require('../app'); | ||
const request = supertest(app); | ||
const jwt = require('jsonwebtoken'); | ||
const { CONFIG_AUTH } = require('../config'); | ||
|
||
|
||
const { setupDB } = require('../setup-test'); | ||
setupDB('api-projects'); | ||
|
||
const { Project } = require('../models'); | ||
const { Project, User } = require('../models'); | ||
const CONFIG = require('../config/auth.config'); | ||
|
||
const headers = {}; | ||
headers['x-customrequired-header'] = CONFIG.CUSTOM_REQUEST_HEADER; | ||
headers.Accept = 'application/json'; | ||
headers.authorization = 'Bearer sometoken'; | ||
|
||
let token; | ||
|
||
|
||
describe('CREATE', () => { | ||
beforeAll( async () => { | ||
const submittedData = { | ||
name: { | ||
firstName: 'test', | ||
lastName: 'user', | ||
}, | ||
email: '[email protected]', | ||
}; | ||
const user = await User.create(submittedData); | ||
const auth_origin = 'TEST'; | ||
token = jwt.sign( | ||
{ id: user.id, role: user.accessLevel, auth_origin }, | ||
CONFIG_AUTH.SECRET, | ||
{ | ||
expiresIn: `${CONFIG_AUTH.TOKEN_EXPIRATION_SEC}s`, | ||
}, | ||
); | ||
}) | ||
test('Create a Project with POST to /api/projects/ without token', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
}; | ||
|
||
// Submit a project | ||
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.send(submittedData); | ||
expect(res.status).toBe(401); | ||
done(); | ||
}); | ||
|
||
test('Create a Project with POST to /api/projects/', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
|
@@ -23,6 +63,7 @@ describe('CREATE', () => { | |
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`] ) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
done(); | ||
|
@@ -40,6 +81,7 @@ describe('READ', () => { | |
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
|
@@ -54,7 +96,25 @@ describe('READ', () => { | |
}); | ||
|
||
describe('UPDATE', () => { | ||
test('Update a project with PATCH to /api/projects/:id', async (done) => { | ||
beforeAll(async () => { | ||
const submittedData = { | ||
name: { | ||
firstName: 'test', | ||
lastName: 'user', | ||
}, | ||
email: '[email protected]', | ||
}; | ||
const user = await User.create(submittedData); | ||
const auth_origin = 'TEST'; | ||
token = jwt.sign( | ||
{ id: user.id, role: user.accessLevel, auth_origin }, | ||
CONFIG_AUTH.SECRET, | ||
{ | ||
expiresIn: `${CONFIG_AUTH.TOKEN_EXPIRATION_SEC}s`, | ||
}, | ||
); | ||
}) | ||
test('Update a project with PATCH to /api/projects/:id without a token', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
|
@@ -64,6 +124,7 @@ describe('UPDATE', () => { | |
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
|
@@ -76,10 +137,44 @@ describe('UPDATE', () => { | |
.put(`/api/projects/${res.body._id}`) | ||
.set(headers) | ||
.send(updatedDataPayload); | ||
expect(res2.status).toBe(200); | ||
expect(res2.status).toBe(401); | ||
|
||
// Get project | ||
const res3 = await request.get(`/api/projects/${res.body._id}`) | ||
.set(headers); | ||
expect(res3.status).toBe(200); | ||
done(); | ||
}); | ||
test('Update a project with PATCH to /api/projects/:id with a token', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
}; | ||
|
||
// Submit a project | ||
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
const updatedDataPayload = { | ||
name: 'updatedProjectName', | ||
}; | ||
|
||
// Update project | ||
const res2 = await request | ||
.put(`/api/projects/${res.body._id}`) | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(updatedDataPayload); | ||
expect(res2.status).toBe(200) | ||
|
||
// Get project | ||
const res3 = await request.get(`/api/projects/${res.body._id}`).set(headers); | ||
const res3 = await request.get(`/api/projects/${res.body._id}`) | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
expect(res3.status).toBe(200); | ||
|
||
const APIData = res3.body; | ||
|
@@ -89,7 +184,45 @@ describe('UPDATE', () => { | |
}); | ||
|
||
describe('DELETE', () => { | ||
test('Delete a project with POST to /api/projects/:id', async (done) => { | ||
beforeAll(async () => { | ||
const submittedData = { | ||
name: { | ||
firstName: 'test', | ||
lastName: 'user', | ||
}, | ||
email: '[email protected]', | ||
}; | ||
const user = await User.create(submittedData); | ||
const auth_origin = 'TEST'; | ||
token = jwt.sign( | ||
{ id: user.id, role: user.accessLevel, auth_origin }, | ||
CONFIG_AUTH.SECRET, | ||
{ | ||
expiresIn: `${CONFIG_AUTH.TOKEN_EXPIRATION_SEC}s`, | ||
}, | ||
); | ||
}) | ||
test('Delete a project with POST to /api/projects/:id without a token', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
}; | ||
|
||
// Submit a project | ||
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
// Delete project | ||
const res2 = await request.patch(`/api/projects/${res.body._id}`) | ||
.set(headers); | ||
expect(res2.status).toBe(401); | ||
done(); | ||
}); | ||
test('Delete a project with POST to /api/projects/:id with a token', async (done) => { | ||
// Test Data | ||
const submittedData = { | ||
name: 'projectName', | ||
|
@@ -99,11 +232,14 @@ describe('DELETE', () => { | |
const res = await request | ||
.post('/api/projects/') | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
.send(submittedData); | ||
expect(res.status).toBe(201); | ||
|
||
// Delete project | ||
const res2 = await request.patch(`/api/projects/${res.body._id}`).set(headers); | ||
const res2 = await request.patch(`/api/projects/${res.body._id}`) | ||
.set(headers) | ||
.set('Cookie', [`token=${token}`]) | ||
expect(res2.status).toBe(200); | ||
done(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ import { Redirect } from 'react-router-dom'; | |
import { | ||
Typography, | ||
Box, | ||
Divider, | ||
Button, | ||
Grid, | ||
Radio, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
client/src/components/manageProjects/utilities/validateEventForm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters