Commit graph

133 commits

Author SHA1 Message Date
Rohitt Vashishtha cb183fef4c botserver: Add tests for reading config section by bot name. 2018-07-27 13:43:42 -04:00
Eeshan Garg 1127f973aa pypi: Release version 0.5.2. 2018-07-26 21:19:12 -02:30
novokrest 50173c105b botserver: Read bot's config from config section with bot's name.
This commit changes the default behavior for a hypothetical bot
named 'bot_one' to the following with the config file:

1. Find and load section named 'bot_one', else...
2. Find and load the first section, else...
3. Exit with error message.

Also, we now gracefully show missing options in a config section
instead of printing the whole stacktrace of the exception.
2018-07-12 20:49:10 +05:30
Eeshan Garg c2fdd547f7 PyPI: Release 0.5.1. 2018-07-01 12:05:59 -02:30
Eeshan Garg c636a5ac49 pypi: Release 0.5.0. 2018-06-07 12:05:18 -02:30
Robert Hönig 242bcdbadc botserver: Add specific error message for unedited zuliprcs.
Previously, when a user tried to run the Botserver with a
zuliprc but forgot to set the bot name, they were told to
edit the botserverrc file. However, the recommended approach
is to specify the botname with the -b option. This commit
adds an error message specific for this case. It recognizes
zuliprc files by their section header `api`.
2018-06-04 10:14:17 -07:00
Robert Hönig 3ddc8f9b5d botserver: Make bot-name-not-found error more user-friendly.
Previously, when a bot name wasn't found, the Botserver threw
an ImportError with an error message. This results in an
intimidating traceback which is in most cases not helpful to
the user. This commit replaces the ImportError with sys.exit.
2018-06-04 10:14:17 -07:00
Robert Hönig c85b42be9f botserver: Exit with helpful output if botserverrc is invalid.
If the botserverrc file contains empty section headers, it
is very likely that the user forgot to edit the file. This
reminds them to do so.
2018-06-04 10:14:17 -07:00
Robert Hönig 3d05b88cc2 botserver: Rename zulip-bot-server to zulip-botserver.
This is consistent with the correct prose "Botserver"
(instead of "Bot-server").
2018-06-04 10:14:17 -07:00
Robert Hönig f4e0808a87 botserver: Validate token before accepting message.
Previously, the botserver would accept any message sent
to it. This was a security hazard, since an attacker could
impersonate arbitrary users with arbitrary messages. We only
want the Zulip instance where a bot is registered to be able
to send out messages for that bot. To do this, this commits
adds a check for the security token associated with each
outgoing webhook bot. For each bot, its token is stored in
the botserverrc file. The server sends the token along with
each message.
2018-05-30 09:37:33 -04:00
Robert Hönig 64a1306e39 Consistently use Botserver instead of botserver or bot server. 2018-05-29 10:58:37 +02:00
Robert Hönig 762118bbea Rename flaskbotrc to botserverrc. 2018-05-29 10:19:50 +02:00
Robert Hönig 3859bef05f botserver: Make handle_bot logic more concise. 2018-05-29 10:05:32 +02:00
Robert Hönig e6ef34a964 botserver: Strip messages like we do in zulip-run-bot.
Previously, messages weren't stripped at all. This
caused most bots to break and send replies similar to
"I didn't understand your command". Nobody noticed,
because the tests were only validating that replies
were sent, but not the content in them. Thus, this
commit also adds tests to avoid further regressions.
2018-05-29 10:05:19 +02:00
Robert Hönig f1bcf3b9a4 botserver: Remove redundant message check.
Previously, the botserver `handle_bot` routine did two checks
on an incoming message:
* First, it checked if the bot email matches
an email in the flaskbotrc.
* Second, it checked if the bot name that corresponds to an email
has a lib module loaded. However, this must be the case, because
all lib modules for all emails are loaded on initialization. Thus,
this commit removes the second check.
2018-05-29 09:52:14 +02:00
Robert Hönig 5c062cee0d botserver: Verify bot response.
This allows for more realistic testing.
2018-05-28 11:13:56 -07:00
Robert Hönig 4285cef29c assert_bot_server_response: Mock ExternalBotHandler. 2018-05-28 11:13:56 -07:00
Robert Hönig 27938a926b Rename assert_bot_server_response param message to event.
It's an event, not a message.
2018-05-28 11:13:56 -07:00
Robert Hönig 48f2c2ae36 Remove default value from assert_bot_server_response message parameter.
This is the first step in validating the bot responses for the
botserver. The default value for `message` was nonsense and
wouldn't trigger a bot in real life. Additionally, we'll want
each test to use a proper message tailored to the test. Thus,
this commit removes a 'default' message alltogether.
2018-05-28 11:13:55 -07:00
Robert Hönig 6a8cb2965c zulip_botserver: Handle all requests from the root / endpoint.
Previously, the Botserver determined which bot to run by dispatching on
a unique URL endpoint /bots/<botname> for each bot.
Now, instead, the Botserver determines which bot to run by the section
header of the bot in the flaskbotrc.
2018-05-28 15:09:39 +02:00
Eeshan Garg 00f22e175c pypi: Release 0.4.7. 2018-05-21 20:02:43 -02:30
dkvasov 79899dba30 zulip_botserver: More test cases. 2018-05-17 09:43:00 -07:00
dkvasov fe801d08eb zulip_botserver: Add test for config parsing. 2018-05-17 09:42:52 -07:00
dkvasov 40785d3116 zulip_botserver: Add test for default input parameters. 2018-05-17 09:40:44 -07:00
dkvasov a06fb98f21 zulip_bots and zulip_botserver: Extract common function. 2018-05-17 17:35:09 +03:00
dkvasov 86ab26d2ba zulip_botserver: Get rid of last global variable. 2018-05-16 10:58:09 -07:00
dkvasov a5d6286d85 zulip_botserver: Better message for single bot mode. 2018-05-16 10:58:09 -07:00
dkvasov b06ebdecef zulip_botserver: Add option to test third party configs 2018-05-16 10:50:43 -07:00
dkvasov d3b99959c6 zulip_botserver: Add test to check two bots working together. 2018-05-16 10:50:43 -07:00
dkvasov 2de862cdcd zulip_botserver/tests: Reformat input to make them more readable. 2018-05-16 10:50:43 -07:00
dkvasov 7bbc81edbd zulip_botserver: Get rid of unused input parameter: use load_lib_modules func for loading modules in tests. 2018-05-16 10:50:43 -07:00
dkvasov ce95f9f4d5 zulip_bots and zulip_botserver: Remove unused imports. 2018-05-16 10:50:43 -07:00
dkvasov a8665aaac8 zulip_botserver: Add option to set third party configs for bots. 2018-05-16 10:50:43 -07:00
dkvasov 6542f8c867 zulip_botserver: Add parameter to set custom bot name (for single-bot mode). 2018-05-16 17:41:22 +03:00
dkvasov aa193c1298 zulip_botserver: Extract input parameters. 2018-05-16 17:40:40 +03:00
Guitar1st f90913d54c zulip_botserver: Get rid of some global variables. 2018-05-15 12:32:57 -07:00
Tim Abbott 7b6da265ea zulip_botserver: Reorder imports. 2018-05-15 12:32:45 -07:00
Tim Abbott 70dd05e5a6 zulip_botserver: Enforce that port argument is an int. 2018-05-15 12:32:45 -07:00
Tim Abbott 5ef224f2a2 zulip_botserver: Eliminate the bots_config global variable.
It's easy to just pass it around to the one function that needs it.
2018-05-15 12:32:44 -07:00
Tim Abbott 1e5c0fec1f zulip_botserver: Fix long line for ImportError. 2018-05-15 12:23:40 -07:00
Tim Abbott 9eda19d6cc zulip_botserver: Get rid of old six.moves for configparser. 2018-05-15 12:23:10 -07:00
Guitar1st 2ba6f75fb3 zulip_botserver: Change style of type annotations to python3 2018-05-14 20:00:44 +00:00
Guitar1st 641665c338 zulip_botserver: Remove unused imports and do some other cleanup. 2018-05-14 20:00:44 +00:00
Tim Abbott b1ab308c26 botserver: Fix mypy error. 2018-05-14 10:07:02 -07:00
Tim Abbott 7124f9dc14 bot_server: Call the bot server initialization code. 2018-05-14 08:50:52 -07:00
Eeshan Garg f4bdb059db pypi: Release version 0.4.6.
This includes a critical bug fix for call_on_each_event.
2018-04-27 01:43:42 -02:30
Eeshan Garg 0f448579ab pypi: Release 0.4.5.
We just made a minor change to our Git integration, so that warranted
a new release so I could update the docs on the zulip/zulip repo.
2018-04-23 18:50:56 -02:30
Eeshan Garg 2d46445ab5 pypi: Release version 0.4.4.
This includes some important changes after the release of pip 10.
2018-04-16 17:05:27 -02:30
Eeshan Garg 60e02ed979 pypi: Release version 0.4.3.
Making this release due to recent changes made to the Trello script.
2018-04-03 22:05:39 -02:30
Eeshan Garg 7e360c244c pypa: Release version 0.4.2. 2018-03-31 17:19:23 -02:30
Eeshan Garg f74c94ba04 pypi_packaging: Release version 0.4.1. 2018-02-07 01:03:49 -03:30
Eeshan Garg 4458276801 requirements: Remove runtime dependency on mock.
The zulip and zulip_botserver packages specify mock as a runtime
dependency, which is only needed for testing during development.
So, it made more sense to move it to requirements.txt so that
it can be installed by ./tools/provision during development.
2018-01-09 17:01:16 -03:30
Eeshan Garg 3030c73060 packages: Release 0.4.0. 2018-01-06 18:28:35 -03:30
Robert Hönig 06c5904347 Add 'mock' requirement for zulip and zulip_botserver.
These packages depend on mock. Previously, that dependency
was satisfied "by chance" because zulip_bots happened to
install 'mock'.
2018-01-06 16:39:52 +01:00
neiljp (Neil Pilgrim) 438f711bb7 mypy: Amend typing of botserver test lib for strict-optional. 2018-01-02 14:05:33 -05:00
Eeshan Garg c3ab265d3e packaging: Upgrade to release 0.3.9. 2017-11-29 01:23:12 -03:30
Steve Howell 536ba1843a Add a command line option to run.py for bot config files.
Before this change, we were looking for config files in
default locations in source control, which is not a good
place to look for them.  Now `run.py` and friends have a
command line argument where users can specify the config
files.

Note that the change to server.py is only a partial fix
to make it so that bots that don't use third party config
files won't crash.  That program needs an overhaul, anyway.
2017-11-28 10:52:13 -08:00
Steve Howell 8a15452525 bots: Require bots_details in ExternalBotHandler.
This parameter was defaulting to a dictionary, which is
a classic Python pitfall.
2017-11-28 10:52:13 -08:00
Eeshan Garg 50b5ec0f49 packages: Release 0.3.8 for all PyPI packages. 2017-11-27 23:34:38 -03:30
derAnfaenger 2736223073 bots: Make StateHandler store state on Zulip server.
This makes the StateHandler functional. To reduce the
number of server roundtrips when fetching/updating the
state, the entire state is fetched ocne at bot
initialization and cached. All changes are stored in the
cache and only saved externally after handle_message()
has been executed.

Fixes #141.
2017-11-18 08:58:47 -08:00
neiljp (Neil Pilgrim) d929cdb91e botserver testing: Move to six.assertRaisesRegex from Regexp variant.
This ensures 2/3 compatibility. The mypy test also now passes, though
the six stubs appear very minimal - maybe incorrect?
2017-11-15 13:43:08 -08:00
derAnfaenger fa9e5a8e26 zulip_botserver: Test for import error with wrong credentials. 2017-11-10 18:36:20 -08:00
derAnfaenger bf72a8994a zulip_botserver: Raise exception on wrong flaskbotrc file. 2017-11-10 18:36:20 -08:00
derAnfaenger fb116259d0 zulip_botserver: Make tests more realistic.
Specifically, this invokes server.load_lib_modules()
and server.load_bot_handlers() to generate the modules
and handlers, instead of hardcoding them.
2017-11-10 18:36:20 -08:00
derAnfaenger bcc8bd7d38 zulip_botserver: Don't reinstantiate ExternalBotHandlers.
Fixes #147.
2017-11-07 05:06:12 -08:00
derAnfaenger e5576388dd botserver: Remove obsolete state_handler param from handle_message(). 2017-10-31 12:24:10 +01:00
Alena Volkova 25d6c68d4d mypy: zulip_botserver: Fix errors in setup.py. 2017-10-27 00:56:16 -04:00
Alena Volkova ed51cabf1b mypy: zulip_botserver: Fix errors in zulip_botserver/server.py. 2017-10-27 00:56:16 -04:00
Alena Volkova 81205ea813 mypy: zulip_botserver: Fix errors in tests/__init__.py. 2017-10-27 00:56:16 -04:00
Eeshan Garg 4af8bcd46e packaging: Upgrade package version (0.3.5 -> 0.3.7). 2017-10-21 01:10:25 -02:30
Eeshan Garg 1e8e1f17c4 release: Upgrade package versions (0.3.4 -> 0.3.5). 2017-10-09 14:13:32 -02:30
Eeshan Garg aaece51380 packages: Stop hardcoding version in dependency checks.
In zulip_bots/setup.py, we now don't specify a minimum version when
checking for dependency on the zulip package. We just want the
latest one.

