def test_html_escape_policy(self):
        sys.modules['weechat'].config_options[
            'otr.policy.server.nick.friend.html_escape'] = 'on'

        result = weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG friend :< > " \' &')
        self.assertEqual(result, 'PRIVMSG friend :&lt; &gt; " \' &amp;')
    def test_html_escape_policy_off_unencrypted(self):
        sys.modules['weechat'].config_options[
            'otr.policy.server.nick.friend.html_escape'] = 'off'
        self.account.getContext('friend@server').is_encrypted_fake = False

        result = weechat_otr.message_out_cb(
            None, None, 'server', ':nick!user@host PRIVMSG friend :< > " \' &')
        self.assertEqual(result, 'PRIVMSG friend :< > " \' &')
示例#3
0
    def test_message_out_cb_send_tag_ctcp(self):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG friend :\x01CTCP VERSION\x01')
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
            'PRIVMSG friend :\x01CTCP VERSION\x01')
示例#4
0
    def test_message_out_cb_send_tag_non_ascii(self):
        sys.modules['weechat'].config_options[
            'otr.policy.server.nick.friend.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(None, None, 'server',
            ":nick!user@host PRIVMSG friend :\xc3")
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
            "PRIVMSG friend :\xc3 \t  \t\t\t\t \t \t \t    \t\t  \t \t")
示例#5
0
    def test_message_out_cb_send_tag_chanserv(self):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG ChanServ :register channel secret desc')
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
            'PRIVMSG ChanServ :register channel secret desc')
    def test_html_escape_policy_non_ascii(self):
        sys.modules["weechat"].config_options[
            weechat_otr.PYVER.to_str("otr.policy.server.nick.gefährte.html_escape")
        ] = "on"
        self.account.getContext("gefährte@server").is_encrypted_fake = True

        result = weechat_otr.message_out_cb(None, None, "server", ":nick!user@host PRIVMSG gefährte :< > \" ' &")
        self.assertEqual(result, weechat_otr.PYVER.to_str("PRIVMSG gefährte :&lt; &gt; \" ' &amp;"))
示例#7
0
    def test_message_out_cb_send_tag_memoserv(self):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG MemoServ :send friend hi')
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
            'PRIVMSG MemoServ :send friend hi')
示例#8
0
    def test_message_out_cb_send_tag_nickserv(self):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(None, None, 'server',
            ":nick!user@host PRIVMSG NickServ :identify secret")
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
            "PRIVMSG NickServ :identify secret")
    def test_html_escape_policy_non_ascii(self):
        sys.modules['weechat'].config_options[
            'otr.policy.server.nick.gefährte.html_escape'] = 'on'

        result = weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG gefährte :< > " \' &')
        self.assertEqual(result, weechat_otr.PYVER.to_str(
            'PRIVMSG gefährte :&lt; &gt; " \' &amp;'))
    def test_html_escape_policy_off_unencrypted(self):
        sys.modules['weechat'].config_options[
            'otr.policy.server.nick.friend.html_escape'] = 'off'
        self.account.getContext('friend@server').is_encrypted_fake = False

        result = weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG friend :< > " \' &')
        self.assertEqual(result, 'PRIVMSG friend :< > " \' &')
示例#11
0
    def test_otr_disabled_require_encryption(self):
        sys.modules['weechat'].config_options.update({
            'otr.policy.default.allow_v2' : 'off',
            'otr.policy.default.require_encryption' : 'on'
        })

        weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG nick2 :hello')

        self.assertNotPrinted('server_nick2_buffer',
            'eval(${color:default}:! ${color:brown}otr${color:default} !:)\t'
            '(color lightred)Your message will not be sent, because policy '
            'requires an encrypted connection.')
        self.assertNotPrinted('server_nick2_buffer',
            'eval(${color:default}:! ${color:brown}otr${color:default} !:)\t'
            '(color lightblue)Wait for the OTR connection or change the '
            'policy to allow clear-text messages:\r\n(color '
            'lightblue)/policy set require_encryption off')
