Skip to content

Commit a338b46

Browse files
#175 Fix review comments
1 parent 3d2f3fc commit a338b46

7 files changed

+41
-17
lines changed

config/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module.exports = {
2727
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
2828
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
2929
USER_TOKEN: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlNoYXJhdGhrdW1hcjkyIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0OTMwNTAiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiU2hhcmF0aGt1bWFyOTJAdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.2gtNJwhcv7MYc-muX3Nv-B0RdWbhMRl7-xrwFUsLazM',
30+
ANOTHER_USER_TOKEN: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlNoYXJhdGhrdW1hcjkyIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDE0OTM1MCIsImlhdCI6MTUzMDE5ODY1OSwiZW1haWwiOiJmb29AYmFyLmNvbSIsImp0aSI6IjZmNzg4MWQ0LThlOTctMTFlYS1iYzU1LTAyNDJhYzEzMDAwMyJ9.Sou5VYEq8dV6AS8OX_fW_xHHUn2qObGHwoEk9L34Jaw',
3031
COPILOT_TOKEN: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.e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7fXE7QQ',

docs/Submission API.postman_collection.json

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2914,7 +2914,7 @@
29142914
"response": []
29152915
},
29162916
{
2917-
"name": "Delete Submission as a copilot - 403",
2917+
"name": "Delete submission as a copilot - 403",
29182918
"request": {
29192919
"method": "DELETE",
29202920
"header": [
@@ -2937,6 +2937,30 @@
29372937
},
29382938
"response": []
29392939
},
2940+
{
2941+
"name": "Delete another user's submission - 403",
2942+
"request": {
2943+
"method": "DELETE",
2944+
"header": [
2945+
{
2946+
"key": "Authorization",
2947+
"value": "Bearer {{ANOTHER_USER_TOKEN}}",
2948+
"type": "text"
2949+
}
2950+
],
2951+
"url": {
2952+
"raw": "{{URL}}/submissions/{{submissionID}}",
2953+
"host": [
2954+
"{{URL}}"
2955+
],
2956+
"path": [
2957+
"submissions",
2958+
"{{submissionID}}"
2959+
]
2960+
}
2961+
},
2962+
"response": []
2963+
},
29402964
{
29412965
"name": "Delete Submission as a user",
29422966
"request": {

docs/submission-api.postman_environment.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"id": "9f46d01c-0036-4350-aa00-c6860b4450de",
3-
"name": "submission-api",
2+
"id": "93a58dd4-67e4-4f7b-b84b-4484feb509fc",
3+
"name": "Submission API",
44
"values": [
55
{
66
"key": "URL",
@@ -22,30 +22,28 @@
2222
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlNoYXJhdGhrdW1hcjkyIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0OTMwNTAiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiU2hhcmF0aGt1bWFyOTJAdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.2gtNJwhcv7MYc-muX3Nv-B0RdWbhMRl7-xrwFUsLazM",
2323
"enabled": true
2424
},
25+
{
26+
"key": "ANOTHER_USER_TOKEN",
27+
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlNoYXJhdGhrdW1hcjkyIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDE0OTM1MCIsImlhdCI6MTUzMDE5ODY1OSwiZW1haWwiOiJmb29AYmFyLmNvbSIsImp0aSI6IjZmNzg4MWQ0LThlOTctMTFlYS1iYzU1LTAyNDJhYzEzMDAwMyJ9.Sou5VYEq8dV6AS8OX_fW_xHHUn2qObGHwoEk9L34Jaw",
28+
"enabled": true
29+
},
2530
{
2631
"key": "submissionID",
2732
"value": "a12a4180-65aa-42ec-a945-5fd21dec0505",
28-
"description": {
29-
"content": "",
30-
"type": "text/plain"
31-
},
3233
"enabled": true
3334
},
3435
{
3536
"key": "artifactID",
3637
"value": "c56a4180-65aa-42ec-a945-5fd21dec0503",
37-
"description": "",
3838
"enabled": true
3939
},
4040
{
4141
"key": "filename",
4242
"value": "sampleFileName",
43-
"type": "text",
44-
"description": "",
4543
"enabled": true
4644
}
4745
],
4846
"_postman_variable_scope": "environment",
49-
"_postman_exported_at": "2019-08-11T08:59:27.296Z",
50-
"_postman_exported_using": "Postman/6.7.4"
47+
"_postman_exported_at": "2020-05-05T06:23:03.562Z",
48+
"_postman_exported_using": "Postman/7.23.0"
5149
}

src/routes/SubmissionRoutes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = {
4545
controller: 'SubmissionController',
4646
method: 'deleteSubmission',
4747
auth: 'jwt',
48-
access: ['Administrator', 'Topcoder User', 'Copilot'],
48+
access: ['Administrator', 'Topcoder User'],
4949
scopes: ['delete:submission', 'all:submission']
5050
}
5151
},

src/services/SubmissionService.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ patchSubmission.schema = {
585585

586586
/**
587587
* Function to delete submission
588+
* @param {Object} authUser Authenticated user (that is making the request)
588589
* @param {String} submissionId submissionId which need to be deleted
589590
* @param {Object} span the Span object
590591
* @return {Promise}

test/e2e/SubmissionService.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,10 @@ describe('Submission Service tests', () => {
655655
})
656656
}).timeout(20000)
657657

658-
it('Deleting submission with copilot token should throw 403', (done) => {
658+
it('Deleting submission that the user does not own should throw 403', (done) => {
659659
chai.request(app)
660660
.delete(`${config.API_VERSION}/submissions/${userSubmissionId}`)
661-
.set('Authorization', `Bearer ${config.COPILOT_TOKEN}`)
661+
.set('Authorization', `Bearer ${config.ANOTHER_USER_TOKEN}`)
662662
.end((err, res) => {
663663
res.should.have.status(403)
664664
res.body.message.should.be.eql('You cannot access other member\'s submission')

test/unit/SubmissionService.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ describe('Submission Service tests', () => {
534534
})
535535

536536
// Non admin users should not be able to delete submissions that they don't own
537-
it('Deleting submission with copilot token should throw 403', (done) => {
537+
it('Deleting submission that the user does not own should throw 403', (done) => {
538538
chai.request(app)
539539
.delete(`${config.API_VERSION}/submissions/${testSubmission.Item.id}`)
540-
.set('Authorization', `Bearer ${config.COPILOT_TOKEN}`)
540+
.set('Authorization', `Bearer ${config.ANOTHER_USER_TOKEN}`)
541541
.end((err, res) => {
542542
res.should.have.status(403)
543543
res.body.message.should.be.eql('You cannot access other member\'s submission')

0 commit comments

Comments
 (0)