-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleAbuseSpec.js
196 lines (176 loc) · 7.78 KB
/
exampleAbuseSpec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
var expect = require("chai").expect;
var request = require('superagent');
const agent = request.agent();
var adminUsername = "[email protected]";
var adminPass = "admin123";
var authToken='';
var url = "http://localhost:3000";
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
describe("Exercise Authenticated Use Cases", function() {
beforeEach(function(done) {
agent
.post(url + '/rest/user/login')
.set('Content-Type', 'application/json;charset=utf-8')
.send({email: adminUsername, password: adminPass})
.end(function(error, response){
expect(response.status).to.equal(200);
authToken = response.body['authentication']['token'];
agent.set('Authorization','Bearer ' + authToken)
agent.set('Cookie','token=' + authToken)
done();
});
});
it("Account names should be HTML-entity encoded", function(done) {
this.timeout(4000)
//create user account
var tmpAgent = request.agent();
var testEmail = "der<script>alert(1)</script>py" + getRandomInt(10000) + "@mcfuggles.local"
var postData = "{\"email\":\"" + testEmail + "\",\"password\":\"password1\",\"passwordRepeat\":\"password1\",\"securityQuestion\":{\"id\":2,\"question\":\"Mother's maiden name?\",\"createdAt\":\"2018-01-10T03:27:48.409Z\",\"updatedAt\":\"2018-01-10T03:27:48.409Z\"},\"securityAnswer\":\"test\"}"
tmpAgent
.post(url+'/api/Users/')
.set('Content-Type', 'application/json;charset=utf-8')
.send(postData)
.end(function(error, response, body) {
expect(response.status).to.equal(201);
agent.get(url+'/rest/user/authentication-details/', function(error, response, body) {
expect(response.status).to.equal(200);
expect(JSON.stringify(response.body)).to.not.contain('"email":"' + testEmail + '"');
done();
});
});
});
it("Ratings must be between 1 and 5, inclusive, 0 should fail", function(done) {
this.timeout(4000)
var tmpAgent = request.agent();
tmpAgent
.set('Content-Type', 'application/json;charset=utf-8')
.get(url+'/rest/captcha/', function(error, response, body) {
expect(response.status).to.equal(200);
var captchaid=response.body['captchaId'];
var captchaanswer=response.body['answer'];
agent
.post(url+'/api/Feedbacks/')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"UserId":1,"rating":0,"comment":"test","captcha":captchaanswer,"captchaId":captchaid})
.end(function(error, response, body) {
expect(response.status).to.equal(400)
done();
});
});
});
it("Authenticated adding shopping cart quantity < 0 should fail", function(done) {
this.timeout(4000)
agent
.post(url+'/api/BasketItems/')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"ProductId":4,"BasketId":"1","quantity":-99999})
.end(function(error, response, body) {
expect(response.status).to.equal(400)
agent
.post(url+'/rest/basket/1/checkout')
.set('Content-Type', 'application/json;charset=utf-8')
.send()
.end(function(error, response, body) {
expect(response.status).to.equal(200)
done();
});
});
});
});
describe("Exercise Unauthenticated Use Cases", function() {
it("Unauthenticated users may not modify product descriptions.", function(done) {
var tmpAgent = request.agent()
tmpAgent
.put(url+'/api/Products/1')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"description":"The all-time classic."})
.end(function(error, response, body) {
expect(response.status).to.equal(403)
done();
});
});
it("Unauthenticated user leaves feedback as a valid user should prompt for authentication", function(done) {
var tmpAgent = request.agent()
tmpAgent
.post(url+'/api/Feedbacks/')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"UserId":1,"rating":0,"comment":"test","captcha":"4","captchaId":1})
.end(function(error, response, body) {
expect(response.status).to.equal(401)
done();
});
});
it("File uploads with html extensions are forbidden", function(done) {
var tmpAgent = request.agent();
tmpAgent
.post(url+'/file-upload')
.set('Content-Type', 'multipart/form-data; boundary=---------------------------87801712517658189031084039755')
.send('-----------------------------87801712517658189031084039755\r\nContent-Disposition: form-data; name="file";filename="test.html"\r\nContent-Type: application/pdf\r\n\r\nderp\r\n\r\n-----------------------------87801712517658189031084039755--')
.end(function(error, response, body) {
expect(response.status).to.equal(400)
done();
});
});
it("File uploads larger than 100k are forbidden", function(done) {
var tmpAgent = request.agent();
var longFileContents = 'A'.repeat(150000)
tmpAgent
.post(url+'/file-upload')
.set('Content-Type', 'multipart/form-data; boundary=---------------------------87801712517658189031084039755')
.send('-----------------------------87801712517658189031084039755\r\nContent-Disposition: form-data; name="file";filename="test.pdf"\r\nContent-Type: application/pdf\r\n\r\n' +longFileContents+'\r\n\r\n-----------------------------87801712517658189031084039755--')
.end(function(error, response, body) {
expect(response.status).to.equal(400)
done();
});
});
it("Searching for common SQLi strings should return no data", function(done) {
request.get(url+'/rest/product/search?q=\';--', function(error,response,body) {
expect(response.status).to.equal(200)
expect(response.body).to.equal('{"status":"success","data":[]}')
done();
});
});
it("Logging in with common SQLi strings in the username should fail", function(done) {
var tmpAgent = request.agent()
var sqliString = adminUsername + '\';--'
tmpAgent
.post(url + '/rest/user/login')
.set('Content-Type', 'application/json;charset=utf-8')
.send({email: sqliString, password: adminPass})
.end(function(error, response){
expect(response.status).to.not.equal(200);
done();
});
});
it("Unauthenticated adding shopping cart quantity < 0 should prompt for authentication", function(done) {
var tmpAgent = request.agent()
tmpAgent
.post(url+'/api/BasketItems/1')
.set('Content-Type', 'application/json;charset=utf-8')
.send({"ProductId":22,"BasketId":"2","quantity":-9999})
.end(function(error, response, body) {
expect(response.status).to.equal(401)
done();
});
});
it("Block access to restricted KeePass file", function(done) {
var tmpAgent = request.agent()
tmpAgent
.redirects(0)
.get(url+'/ftp/incident-support.kdbx', function(error,response,body) {
expect(response.status).to.not.equal(200)
done();
});
});
it("Redirection request outside of whitelisted sites should not redirect", function(done) {
var tmpAgent = request.agent()
tmpAgent
.redirects(0)
.get(url+'/redirect?to=https://evilsite.local/?extra=https://github.com/bkimminich/juice-shop', function(error,response,body) {
expect(response.status).to.not.equal(302)
done();
});
});
});