Exemplo n.º 1
0
    def test_pub_ident_checked(self):
        c = self.make_connection()
        name, rand = readinfo(parse(c.transport.write)[0][1])
        c.data_received(msgauth(rand, 'test', 'secret'))
        c.data_received(msgpublish('wrong-ident', 'test-chan2', b'c'))

        assert parse(c.transport.write)[1][1] == b'Invalid authkey in message, ident=wrong-ident'
Exemplo n.º 2
0
    def test_permission_to_pub(self):
        c = self.make_connection()
        name, rand = readinfo(parse(c.transport.write)[0][1])
        c.data_received(msgauth(rand, 'test', 'secret'))
        c.data_received(msgpublish('test', 'test-chan2', b'c'))

        assert parse(c.transport.write)[1][1] == b'Authkey not allowed to pub here. ident=test, chan=test-chan2'
Exemplo n.º 3
0
    def test_auth_unsubscribe(self):
        c = self.make_connection()
        name, rand = readinfo(parse(c.transport.write)[0][1])
        c.data_received(msgauth(rand, 'test', 'secret'))

        c.data_received(msgsubscribe('test', 'test-chan'))
        c.data_received(msgpublish('test', 'test-chan', b'c'))
        c.data_received(msgunsubscribe('test', 'test-chan'))
        c.data_received(msgpublish('test', 'test-chan', b'c'))
        c.data_received(msgsubscribe('test', 'test-chan'))
        c.data_received(msgpublish('test', 'test-chan', b'c'))

        messages = parse(c.transport.write)
        for msg in messages[1:]:
            assert readpublish(msg[1]) == ('test', 'test-chan', b'c')

        # 1 auth and 2 publish
        assert len(messages) == 3
Exemplo n.º 4
0
    def test_auth_success(self):
        c = self.make_connection()
        name, rand = readinfo(parse(c.transport.write)[0][1])
        c.data_received(msgauth(rand, 'test', 'secret'))
        c.data_received(msgsubscribe('test', 'test-chan'))
        c.data_received(msgpublish('test', 'test-chan', b'c'))

        assert readpublish(parse(c.transport.write)[1][1]) == ('test',
                                                               'test-chan',
                                                               b'c')
Exemplo n.º 5
0
    def test_multiple_subscribers(self):
        subscribers = []
        for i in range(5):
            c = self.make_connection()
            name, rand = readinfo(parse(c.transport.write)[0][1])
            c.data_received(msgauth(rand, 'test', 'secret'))
            c.data_received(msgsubscribe('test', 'test-chan'))
            subscribers.append(c)

        c = self.make_connection()
        name, rand = readinfo(parse(c.transport.write)[0][1])
        c.data_received(msgauth(rand, 'test', 'secret'))
        c.data_received(msgpublish('test', 'test-chan', b'c'))

        for c in subscribers:
            msgs = parse(c.transport.write)
            assert readpublish(msgs[1][1]) == ('test', 'test-chan', b'c')
Exemplo n.º 6
0
 def publish(self, channel, payload):
     self._reactor.write(msgpublish(self.ident, channel, payload))
Exemplo n.º 7
0
 def publish(self, ident, channel, payload):
     self.transport.write(msgpublish(ident, channel, payload))
Exemplo n.º 8
0
    def test_must_auth(self):
        c = self.make_connection()
        c.data_received(msgpublish('a', 'b', b'c'))

        assert parse(c.transport.write)[0][1][:-4] == b'\x07hpfeeds'
        assert parse(c.transport.write)[1][1] == b'First message was not AUTH'
Exemplo n.º 9
0
 def forward(self, ident, chan, data):
     self.write(msgpublish(ident, chan, data))
Exemplo n.º 10
0
 def test_msgpublish(self):
     msg = msgpublish('ident', 'chan', 'somedata')
     assert msg == b'\x00\x00\x00\x18\x03\x05ident\x04chansomedata'