MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / badPost

Function badPost

tests/testFileEditor.js:290–316  ·  view source on GitHub ↗
(action, fileEditContents, url)

Source from the content-addressed store, hash-verified

288}
289
290function 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
318function b64EncodeUnicode(str) {
319 // (1) use encodeURIComponent to get percent-encoded UTF-8

Callers 1

doEditsFunction · 0.85

Calls 3

itFunction · 0.85
callbackFunction · 0.85
b64EncodeUnicodeFunction · 0.70

Tested by

no test coverage detected