Add webhookKey support (#1920)

This commit is contained in:
Tyler Brock
2016-05-26 11:17:24 -07:00
parent 0850c184d3
commit 2561987d20
4 changed files with 70 additions and 8 deletions

View File

@@ -17,7 +17,7 @@ app.listen(12345);
describe('Hooks', () => {
it("should have some hooks registered", (done) => {
it("should have no hooks registered", (done) => {
Parse.Hooks.getFunctions().then((res) => {
expect(res.constructor).toBe(Array.prototype.constructor);
done();
@@ -27,7 +27,7 @@ describe('Hooks', () => {
});
});
it("should have some triggers registered", (done) => {
it("should have no triggers registered", (done) => {
Parse.Hooks.getTriggers().then( (res) => {
expect(res.constructor).toBe(Array.prototype.constructor);
done();
@@ -291,7 +291,7 @@ describe('Hooks', () => {
console.error(err);
fail("Should not fail calling a function");
done();
})
});
});
it("should run the function on the test server", (done) => {
@@ -299,7 +299,7 @@ describe('Hooks', () => {
app.post("/SomeFunctionError", function(req, res) {
res.json({error: {code: 1337, error: "hacking that one!"}});
});
// The function is delete as the DB is dropped between calls
// The function is deleted as the DB is dropped between calls
Parse.Hooks.createFunction("SOME_TEST_FUNCTION", hookServerURL+"/SomeFunctionError").then(function(){
return Parse.Cloud.run("SOME_TEST_FUNCTION")
}, (err) => {
@@ -317,6 +317,57 @@ describe('Hooks', () => {
});
});
it("should provide X-Parse-Webhook-Key when defined", (done) => {
app.post("/ExpectingKey", function(req, res) {
if (req.get('X-Parse-Webhook-Key') === 'hook') {
res.json({success: "correct key provided"});
} else {
res.json({error: "incorrect key provided"});
}
});
Parse.Hooks.createFunction("SOME_TEST_FUNCTION", hookServerURL+"/ExpectingKey").then(function(){
return Parse.Cloud.run("SOME_TEST_FUNCTION")
}, (err) => {
console.error(err);
fail("Should not fail creating a function");
done();
}).then(function(res){
expect(res).toBe("correct key provided");
done();
}, (err) => {
console.error(err);
fail("Should not fail calling a function");
done();
});
});
it("should not pass X-Parse-Webhook-Key if not provided", (done) => {
setServerConfiguration(Object.assign({}, defaultConfiguration, { webhookKey: undefined }));
app.post("/ExpectingKeyAlso", function(req, res) {
if (req.get('X-Parse-Webhook-Key') === 'hook') {
res.json({success: "correct key provided"});
} else {
res.json({error: "incorrect key provided"});
}
});
Parse.Hooks.createFunction("SOME_TEST_FUNCTION", hookServerURL+"/ExpectingKeyAlso").then(function(){
return Parse.Cloud.run("SOME_TEST_FUNCTION")
}, (err) => {
console.error(err);
fail("Should not fail creating a function");
done();
}).then(function(res){
fail("Should not succeed calling that function");
done();
}, (err) => {
expect(err.code).toBe(141);
expect(err.message).toEqual("incorrect key provided");
done();
});
});
it("should run the beforeSave hook on the test server", (done) => {
var triggerCount = 0;