示例#12
0
    def test_require_encryption(self):
        sys.modules['weechat'].config_options.update(
            {'otr.policy.default.require_encryption': 'on'})

        weechat_otr.message_out_cb(None, None, 'server',
                                   ':nick!user@host PRIVMSG nick2 :hello')

        self.assertPrinted(
            'server_nick2_buffer',
            'eval(${color:default}:! ${color:brown}otr${color:default} !:)\t'
            '(color lightred)Your message will not be sent, because policy '
            'requires an encrypted connection.')
        self.assertPrinted(
            'server_nick2_buffer',
            'eval(${color:default}:! ${color:brown}otr${color:default} !:)\t'
            '(color lightblue)Wait for the OTR connection or change the '
            'policy to allow clear-text messages:\r\n(color '
            'lightblue)/otr policy require_encryption off')
    def test_message_out_cb_send_tag_ctcp(self):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(
            None, None, 'server',
            ':nick!user@host PRIVMSG friend :\x01CTCP VERSION\x01')
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
                         'PRIVMSG friend :\x01CTCP VERSION\x01')
    def test_message_out_cb_send_tag_non_ascii(self):
        sys.modules['weechat'].config_options[
            'otr.policy.server.nick.friend.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(
            None, None, 'server', ":nick!user@host PRIVMSG friend :\xc3")
        self.assertEqual(
            weechat_otr.PYVER.to_unicode(result),
            "PRIVMSG friend :\xc3 \t  \t\t\t\t \t \t \t    \t\t  \t \t")
    def test_exception_raised_prints_versions(self):
        sys.modules['weechat'].info_get_hashtable_raise = Exception('test')
        sys.modules['weechat'].infos[('', )]['version'] = '9.8.7'

        version_str = (
            'Versions: weechat-otr {script_version}, '
            'potr {potr_major}.{potr_minor}.{potr_patch}-{potr_sub}, '
            'Python {python_version}, '
            'WeeChat 9.8.7').format(script_version=weechat_otr.SCRIPT_VERSION,
                                    potr_major=potr.VERSION[0],
                                    potr_minor=potr.VERSION[1],
                                    potr_patch=potr.VERSION[2],
                                    potr_sub=potr.VERSION[3],
                                    python_version=platform.python_version())

        weechat_otr.message_out_cb(None, None, 'server',
                                   ':nick!user@host PRIVMSG nick2 :hello')
        self.assertPrintedContains('', version_str)
示例#16
0
    def assertNickIsNotTagged(self, nick):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(None, None, 'server',
            weechat_otr.PYVER.to_str(
            ':nick!user@host PRIVMSG {nick} :send friend hi'.format(
            nick=nick)))
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
            'PRIVMSG {nick} :send friend hi'.format(nick=nick))
示例#17
0
    def test_html_escape_policy_non_ascii(self):
        sys.modules['weechat'].config_options[weechat_otr.PYVER.to_str(
            'otr.policy.server.nick.gefährte.html_escape')] = 'on'
        self.account.getContext('gefährte@server').is_encrypted_fake = True

        result = weechat_otr.message_out_cb(
            None, None, 'server',
            ':nick!user@host PRIVMSG gefährte :< > " \' &')
        self.assertEqual(result, weechat_otr.PYVER.to_str(
            'PRIVMSG gefährte :&lt; &gt; " \' &amp;'))
示例#18
0
    def test_otr_change_my_nick_case(self):
        sys.modules['weechat'].set_server_current_nick('server', 'nick')

        account1 = weechat_otr_test.recording_account.RecordingAccount(
            'nick@server')
        weechat_otr.ACCOUNTS['nick@server'] = account1

        account2 = weechat_otr_test.recording_account.RecordingAccount(
            'nick2@server')
        weechat_otr.ACCOUNTS['nick2@server'] = account2

        context1 = account2.getContext('nick@server')
        context2 = account1.getContext('nick2@server')

        weechat_otr.message_in_cb(
            None, None, 'server', ':nick2!user@host PRIVMSG nick :?OTRv2?')

        sys.modules['weechat'].set_server_current_nick('server', 'nick2')
        self.send_all('nick', 'nick2', context2.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'nick')
        self.send_all('nick2', 'nick', context1.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'nick2')
        self.send_all('nick', 'nick2', context2.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'nick')
        self.send_all('nick2', 'nick', context1.injected)

        self.assertTrue(context1.is_encrypted())
        self.assertTrue(context2.is_encrypted())

        sys.modules['weechat'].set_server_current_nick('server', 'NiCk')
        weechat_otr.message_out_cb(
            None, None, 'server', ':NiCk!user@host PRIVMSG nick2 :hi')

        sys.modules['weechat'].set_server_current_nick('server', 'nick2')

        result = weechat_otr.message_in_cb(
            None, None, 'server',
            ':NiCk!user@host PRIVMSG nick2 :%s' % context2.injected.pop())

        self.assertEqual(result, ':NiCk!user@host PRIVMSG nick2 :hi')
