Beispiel #1
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)
Beispiel #2
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()
Beispiel #3
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()
Beispiel #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)
Beispiel #5
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))
Beispiel #6
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()
Beispiel #7
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)