Skip to content
This repository has been archived by the owner on Apr 19, 2019. It is now read-only.

Commit

Permalink
more: Disallow reading from other users' PM buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
kxz committed Aug 8, 2015
1 parent 8f5a353 commit 41a7bdd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions omnipresence/plugins/more/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
from itertools import tee

from ...message import collapse
from ...plugin import EventPlugin
from ...plugin import EventPlugin, UserVisibleError
from ...settings import PRIVATE_CHANNEL


class Default(EventPlugin):
def on_command(self, msg):
venue = PRIVATE_CHANNEL if msg.private else msg.venue
source = msg.content or msg.actor.nick
buf = msg.connection.message_buffers[venue].get(source, [])
if not buf:
return 'No text in buffer.'
buf = (msg.connection.message_buffers[venue].get(source, []) or
'No text in buffer.')
if msg.connection.case_mapping.equates(source, msg.actor.nick):
return buf
if msg.private:
raise UserVisibleError("You cannot read another user's "
"private reply buffer.")
if isinstance(buf, Sequence):
return buf[:]
# Assume an iterator. The original iterator can no longer be
Expand Down
11 changes: 11 additions & 0 deletions omnipresence/plugins/more/test_more.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from itertools import count, imap

from ...message import Message, collapse
from ...settings import PRIVATE_CHANNEL
from ...test.helpers import AbstractCommandTestCase, OutgoingPlugin

from . import Default
Expand Down Expand Up @@ -59,3 +60,13 @@ def test_other_buffer_iterator(self):
self.assert_reply('', '1', actor='party3')
self.assert_reply('party3', '2')
self.assert_reply('', '2', actor='party3')

def test_other_buffer_private(self):
private_buffers = self.connection.message_buffers[PRIVATE_CHANNEL]
private_buffers[self.other_user.nick] = ['hello world']
private_buffers['party3'] = ['lorem ipsum dolor sit amet']
self.assert_reply(
'party3',
"You cannot read another user's private reply buffer.",
venue=self.connection.nickname)
self.assert_reply('', 'hello world', venue=self.connection.nickname)

0 comments on commit 41a7bdd

Please sign in to comment.