示例#19
0
    def test_message_out_cb_empty_no_send_tag_regex(self):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'
        sys.modules['weechat'].config_options[
            'otr.general.no_send_tag_regex'] = weechat_otr.PYVER.to_str('')

        result = weechat_otr.message_out_cb(None, None, 'server',
            weechat_otr.PYVER.to_str(":nick!user@host PRIVMSG friend :hi"))
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
            "PRIVMSG friend :hi \t  \t\t\t\t \t \t \t    \t\t  \t \t")
示例#20
0
    def test_otr_change_my_nick_case(self):
        sys.modules['weechat'].set_server_current_nick('server', 'nick')

        account1 = weechat_otr_test.recording_account.RecordingAccount(
            'nick@server')
        weechat_otr.ACCOUNTS['nick@server'] = account1

        account2 = weechat_otr_test.recording_account.RecordingAccount(
            'nick2@server')
        weechat_otr.ACCOUNTS['nick2@server'] = account2

        context1 = account2.getContext('nick@server')
        context2 = account1.getContext('nick2@server')

        weechat_otr.message_in_cb(None, None, 'server',
                                  ':nick2!user@host PRIVMSG nick :?OTRv2?')

        sys.modules['weechat'].set_server_current_nick('server', 'nick2')
        self.send_all('nick', 'nick2', context2.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'nick')
        self.send_all('nick2', 'nick', context1.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'nick2')
        self.send_all('nick', 'nick2', context2.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'nick')
        self.send_all('nick2', 'nick', context1.injected)

        self.assertTrue(context1.is_encrypted())
        self.assertTrue(context2.is_encrypted())

        sys.modules['weechat'].set_server_current_nick('server', 'NiCk')
        weechat_otr.message_out_cb(None, None, 'server',
                                   ':NiCk!user@host PRIVMSG nick2 :hi')

        sys.modules['weechat'].set_server_current_nick('server', 'nick2')

        result = weechat_otr.message_in_cb(
            None, None, 'server',
            ':NiCk!user@host PRIVMSG nick2 :%s' % context2.injected.pop())

        self.assertEqual(result, ':NiCk!user@host PRIVMSG nick2 :hi')
    def assertNickIsNotTagged(self, nick):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'

        result = weechat_otr.message_out_cb(
            None, None, 'server',
            weechat_otr.PYVER.to_str(
                ':nick!user@host PRIVMSG {nick} :send friend hi'.format(
                    nick=nick)))
        self.assertEqual(weechat_otr.PYVER.to_unicode(result),
                         'PRIVMSG {nick} :send friend hi'.format(nick=nick))
    def test_html_escape_policy_non_ascii(self):
        sys.modules['weechat'].config_options[weechat_otr.PYVER.to_str(
            'otr.policy.server.nick.gefährte.html_escape')] = 'on'
        self.account.getContext('gefährte@server').is_encrypted_fake = True

        result = weechat_otr.message_out_cb(
            None, None, 'server',
            ':nick!user@host PRIVMSG gefährte :< > " \' &')
        self.assertEqual(
            result,
            weechat_otr.PYVER.to_str('PRIVMSG gefährte :&lt; &gt; " \' &amp;'))
示例#23
0
    def test_exception_raised_prints_versions(self):
        sys.modules['weechat'].info_get_hashtable_raise = Exception('test')
        sys.modules['weechat'].infos[('',)]['version'] = '9.8.7'

        version_str = (
            'Versions: weechat-otr {script_version}, '
            'potr {potr_major}.{potr_minor}.{potr_patch}-{potr_sub}, '
            'Python {python_version}, '
            'WeeChat 9.8.7'
            ).format(
            script_version=weechat_otr.SCRIPT_VERSION,
            potr_major=potr.VERSION[0],
            potr_minor=potr.VERSION[1],
            potr_patch=potr.VERSION[2],
            potr_sub=potr.VERSION[3],
            python_version=platform.python_version())

        weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG nick2 :hello')
        self.assertPrintedContains('', version_str)
    def test_message_out_cb_empty_no_send_tag_regex(self):
        sys.modules['weechat'].config_options[
            'otr.policy.default.send_tag'] = 'on'
        sys.modules['weechat'].config_options[
            'otr.general.no_send_tag_regex'] = weechat_otr.PYVER.to_str('')

        result = weechat_otr.message_out_cb(
            None, None, 'server',
            weechat_otr.PYVER.to_str(":nick!user@host PRIVMSG friend :hi"))
        self.assertEqual(
            weechat_otr.PYVER.to_unicode(result),
            "PRIVMSG friend :hi \t  \t\t\t\t \t \t \t    \t\t  \t \t")
 def test_message_out_cb_nick_with_at(self):
     result = weechat_otr.message_out_cb(
         None, None, 'server', ':nick!user@host PRIVMSG @#chan :hello')
     self.assertEqual(result, ':nick!user@host PRIVMSG @#chan :hello')
