mirror of https://github.com/zulip/zulip.git
bots: Add token to outgoing webhook zuliprc.
We want the Botserver to not only work with the botserverrc, but also with a zuliprc of an outgoing webhook. Because the Botserver uses the outgoing webhook token for authentication, we need to include it in the zuliprc for outgoing webhooks.
This commit is contained in:
parent
d08c701bb4
commit
5d9a8cf64f
|
@ -1,6 +1,7 @@
|
||||||
var common = require('../casper_lib/common.js').common;
|
var common = require('../casper_lib/common.js').common;
|
||||||
var test_credentials = require('../../var/casper/test_credentials.js').test_credentials;
|
var test_credentials = require('../../var/casper/test_credentials.js').test_credentials;
|
||||||
var OUTGOING_WEBHOOK_BOT_TYPE = '3';
|
var OUTGOING_WEBHOOK_BOT_TYPE = '3';
|
||||||
|
var GENERIC_BOT_TYPE = '1';
|
||||||
|
|
||||||
common.start_and_log_in();
|
common.start_and_log_in();
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@ common.start_and_log_in();
|
||||||
|
|
||||||
// var form_sel = 'form[action^="/json/settings"]';
|
// var form_sel = 'form[action^="/json/settings"]';
|
||||||
var regex_zuliprc = /^data:application\/octet-stream;charset=utf-8,\[api\]\nemail=.+\nkey=.+\nsite=.+\n$/;
|
var regex_zuliprc = /^data:application\/octet-stream;charset=utf-8,\[api\]\nemail=.+\nkey=.+\nsite=.+\n$/;
|
||||||
|
var regex_outgoing_webhook_zuliprc = /^data:application\/octet-stream;charset=utf-8,\[api\]\nemail=.+\nkey=.+\nsite=.+\ntoken=.+\n$/;
|
||||||
var regex_botserverrc = /^data:application\/octet-stream;charset=utf-8,\[\]\nemail=.+\nkey=.+\nsite=.+\ntoken=.+\n$/;
|
var regex_botserverrc = /^data:application\/octet-stream;charset=utf-8,\[\]\nemail=.+\nkey=.+\nsite=.+\ntoken=.+\n$/;
|
||||||
|
|
||||||
casper.then(function () {
|
casper.then(function () {
|
||||||
|
@ -110,7 +112,7 @@ casper.then(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
casper.then(function create_bot() {
|
casper.then(function create_bot() {
|
||||||
casper.test.info('Filling out the create bot form');
|
casper.test.info('Filling out the create bot form for an outgoing webhook bot');
|
||||||
|
|
||||||
casper.fill('#create_bot_form',{
|
casper.fill('#create_bot_form',{
|
||||||
bot_name: 'Bot 1',
|
bot_name: 'Bot 1',
|
||||||
|
@ -136,6 +138,37 @@ casper.then(function () {
|
||||||
casper.waitUntilVisible(button_sel + '[href^="data:application"]', function () {
|
casper.waitUntilVisible(button_sel + '[href^="data:application"]', function () {
|
||||||
casper.test.assertMatch(
|
casper.test.assertMatch(
|
||||||
decodeURIComponent(casper.getElementsAttribute(button_sel, 'href')),
|
decodeURIComponent(casper.getElementsAttribute(button_sel, 'href')),
|
||||||
|
regex_outgoing_webhook_zuliprc,
|
||||||
|
'Looks like an outgoing webhook bot ~/.zuliprc file');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.then(function create_bot() {
|
||||||
|
casper.test.info('Filling out the create bot form for a normal bot');
|
||||||
|
|
||||||
|
casper.fill('#create_bot_form',{
|
||||||
|
bot_name: 'Bot 2',
|
||||||
|
bot_short_name: '2',
|
||||||
|
bot_type: GENERIC_BOT_TYPE,
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.test.info('Submitting the create bot form');
|
||||||
|
casper.click('#create_bot_button');
|
||||||
|
});
|
||||||
|
|
||||||
|
var second_bot_email = '2-bot@zulip.zulipdev.com';
|
||||||
|
var second_button_sel = '.download_bot_zuliprc[data-email="' + second_bot_email + '"]';
|
||||||
|
|
||||||
|
casper.then(function () {
|
||||||
|
casper.waitUntilVisible(second_button_sel, function () {
|
||||||
|
casper.click(second_button_sel);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.then(function () {
|
||||||
|
casper.waitUntilVisible(second_button_sel + '[href^="data:application"]', function () {
|
||||||
|
casper.test.assertMatch(
|
||||||
|
decodeURIComponent(casper.getElementsAttribute(second_button_sel, 'href')),
|
||||||
regex_zuliprc,
|
regex_zuliprc,
|
||||||
'Looks like a bot ~/.zuliprc file');
|
'Looks like a bot ~/.zuliprc file');
|
||||||
});
|
});
|
||||||
|
|
|
@ -97,7 +97,14 @@ function render_bots() {
|
||||||
|
|
||||||
exports.generate_zuliprc_uri = function (bot_id) {
|
exports.generate_zuliprc_uri = function (bot_id) {
|
||||||
var bot = bot_data.get(bot_id);
|
var bot = bot_data.get(bot_id);
|
||||||
var data = exports.generate_zuliprc_content(bot.email, bot.api_key);
|
var data;
|
||||||
|
var token;
|
||||||
|
// For outgoing webhooks, include the token in the zuliprc.
|
||||||
|
// It's needed for authenticating to the Botserver.
|
||||||
|
if (bot.bot_type === 3) {
|
||||||
|
token = bot_data.get_services(bot_id)[0].token;
|
||||||
|
}
|
||||||
|
data = exports.generate_zuliprc_content(bot.email, bot.api_key, token);
|
||||||
return exports.encode_zuliprc_as_uri(data);
|
return exports.encode_zuliprc_as_uri(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -105,11 +112,12 @@ exports.encode_zuliprc_as_uri = function (zuliprc) {
|
||||||
return "data:application/octet-stream;charset=utf-8," + encodeURIComponent(zuliprc);
|
return "data:application/octet-stream;charset=utf-8," + encodeURIComponent(zuliprc);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.generate_zuliprc_content = function (email, api_key) {
|
exports.generate_zuliprc_content = function (email, api_key, token) {
|
||||||
return "[api]" +
|
return "[api]" +
|
||||||
"\nemail=" + email +
|
"\nemail=" + email +
|
||||||
"\nkey=" + api_key +
|
"\nkey=" + api_key +
|
||||||
"\nsite=" + page_params.realm_uri +
|
"\nsite=" + page_params.realm_uri +
|
||||||
|
(token === undefined ? "" : ("\ntoken=" + token)) +
|
||||||
// Some tools would not work in files without a trailing new line.
|
// Some tools would not work in files without a trailing new line.
|
||||||
"\n";
|
"\n";
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue