Skip to content

Commit

Permalink
Allow even less arbitrary file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
jtatum committed Jul 23, 2017
1 parent d99e114 commit 9063de0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
13 changes: 7 additions & 6 deletions slackbot/plugins/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@


@respond_to(r'upload \<?(.*)\>?')
def upload(message, url):
def upload(message, thing):
# message.channel.upload_file(slack_filename, local_filename,
# initial_comment='')
url = url.lstrip('<').rstrip('>')
message.reply('uploading {}'.format(url))
if url.startswith('http'):
if thing == 'favicon':
url = 'https://slack.com/favicon.ico'
message.reply('uploading {}'.format(url))
with create_tmp_file() as tmpf:
download_file(url, tmpf)
message.channel.upload_file(url, tmpf,
'downloaded from {}'.format(url))
elif url == 'slack.png':
elif thing == 'slack.png':
message.reply('uploading slack.png')
cwd = os.path.abspath(os.path.dirname(__file__))
fname = os.path.join(cwd, '../../tests/functional/slack.png')
message.channel.upload_file(url, fname)
message.channel.upload_file(thing, fname)


@respond_to('send_string_content')
Expand Down
3 changes: 2 additions & 1 deletion tests/functional/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def _has_got_message_rtm(self, channel, match, tosender=True, thread=False):
match = six.text_type(r'\<@{}\>: {}').format(self.driver_userid, match)
with self._events_lock:
for event in self.events:
if 'type' not in event or 'text' not in event:
if 'type' not in event or \
(event['type'] == 'message' and 'text' not in event):
print('Unusual event received: ' + repr(event))
if (not thread or (thread and event.get('thread_ts', False))) \
and event['type'] == 'message' and re.match(match, event['text'], re.DOTALL):
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_bot_upload_file(driver):
def test_bot_upload_file_from_link(driver):
url = 'https://slack.com/favicon.ico'
fname = basename(url)
driver.send_direct_message('upload %s' % url)
driver.send_direct_message('upload favicon')
driver.wait_for_bot_direct_message('uploading <%s>' % url)
driver.wait_for_file_uploaded(fname)

Expand Down

0 comments on commit 9063de0

Please sign in to comment.