Ejemplo n.º 1
0
    def test_async_eqlinks(self):
        c1 = Client('localhost', TEST_SERVER_PORT, timeout=1)
        c1.connect()
        cmd1 = make_pdu('enquire_link', client=c1)
        cmd1.sequence = 1
        c1.send_pdu(cmd1)

        c2 = Client('localhost', TEST_SERVER_PORT, timeout=1)
        c2.connect()
        cmd2 = make_pdu('enquire_link', client=c2)
        cmd2.sequence = 2
        c2.send_pdu(cmd2)

        c3 = Client('localhost', TEST_SERVER_PORT, timeout=1)
        c3.connect()
        cmd3 = make_pdu('enquire_link', client=c3)
        cmd3.sequence = 3
        c3.send_pdu(cmd3)

        # Should not block
        resp3 = c3.read_pdu()
        resp1 = c1.read_pdu()
        resp2 = c2.read_pdu()

        # Should dispatch correctly
        self.assertEqual(resp1.sequence, 1)
        self.assertEqual(resp2.sequence, 2)
        self.assertEqual(resp3.sequence, 3)
Ejemplo n.º 2
0
    def test_no_success_receipt_required(self):
        t = Client('localhost', TEST_SERVER_PORT, timeout=1)
        t.connect()
        t.bind_transmitter(system_id="mtc", password="******")

        r1 = Client('localhost', TEST_SERVER_PORT, timeout=1)
        r1.connect()
        r1.bind_receiver(system_id="mtc", password="******")

        message_text = "Hello world!"

        ssm = t.send_message(
            esm_class=consts.SMPP_MSGMODE_STOREFORWARD,
            registered_delivery=
            0b11100010,  # Request delivery receipt on failure only
            source_addr_ton=12,
            source_addr_npi=34,
            source_addr="src",
            dest_addr_ton=56,
            dest_addr_npi=67,
            destination_addr="dst",
            short_message=message_text.encode('ascii'))

        with self.assertRaises(socket.timeout):
            r1.read_pdu()
Ejemplo n.º 3
0
    def test_master_delivery_receipt(self):
        # Have to let workers establish pub-sub connection among eash other.
        time.sleep(3)

        t = Client('localhost', TEST_SERVER_PORT, timeout=1)
        t.connect()
        t.bind_transmitter(system_id="mtc", password="******")

        RECEIVERS_COUNT = 6
        receivers = []
        for _ in range(RECEIVERS_COUNT):
            r = Client('localhost', TEST_SERVER_PORT, timeout=1)
            r.connect()
            r.bind_receiver(system_id="mtc", password="******")
            receivers.append(r)

        EAVESDROPPERS_COUNT = 6
        eavesdroppers = []
        for _ in range(EAVESDROPPERS_COUNT):
            e = Client('localhost', TEST_SERVER_PORT, timeout=1)
            e.connect()
            e.bind_receiver(system_id="nomtc", password="******")
            eavesdroppers.append(e)

        for port in self.master._all_queue_ports():
            wait_til_open(socket.AF_INET, ('localhost', port))

        message_text = "Test message"
        t.send_message(
            esm_class=consts.SMPP_MSGMODE_STOREFORWARD,
            registered_delivery=0b00000001,  # Request delivery receipt
            source_addr_ton=12,
            source_addr_npi=34,
            source_addr="src",
            dest_addr_ton=56,
            dest_addr_npi=67,
            destination_addr="dst",
            short_message=message_text.encode('ascii'))

        submit_resp = t.read_pdu()

        for r in receivers:
            receipt = r.read_pdu()
            self.assert_receipt_valid(submit_resp, receipt)

        for e in eavesdroppers:
            with self.assertRaises(socket.timeout):
                e.read_pdu()
Ejemplo n.º 4
0
    def test_self_listening_queue_server(self):
        c = Client(unix_sock=self.UNI_SERVER_SOCK, timeout=1)
        c.connect()
        c.bind_transceiver(system_id="qtc", password="******")

        c.send_message(esm_class=consts.SMPP_MSGMODE_STOREFORWARD,
                       registered_delivery=0b00000001,
                       source_addr_ton=12,
                       source_addr_npi=34,
                       source_addr="src",
                       dest_addr_ton=56,
                       dest_addr_npi=67,
                       destination_addr="dst",
                       short_message=b'Hello world')

        submit_resp = c.read_pdu()
        deliv_sm = c.read_pdu()
        self.assert_resp_valid(submit_resp, deliv_sm)
