Skip to content

Commit

Permalink
Version 0.9.20
Browse files Browse the repository at this point in the history
- Now validating timezone on create_event, update_event, run_event and update_job APIs
- Fixes #571
  • Loading branch information
jhuckaby committed Jan 31, 2023
1 parent 1ab8b85 commit 9f574e7
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var fs = require('fs');
var assert = require("assert");
var async = require('async');
var moment = require('moment-timezone');

var Class = require("pixl-class");
var Tools = require("pixl-tools");
Expand Down Expand Up @@ -259,6 +260,15 @@ module.exports = Class.create({
}
} // timing

// timezone must be one of the supported moment timezones
if (event.timezone) {
var zones = moment.tz.names();
if (!zones.includes(event.timezone)) {
this.doError('api', "Malformed or unknown timezone: " + event.timezone, callback);
return false;
}
}

return true;
},

Expand Down
28 changes: 28 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,34 @@ module.exports = {
} );
},

function testAPIUpdateEventBadTimezone(test) {
// test app/update_event api with a bad tz (should error out)
var self = this;
var params = {
"id": this.event_id,
"timezone": "THIS IS BAD",
"session_id": session_id
};

request.json( api_url + '/app/update_event', params, function(err, resp, data) {

test.ok( !err, "No error requesting API" );
test.ok( "code" in data, "Found code prop in JSON response" );
test.ok( data.code == 'api', "Code is api" );

// make sure event didn't get saved in storage
storage.listFind( 'global/schedule', { id: self.event_id }, function(err, event) {
test.ok( !err, "No error fetching data" );
test.ok( !!event, "Data record record is non-null" );
test.ok( event.username == "admin", "Username is correct" );
test.ok( event.created > 0, "Record creation date is non-zero" );
test.ok( event.timezone == cronicle.tz, "New timezone is correct (not changed)" );

test.done();
} );
} );
},

// app/get_schedule

function testAPIGetSchedule(test) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Cronicle",
"version": "0.9.19",
"version": "0.9.20",
"description": "A simple, distributed task scheduler and runner with a web based UI.",
"author": "Joseph Huckaby <[email protected]>",
"homepage": "https://github.com/jhuckaby/Cronicle",
Expand Down

0 comments on commit 9f574e7

Please sign in to comment.