Exemplo n.º 1
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()
Exemplo n.º 2
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)
Exemplo 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()
Exemplo n.º 4
0
    def test_rcv_submit_nack(self):
        client = Client('localhost', TEST_SERVER_PORT, timeout=1)
        client.connect()
        client.bind_receiver()

        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)
Exemplo n.º 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))
Exemplo n.º 6
0
    def test_receipt_through_queue(self):
        pubc = Client(unix_sock=self.PUB_SERVER_SOCK, timeout=1)
        pubc.connect()
        pubc.bind_transmitter(system_id="qtc", password="******")

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

        pubc.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 = pubc.read_pdu()
        deliv_sm = subc.read_pdu()
        self.assert_resp_valid(submit_resp, deliv_sm)
Exemplo n.º 7
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()