Ejemplo n.º 5
0
    def test_master_enquire_link(self):
        c = Client('localhost', TEST_SERVER_PORT, timeout=1)
        c.connect()

        elink = make_pdu('enquire_link', client=c)
        elink.sequence = 12
        c.send_pdu(elink)

        resp = c.read_pdu()
        self.assertEqual(elink.sequence, resp.sequence)
Ejemplo n.º 6
0
    def _test_error_receipt(self, prov_status: external.DeliveryStatus,
                            exp_rct_status: str):
        self.provider.status = prov_status

        t = Client('localhost', TEST_SERVER_PORT, timeout=1)
        t.connect()
        t.bind_transmitter(system_id="mtc", password="******")

        r1 = Client('localhost', TEST_SERVER_PORT, timeout=1)
        r1.connect()
        r1.bind_receiver(system_id="mtc", password="******")

        message_text = "Hello world!"

        ssm = t.send_message(
            esm_class=consts.SMPP_MSGMODE_STOREFORWARD,
            registered_delivery=
            0b11100010,  # Request delivery receipt with noise bits
            source_addr_ton=12,
            source_addr_npi=34,
            source_addr="src",
            dest_addr_ton=56,
            dest_addr_npi=67,
            destination_addr="dst",
            short_message=message_text.encode('ascii'))

        ssmr = t.read_pdu()

        receipt_regex = r'^id:(\S+) sub:(\d+) dlvrd:(\d+) submit date:(\d+) done date:(\d+) stat:(\S+) err:(\d+) text:(.+)$'

        rec = r1.read_pdu()
        self.assertEqual(rec.command, 'deliver_sm')
        self.assertNotEqual(int(rec.esm_class) & 0b00000100, 0)

        m = re.search(receipt_regex, rec.short_message.decode('ascii'))
        self.assertIsNotNone(m, msg="Receipt text does not match regex")

        rct_id, _, rct_dlvr, _, _, rct_stat, rct_err, rct_text = m.groups()
        self.assertEqual(rct_id, ssmr.message_id.decode('ascii'))
        self.assertEqual(int(rct_dlvr), 0)
        self.assertEqual(rct_stat, exp_rct_status)
        self.assertEqual(int(rct_err), 1)
        self.assertTrue(message_text.startswith(rct_text))
Ejemplo n.º 7
0
    def test_unix_sock_enquire_link(self):
        # Simple sanity test
        client = Client(unix_sock=self.UNIX_SOCK)
        client.connect()

        elink = make_pdu('enquire_link', client=client)
        elink.sequence = 1
        client.send_pdu(elink)

        elink_resp = client.read_pdu()
        self.assertEqual(elink_resp.sequence, elink.sequence)
Ejemplo n.º 8
0
    def test_receipt_delivery(self):
        t = Client('localhost', TEST_SERVER_PORT, timeout=1)
        t.connect()
        t.bind_transmitter(system_id="mtc", password="******")

        r1 = Client('localhost', TEST_SERVER_PORT, timeout=1)
        r1.connect()
        r1.bind_receiver(system_id="mtc", password="******")

        r2 = Client('localhost', TEST_SERVER_PORT, timeout=1)
        r2.connect()
        r2.bind_receiver(system_id="mtc", password="******")

        rx = Client('localhost', TEST_SERVER_PORT, timeout=1)
        rx.connect()
        rx.bind_receiver(system_id="nomtc", password="******")

        message_text = "Hello world!"

        ssm = t.send_message(
            esm_class=consts.SMPP_MSGMODE_STOREFORWARD,
            registered_delivery=
            0b11100001,  # Request delivery receipt with noise bits
            source_addr_ton=12,
            source_addr_npi=34,
            source_addr="src",
            dest_addr_ton=56,
            dest_addr_npi=67,
            destination_addr="dst",
            short_message=message_text.encode('ascii'))

        r1rec = r1.read_pdu()
        self.assertEqual(r1rec.command, 'deliver_sm')
        self.assertNotEqual(int(r1rec.esm_class) & 0b00000100, 0)

        r2rec = r2.read_pdu()
        self.assertEqual(r2rec.command, 'deliver_sm')
        self.assertNotEqual(int(r2rec.esm_class) & 0b00000100, 0)

        with self.assertRaises(socket.timeout):
            rx.read_pdu()
Ejemplo n.º 9
0
    def test_enquire_link_resp(self):
        client = Client('localhost', TEST_SERVER_PORT, timeout=1)
        client.connect()

        command = make_pdu('enquire_link', client=client)
        client.send_pdu(command)
        resp = client.read_pdu()

        self.assertEqual(resp.command, 'enquire_link_resp')
        self.assertEqual(resp.sequence, command.sequence)

        client.disconnect()
