(action, fileEditContents, url)
| 288 | } |
| 289 | |
| 290 | function badPost(action, fileEditContents, url) { |
| 291 | describe(`POST to edit url with action ${action} and with bad path`, function() { |
| 292 | it('should not load successfully', function(callback) { |
| 293 | let form = { |
| 294 | __action: action, |
| 295 | __csrf_token: locals.__csrf_token, |
| 296 | file_edit_contents: b64EncodeUnicode(fileEditContents), |
| 297 | file_edit_user_id: locals.file_edit_user_id, |
| 298 | file_edit_course_id: locals.file_edit_course_id, |
| 299 | file_edit_dir_name: '../PrairieLearn/', |
| 300 | file_edit_file_name: 'config.json', |
| 301 | file_edit_orig_hash: locals.file_edit_orig_hash, |
| 302 | }; |
| 303 | locals.preEndTime = Date.now(); |
| 304 | request.post({url: url, form: form, followAllRedirects: true}, function (error, response, body) { |
| 305 | if (error) { |
| 306 | return callback(error); |
| 307 | } |
| 308 | locals.postEndTime = Date.now(); |
| 309 | if (response.statusCode != 400) { |
| 310 | return callback(new Error('bad status: ' + response.statusCode + '\n' + body)); |
| 311 | } |
| 312 | callback(null); |
| 313 | }); |
| 314 | }); |
| 315 | }); |
| 316 | } |
| 317 | |
| 318 | function b64EncodeUnicode(str) { |
| 319 | // (1) use encodeURIComponent to get percent-encoded UTF-8 |
no test coverage detected