In zulip_botserver/setup.py, we now don't specify a minimum version
when checking for dependencies on the zulip and zulip_bots package.
We just want the latest ones.
2017-10-05 12:01:37 -07:00
derAnfaenger fb2aff4611 zulip package: Add unittest
As the first unittest, this creates a test directory and
abnd adds it tho the excluded pip package files.

There are two `tests` directories now, one in zulip_botserver and one in
zulip. This confuses the unittest runner, leading to failed test imports.
Therefore, we need to tell the package importer that there are multiple
tests directories, all of which should be considered for a search.
2017-09-12 01:27:09 -07:00
Eeshan Garg 390054da62 python-zulip-api: Upgrade versions (0.3.3 -> 0.3.4). 2017-09-11 21:09:28 -02:30
Eeshan Garg 6e798f317f python-zulip-api: Upgrade versions (0.3.2 -> 0.3.3).
We now have "universal" wheel distributions. Universal wheels
support both Python 2 and Python 3.
2017-09-01 23:10:12 -02:30
derAnfaenger 9d683e4669 api: Ensure automatic tilde expansion. 2017-08-29 14:20:48 -07:00
derAnfaenger 689addc5bf zulip_botserver: Add skeleton config file for supervisord. 2017-08-29 09:53:34 -07:00
derAnfaenger 6c026c84aa flaskserver: Load json python 3 compatible. 2017-08-15 06:38:50 -07:00
Eeshan Garg 59c750707a python-zulip-api: Upgrade package versions (0.3.1 -> 0.3.2). 2017-07-31 15:33:34 -07:00
Eeshan Garg de23a1b32f zulip_botserver: Migrate from optparse to argparse. 2017-07-29 00:17:43 -02:30
vaibhav c4876dddae bot server: Raise BadRequest when bot code can't be imported.
This adds support to check and raise a BadRequest when either the
configuration of bot couldn't be found or the BotHandler code of bot
couldn't be fetched. There can be cases where flaskbotrc contains config
details of a bot, but the user hasn't added it's handler class code. This
fixes server to handle such cases, by reporting it to user.
This also fixes the response of bot server to make it possible to skip
the response message.
2017-07-27 11:03:33 -07:00
derAnfaenger f3eaa381f6 bots: Audit filesystem access.
This adds a safe function for opening files via
ExternalBotHandler. This restricts open calls to a bot's
local directory.

Finalizes #9
2017-07-26 20:01:17 +02:00
Eeshan Garg 928d5ca16d flask_server: Move the server to its own package. 2017-07-18 01:31:54 -02:30