Ejemplo n.º 10
0
    def test_nobind_nack(self):
        client = Client('localhost', TEST_SERVER_PORT, timeout=1)
        client.connect()

        cmd = make_pdu('submit_sm',
                       client=client,
                       source_addr_ton=12,
                       source_addr="src",
                       dest_addr_ton=34,
                       destination_addr="dst",
                       short_message=b"Hello world")
        client.send_pdu(cmd)
        resp = client.read_pdu()

        self.assertEqual(resp.command, 'generic_nack')
        self.assertEqual(resp.sequence, cmd.sequence)
        self.assertEqual(resp.status, consts.SMPP_ESME_RINVBNDSTS)
Ejemplo n.º 11
0
    def test_multiprod_multicons(self):
        subc1 = Client(unix_sock=self.SUB_SERVER_SOCK, timeout=1)
        subc1.connect()
        subc1.bind_receiver(system_id="qtc", password="******")

        subc2 = Client(unix_sock=self.SUB_SERVER_2_SOCK, timeout=1)
        subc2.connect()
        subc2.bind_receiver(system_id="qtc", password="******")

        pubc1 = Client(unix_sock=self.PUB_SERVER_SOCK, timeout=1)
        pubc1.connect()
        pubc1.bind_transmitter(system_id="qtc", password="******")

        pubc1.send_message(esm_class=consts.SMPP_MSGMODE_STOREFORWARD,
                           registered_delivery=0b00000001,
                           source_addr_ton=12,
                           source_addr_npi=34,
                           source_addr="src",
                           dest_addr_ton=56,
                           dest_addr_npi=67,
                           destination_addr="dst",
                           short_message=b'Hello world')

        submit_resp_1 = pubc1.read_pdu()

        dsm1 = subc1.read_pdu()
        self.assert_resp_valid(submit_resp_1, dsm1)

        dsm2 = subc2.read_pdu()
        self.assert_resp_valid(submit_resp_1, dsm2)

        pubc2 = Client(unix_sock=self.PUB_SERVER_2_SOCK, timeout=1)
        pubc2.connect()
        pubc2.bind_transmitter(system_id="qtc", password="******")

        pubc2.send_message(esm_class=consts.SMPP_MSGMODE_STOREFORWARD,
                           registered_delivery=0b00000001,
                           source_addr_ton=12,
                           source_addr_npi=34,
                           source_addr="src",
                           dest_addr_ton=56,
                           dest_addr_npi=67,
                           destination_addr="dst",
                           short_message=b'Hello world')

        submit_resp_2 = pubc2.read_pdu()

        dsm1 = subc1.read_pdu()
        self.assert_resp_valid(submit_resp_2, dsm1)

        dsm2 = subc2.read_pdu()
        self.assert_resp_valid(submit_resp_2, dsm2)
Ejemplo n.º 12
0
    def test_store_and_forward(self):
        t = Client('localhost', TEST_SERVER_PORT, timeout=1)
        t.connect()
        t.bind_transmitter(system_id="mtc", password="******")

        message_text = "Hello world!"

        ssm = t.send_message(
            esm_class=consts.SMPP_MSGMODE_STOREFORWARD,
            registered_delivery=
            0b11100001,  # Request delivery receipt with noise bits
            source_addr_ton=12,
            source_addr_npi=34,
            source_addr="src",
            dest_addr_ton=56,
            dest_addr_npi=67,
            destination_addr="dst",
            short_message=message_text.encode('ascii'))

        ssmr = t.read_pdu()
        self.assertEqual(ssmr.command, 'submit_sm_resp')
        self.assertEqual(ssmr.sequence, ssm.sequence)

        self.provider.wait_for_message(timeout=1)

        messages = self.provider.get_messages()
        self.assertEqual(len(messages), 1)

        msg = messages[0]
        self.assertEqual(msg.system_id, "mtc")
        self.assertEqual(msg.password, "pwd")
        self.assertEqual(msg.source_addr_ton, 12)
        self.assertEqual(msg.source_addr_npi, 34)
        self.assertEqual(msg.source_addr, "src")
        self.assertEqual(msg.dest_addr_ton, 56)
        self.assertEqual(msg.dest_addr_npi, 67)
        self.assertEqual(msg.destination_addr, "dst")
        self.assertEqual(msg.body, message_text)