示例#26
0
    def test_otr_session_non_ascii(self):
        sys.modules['weechat'].set_server_current_nick('server', 'gefährte')
        sys.modules['weechat'].infos.update({
            (weechat_otr.PYVER.to_str('server,gefährte'), ): {
                'irc_buffer': 'server_gefährte_buffer'
            },
            (weechat_otr.PYVER.to_str('server,gefährte2'), ): {
                'irc_buffer': 'server_gefährte2_buffer'
            },
        })
        sys.modules['weechat'].buffers.update({
            weechat_otr.PYVER.to_str('server_gefährte_buffer'): {
                'localvar_type': 'private',
                'localvar_channel': 'gefährte',
                'localvar_server': 'server',
                'name': 'server_gefährte_buffer_name',
                'plugin': 'irc',
            },
            weechat_otr.PYVER.to_str('server_gefährte2_buffer'): {
                'localvar_type': 'private',
                'localvar_channel': 'gefährte2',
                'localvar_server': 'server',
                'name': 'server_gefährte2_buffer_name',
                'plugin': 'irc',
            },
        })

        account1 = weechat_otr_test.recording_account.RecordingAccount(
            'gefährte@server')
        weechat_otr.ACCOUNTS['gefährte@server'] = account1

        account2 = weechat_otr_test.recording_account.RecordingAccount(
            'gefährte2@server')
        weechat_otr.ACCOUNTS['gefährte2@server'] = account2

        context1 = account2.getContext('gefährte@server')
        context2 = account1.getContext('gefährte2@server')

        weechat_otr.message_in_cb(
            None, None, 'server',
            ':gefährte2!user@host PRIVMSG gefährte :?OTRv2?')

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte2')
        self.send_all('gefährte', 'gefährte2', context2.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte')
        self.send_all('gefährte2', 'gefährte', context1.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte2')
        self.send_all('gefährte', 'gefährte2', context2.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte')
        self.send_all('gefährte2', 'gefährte', context1.injected)

        self.assertTrue(context1.is_encrypted())
        self.assertTrue(context2.is_encrypted())

        weechat_otr.message_out_cb(
            None, None, 'server', ':gefährte!user@host PRIVMSG gefährte2 :hi')

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte2')

        result = weechat_otr.message_in_cb(
            None, None, 'server',
            ':gefährte!user@host PRIVMSG gefährte2 :%s' % \
            context2.injected.pop())

        self.assertEqual(
            result,
            weechat_otr.PYVER.to_str(
                ':gefährte!user@host PRIVMSG gefährte2 :hi'))
示例#27
0
 def test_message_out_cb(self):
     result = weechat_otr.message_out_cb(None, None, 'server',
         ':nick!user@host PRIVMSG friend :hello')
     self.assertEqual(result, 'PRIVMSG friend :hello')
 def test_message_out_cb(self):
     result = weechat_otr.message_out_cb(
         None, None, 'server', ':nick!user@host PRIVMSG friend :hello')
     self.assertEqual(result, 'PRIVMSG friend :hello')
 def test_default_html_escape_policy(self):
     result = weechat_otr.message_out_cb(None, None, 'server',
         ':nick!user@host PRIVMSG friend :< > " \' &')
     self.assertEqual(result, 'PRIVMSG friend :< > " \' &')
示例#30
0
    def test_exception_raised_prints_traceback(self):
        sys.modules['weechat'].info_get_hashtable_raise = Exception('test')

        weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG nick2 :hello')
        self.assertPrintedContains('', 'Exception: test')
    def test_exception_raised_returns_empty_string(self):
        sys.modules['weechat'].info_get_hashtable_raise = Exception('test')

        result = weechat_otr.message_out_cb(
            None, None, 'server', ':nick!user@host PRIVMSG nick2 :hello')
        self.assertEqual(result, '')
示例#32
0
 def test_message_out_cb_nick_with_at(self):
     result = weechat_otr.message_out_cb(None, None, 'server',
         ':nick!user@host PRIVMSG @#chan :hello')
     self.assertEqual(result, ':nick!user@host PRIVMSG @#chan :hello')
示例#33
0
    def test_html_escape_policy_off_unencrypted(self):
        sys.modules["weechat"].config_options["otr.policy.server.nick.friend.html_escape"] = "off"
        self.account.getContext("friend@server").is_encrypted_fake = False

        result = weechat_otr.message_out_cb(None, None, "server", ":nick!user@host PRIVMSG friend :< > \" ' &")
        self.assertEqual(result, "PRIVMSG friend :< > \" ' &")
 def test_default_html_escape_policy(self):
     result = weechat_otr.message_out_cb(
         None, None, 'server', ':nick!user@host PRIVMSG friend :< > " \' &')
     self.assertEqual(result, 'PRIVMSG friend :< > " \' &')
示例#35
0
 def test_default_html_escape_policy(self):
     result = weechat_otr.message_out_cb(None, None, "server", ":nick!user@host PRIVMSG friend :< > \" ' &")
     self.assertEqual(result, "PRIVMSG friend :< > \" ' &")
示例#36
0
    def test_exception_raised_returns_empty_string(self):
        sys.modules['weechat'].info_get_hashtable_raise = Exception('test')

        result = weechat_otr.message_out_cb(None, None, 'server',
            ':nick!user@host PRIVMSG nick2 :hello')
        self.assertEqual(result, '')
示例#37
0
    def test_otr_session_non_ascii(self):
        sys.modules['weechat'].set_server_current_nick('server', 'gefährte')
        sys.modules['weechat'].infos.update({
            (weechat_otr.PYVER.to_str('server,gefährte'),) :
                {'irc_buffer' : 'server_gefährte_buffer'},
            (weechat_otr.PYVER.to_str('server,gefährte2'),) :
                {'irc_buffer' : 'server_gefährte2_buffer'},
            })
        sys.modules['weechat'].buffers.update({
            weechat_otr.PYVER.to_str('server_gefährte_buffer') : {
                'localvar_type' : 'private',
                'localvar_channel' : 'gefährte',
                'localvar_server' : 'server',
                'name' : 'server_gefährte_buffer_name',
                'plugin' : 'irc',
                },
            weechat_otr.PYVER.to_str('server_gefährte2_buffer') : {
                'localvar_type' : 'private',
                'localvar_channel' : 'gefährte2',
                'localvar_server' : 'server',
                'name' : 'server_gefährte2_buffer_name',
                'plugin' : 'irc',
                },
            })

        account1 = weechat_otr_test.recording_account.RecordingAccount(
            'gefährte@server')
        weechat_otr.ACCOUNTS['gefährte@server'] = account1

        account2 = weechat_otr_test.recording_account.RecordingAccount(
            'gefährte2@server')
        weechat_otr.ACCOUNTS['gefährte2@server'] = account2

        context1 = account2.getContext('gefährte@server')
        context2 = account1.getContext('gefährte2@server')

        weechat_otr.message_in_cb(
            None, None, 'server',
            ':gefährte2!user@host PRIVMSG gefährte :?OTRv2?')

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte2')
        self.send_all('gefährte', 'gefährte2', context2.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte')
        self.send_all('gefährte2', 'gefährte', context1.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte2')
        self.send_all('gefährte', 'gefährte2', context2.injected)

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte')
        self.send_all('gefährte2', 'gefährte', context1.injected)

        self.assertTrue(context1.is_encrypted())
        self.assertTrue(context2.is_encrypted())

        weechat_otr.message_out_cb(
            None, None, 'server', ':gefährte!user@host PRIVMSG gefährte2 :hi')

        sys.modules['weechat'].set_server_current_nick('server', 'gefährte2')

        result = weechat_otr.message_in_cb(
            None, None, 'server',
            ':gefährte!user@host PRIVMSG gefährte2 :%s' % \
            context2.injected.pop())

        self.assertEqual(result, weechat_otr.PYVER.to_str(
            ':gefährte!user@host PRIVMSG gefährte2 :hi'))
    def test_exception_raised_prints_traceback(self):
        sys.modules['weechat'].info_get_hashtable_raise = Exception('test')

        weechat_otr.message_out_cb(None, None, 'server',
                                   ':nick!user@host PRIVMSG nick2 :hello')
        self.assertPrintedContains('', 'Exception: test')