Пример #1
0
 def handle_bind_transceiver(self, pdu):
     if pdu['header']['command_status'] == 'ESME_ROK':
         sequence_number = pdu['header']['sequence_number']
         system_id = pdu['body']['mandatory_parameters']['system_id']
         pdu_resp = BindTransceiverResp(sequence_number,
                                        system_id=system_id)
         self.send_pdu(pdu_resp)
Пример #2
0
    def test_bind_no_timeout(self):
        esme = self.get_esme()
        esme.connectionMade()

        self.assertEqual(True, esme.transport.connected)
        self.assertNotEqual(None, esme._lose_conn)

        esme.handle_bind_transceiver_resp(
            unpack_pdu(BindTransceiverResp(1).get_bin()))

        self.assertEqual(True, esme.transport.connected)
        self.assertEqual(None, esme._lose_conn)
        esme.lc_enquire.stop()
Пример #3
0
    def test_bind_mode_TRX(self):
        """
        FakeSMSC can accept tranceiver bind requests.
        """
        fake_smsc = FakeSMSC()
        client = self.successResultOf(self.connect(fake_smsc))
        self.assertEqual(client.received, b"")

        bind_d = fake_smsc.bind()
        yield client.write(BindTransceiver(0).get_bin())
        yield client.write(EnquireLink(1).get_bin())
        self.assertEqual(
            client.received, b"".join([
                BindTransceiverResp(0).get_bin(),
                EnquireLinkResp(1).get_bin()
            ]))
        yield wait0()
        self.successResultOf(bind_d)
Пример #4
0
    def test_bind_and_disconnect(self):
        callbacks_called = []
        esme = yield self.get_unbound_esme(
            callbacks={
                'connect': lambda client: callbacks_called.append('connect'),
                'disconnect': lambda: callbacks_called.append('disconnect'),
            })
        yield esme.connectionMade()

        esme.handle_bind_transceiver_resp(
            unpack_pdu(BindTransceiverResp(1).get_bin()))

        self.assertEqual(['connect'], callbacks_called)
        esme.lc_enquire.stop()
        yield esme.lc_enquire.deferred

        yield esme.transport.loseConnection()

        self.assertEqual(['connect', 'disconnect'], callbacks_called)
        self.assertEqual(False, esme.transport.connected)
Пример #5
0
    def test_bind_explicit(self):
        """
        FakeSMSC can bind using a PDU explicitly passed in.
        """
        fake_smsc = FakeSMSC()
        client = self.successResultOf(self.connect(fake_smsc))
        self.assertEqual(client.received, b"")

        bind_d = fake_smsc.bind(BindTransceiver(0).obj)
        yield wait0()
        # Bind response received.
        self.assertNoResult(bind_d)
        self.assertEqual(client.received, BindTransceiverResp(0).get_bin())
        client.received = b""

        yield client.write(EnquireLink(1).get_bin())
        # enquire_link response received.
        self.assertNoResult(bind_d)
        self.assertEqual(client.received, EnquireLinkResp(1).get_bin())

        yield wait0()
        # Bind complete.
        self.successResultOf(bind_d)
Пример #6
0
    def test_bind(self):
        """
        FakeSMSC can accept a bind request and respond to the first
        enquire_link.
        """
        fake_smsc = FakeSMSC()
        client = self.successResultOf(self.connect(fake_smsc))
        self.assertEqual(client.received, b"")

        bind_d = fake_smsc.bind()
        yield client.write(BindTransceiver(0).get_bin())
        # Bind response received.
        self.assertNoResult(bind_d)
        self.assertEqual(client.received, BindTransceiverResp(0).get_bin())
        client.received = b""

        yield client.write(EnquireLink(1).get_bin())
        # enquire_link response received.
        self.assertNoResult(bind_d)
        self.assertEqual(client.received, EnquireLinkResp(1).get_bin())

        yield wait0()
        # Bind complete.
        self.successResultOf(bind_d)
Пример #7
0
    def test_match_resp(self):
        message1 = self.mkmsg_out(
            message_id='444',
            content="hello world",
            to_addr="1111111111")
        sequence_num1 = self.esme.getSeq()
        response1 = SubmitSMResp(sequence_num1, "3rd_party_id_1")
        yield self.transport._process_message(message1)

        message2 = self.mkmsg_out(
            message_id='445',
            content="hello world",
            to_addr="1111111111")
        sequence_num2 = self.esme.getSeq()
        response2 = SubmitSMResp(sequence_num2, "3rd_party_id_2")
        yield self.transport._process_message(message2)

        # respond out of order - just to keep things interesting
        self.esme.handleData(response2.get_bin())
        self.esme.handleData(response1.get_bin())

        self.assertEqual([
                self.mkmsg_ack('445', '3rd_party_id_2'),
                self.mkmsg_ack('444', '3rd_party_id_1'),
                ], self.get_dispatched_events())

        message3 = self.mkmsg_out(
            message_id=446,
            content="hello world",
            to_addr="1111111111")
        sequence_num3 = self.esme.getSeq()
        response3 = SubmitSMResp(sequence_num3, "3rd_party_id_3",
                command_status="ESME_RSUBMITFAIL")
        self.transport._process_message(message3)
        self.esme.handleData(response3.get_bin())
        self.assertEqual([self.mkmsg_ack('446', '3rd_party_id_3')],
                         self.get_dispatched_events()[2:])

        self.assertEqual([self.mkmsg_fail({'id': '446'}, 'ESME_RSUBMITFAIL')],
                         self.get_dispatched_failures())

        message4 = self.mkmsg_out(
            message_id=447,
            content="hello world",
            to_addr="1111111111")
        sequence_num4 = self.esme.getSeq()
        response4 = SubmitSMResp(sequence_num4, "3rd_party_id_4",
                command_status="ESME_RTHROTTLED")
        self.transport._process_message(message4)
        self.esme.handleData(response4.get_bin())
        self.assertEqual([self.mkmsg_ack('447', '3rd_party_id_4')],
                         self.get_dispatched_events()[3:])
        self.assertTrue(self.transport.throttle_invoked_via_pdu)

        fail_msg = self.mkmsg_out(
            message_id=555,
            content="hello world",
            to_addr="1111111111")

        self.transport.send_failure(fail_msg, Exception("Foo"), "testing")

        self.assertEqual([self.mkmsg_fail(fail_msg.payload, "testing")],
                         self.get_dispatched_failures()[1:])

        # Some error codes would occur on bind attempts
        bind_dispatch_methods = {
            "ESME_ROK": self.transport.ok,
            "ESME_RINVBNDSTS": self.transport.conn_tempfault,
            "ESME_RALYBND": self.transport.conn_tempfault,
            "ESME_RSYSERR": self.transport.conn_permfault,
            "ESME_RBINDFAIL": self.transport.conn_permfault,
            "ESME_RINVPASWD": self.transport.conn_permfault,
            "ESME_RINVSYSID": self.transport.conn_permfault,
            "ESME_RINVSERTYP": self.transport.conn_permfault,
        }

        # Some error codes would occur post bind i.e. on submission attempts
        submit_dispatch_methods = {
            "ESME_RINVMSGLEN": self.transport.mess_permfault,
            "ESME_RINVCMDLEN": self.transport.mess_permfault,
            "ESME_RINVCMDID": self.transport.mess_permfault,

            "ESME_RINVPRTFLG": self.transport.mess_permfault,
            "ESME_RINVREGDLVFLG": self.transport.mess_permfault,

            "ESME_RINVSRCADR": self.transport.mess_permfault,
            "ESME_RINVDSTADR": self.transport.mess_permfault,
            "ESME_RINVMSGID": self.transport.mess_permfault,

            "ESME_RCANCELFAIL": self.transport.mess_permfault,
            "ESME_RREPLACEFAIL": self.transport.mess_permfault,

            "ESME_RMSGQFUL": self.transport.conn_throttle,

            "ESME_RINVNUMDESTS": self.transport.mess_permfault,
            "ESME_RINVDLNAME": self.transport.mess_permfault,
            "ESME_RINVDESTFLAG": self.transport.mess_permfault,
            "ESME_RINVSUBREP": self.transport.mess_permfault,
            "ESME_RINVESMCLASS": self.transport.mess_permfault,
            "ESME_RCNTSUBDL": self.transport.mess_permfault,

            "ESME_RSUBMITFAIL": self.transport.mess_tempfault,

            "ESME_RINVSRCTON": self.transport.mess_permfault,
            "ESME_RINVSRCNPI": self.transport.mess_permfault,
            "ESME_RINVDSTTON": self.transport.mess_permfault,
            "ESME_RINVDSTNPI": self.transport.mess_permfault,
            "ESME_RINVSYSTYP": self.transport.conn_permfault,
            "ESME_RINVREPFLAG": self.transport.mess_permfault,

            "ESME_RINVNUMMSGS": self.transport.mess_tempfault,

            "ESME_RTHROTTLED": self.transport.conn_throttle,

            "ESME_RINVSCHED": self.transport.mess_permfault,
            "ESME_RINVEXPIRY": self.transport.mess_permfault,
            "ESME_RINVDFTMSGID": self.transport.mess_permfault,

            "ESME_RX_T_APPN": self.transport.mess_tempfault,

            "ESME_RX_P_APPN": self.transport.mess_permfault,
            "ESME_RX_R_APPN": self.transport.mess_permfault,
            "ESME_RQUERYFAIL": self.transport.mess_permfault,
            "ESME_RINVOPTPARSTREAM": self.transport.mess_permfault,
            "ESME_ROPTPARNOTALLWD": self.transport.mess_permfault,
            "ESME_RINVPARLEN": self.transport.mess_permfault,
            "ESME_RMISSINGOPTPARAM": self.transport.mess_permfault,
            "ESME_RINVOPTPARAMVAL": self.transport.mess_permfault,

            "ESME_RDELIVERYFAILURE": self.transport.mess_tempfault,
            "ESME_RUNKNOWNERR": self.transport.mess_tempfault,
        }

        # Also have unknown error codes
        newfangled_fake_error = {
            "ESME_NEWFNGLEDFAKERR": self.esme.dummy_unknown,
        }

        for code, method in bind_dispatch_methods.items():
            response = BindTransceiverResp(1, code)
            # check the dispatcher returns the correct transport method
            self.assertEquals(method,
                    self.esme.command_status_dispatch(response.get_obj()))

        for code, method in submit_dispatch_methods.items():
            response = SubmitSMResp(1, "2", code)
            # check the dispatcher returns the correct transport method
            self.assertEquals(method,
                    self.esme.command_status_dispatch(response.get_obj()))

        for code, method in newfangled_fake_error.items():
            response = SubmitSMResp(1, "2", code)
            # check the dispatcher returns the correct transport method
            self.assertEquals(method,
                    self.esme.command_status_dispatch(response.get_obj()))
Пример #8
0
    def test_match_resp(self):
        message1 = Message(
            message_id=444,
            message="hello world",
            to_addr="1111111111")
        sequence_num1 = self.esme.getSeq()
        response1 = SubmitSMResp(sequence_num1, "3rd_party_id_1")
        self.transport.consume_message(message1)

        message2 = Message(
            message_id=445,
            message="hello world",
            to_addr="1111111111")
        sequence_num2 = self.esme.getSeq()
        response2 = SubmitSMResp(sequence_num2, "3rd_party_id_2")
        self.transport.consume_message(message2)

        # respond out of order - just to keep things interesting
        self.esme.handleData(response2.get_bin())
        self.esme.handleData(response1.get_bin())

        self.assertTrue(payload_equal_except_timestamp(
            self.transport.publisher.queue[0][0].payload,
            {
                'transport_message_id': '3rd_party_id_2',
                'message_version': '20110907',
                'message': '',
                'transport_metadata': {},
                'message_type': 'sms_ack',
                'message_id': '445',
                'transport': 'redis_testing_transport',
                'metadata': {}
                }
            ))

        self.assertTrue(payload_equal_except_timestamp(
            self.transport.publisher.queue[1][0].payload,
            {
                'transport_message_id': '3rd_party_id_1',
                'message_version': '20110907',
                'message': '',
                'transport_metadata': {},
                'message_type': 'sms_ack',
                'message_id': '444',
                'transport': 'redis_testing_transport',
                'metadata': {}
                }
            ))

        message3 = Message(
            message_id=446,
            message="hello world",
            to_addr="1111111111")
        sequence_num3 = self.esme.getSeq()
        response3 = SubmitSMResp(sequence_num3, "3rd_party_id_3",
                command_status="ESME_RSUBMITFAIL")
        self.transport.consume_message(message3)
        self.esme.handleData(response3.get_bin())
        self.assertTrue(payload_equal_except_timestamp(
            self.transport.publisher.queue[2][0].payload,
            {
                'transport_message_id': '3rd_party_id_3',
                'message_version': '20110907',
                'message': '',
                'transport_metadata': {},
                'message_type': 'sms_ack',
                'message_id': '446',
                'transport': 'redis_testing_transport',
                'metadata': {}
                }
            ))
        self.assertEquals(self.transport.failure_publisher.queue.pop()[0],
                Message(message={'id': '446'}, reason='ESME_RSUBMITFAIL'))

        message4 = Message(
            message_id=447,
            message="hello world",
            to_addr="1111111111")
        sequence_num4 = self.esme.getSeq()
        response4 = SubmitSMResp(sequence_num4, "3rd_party_id_4",
                command_status="ESME_RTHROTTLED")
        self.transport.consume_message(message4)
        self.esme.handleData(response4.get_bin())
        self.assertTrue(payload_equal_except_timestamp(
            self.transport.publisher.queue[3][0].payload,
            {
                'transport_message_id': '3rd_party_id_4',
                'message_version': '20110907',
                'message': '',
                'transport_metadata': {},
                'message_type': 'sms_ack',
                'message_id': '447',
                'transport': 'redis_testing_transport',
                'metadata': {}
                }
            ))
        self.assertTrue(self.transport.throttle_invoked_via_pdu)

        self.transport.send_failure(
                Message(
                    id=555,
                    message="hello world",
                    to_msisdn="1111111111"),
                "testing")
        self.assertEquals(self.transport.failure_publisher.queue.pop()[0],
                Message(message={"id": 555,
                    "message": "hello world",
                    "to_msisdn": "1111111111"},
                    reason="testing"))

        # Some error codes would occur on bind attempts
        bind_dispatch_methods = {
            "ESME_ROK"              : self.transport.ok,
            "ESME_RINVBNDSTS"       : self.transport.conn_tempfault,
            "ESME_RALYBND"          : self.transport.conn_tempfault,

            "ESME_RSYSERR"          : self.transport.conn_permfault,

            "ESME_RBINDFAIL"        : self.transport.conn_permfault,
            "ESME_RINVPASWD"        : self.transport.conn_permfault,
            "ESME_RINVSYSID"        : self.transport.conn_permfault,

            "ESME_RINVSERTYP"       : self.transport.conn_permfault,

        }

        # Some error codes would occur post bind i.e. on submission attempts
        submit_dispatch_methods = {
            "ESME_RINVMSGLEN"       : self.transport.mess_permfault,
            "ESME_RINVCMDLEN"       : self.transport.mess_permfault,
            "ESME_RINVCMDID"        : self.transport.mess_permfault,

            "ESME_RINVPRTFLG"       : self.transport.mess_permfault,
            "ESME_RINVREGDLVFLG"    : self.transport.mess_permfault,

            "ESME_RINVSRCADR"       : self.transport.mess_permfault,
            "ESME_RINVDSTADR"       : self.transport.mess_permfault,
            "ESME_RINVMSGID"        : self.transport.mess_permfault,

            "ESME_RCANCELFAIL"      : self.transport.mess_permfault,
            "ESME_RREPLACEFAIL"     : self.transport.mess_permfault,

            "ESME_RMSGQFUL"         : self.transport.conn_throttle,

            "ESME_RINVNUMDESTS"     : self.transport.mess_permfault,
            "ESME_RINVDLNAME"       : self.transport.mess_permfault,
            "ESME_RINVDESTFLAG"     : self.transport.mess_permfault,
            "ESME_RINVSUBREP"       : self.transport.mess_permfault,
            "ESME_RINVESMCLASS"     : self.transport.mess_permfault,
            "ESME_RCNTSUBDL"        : self.transport.mess_permfault,

            "ESME_RSUBMITFAIL"      : self.transport.mess_tempfault,

            "ESME_RINVSRCTON"       : self.transport.mess_permfault,
            "ESME_RINVSRCNPI"       : self.transport.mess_permfault,
            "ESME_RINVDSTTON"       : self.transport.mess_permfault,
            "ESME_RINVDSTNPI"       : self.transport.mess_permfault,
            "ESME_RINVSYSTYP"       : self.transport.conn_permfault,
            "ESME_RINVREPFLAG"      : self.transport.mess_permfault,

            "ESME_RINVNUMMSGS"      : self.transport.mess_tempfault,

            "ESME_RTHROTTLED"       : self.transport.conn_throttle,

            "ESME_RINVSCHED"        : self.transport.mess_permfault,
            "ESME_RINVEXPIRY"       : self.transport.mess_permfault,
            "ESME_RINVDFTMSGID"     : self.transport.mess_permfault,

            "ESME_RX_T_APPN"        : self.transport.mess_tempfault,

            "ESME_RX_P_APPN"        : self.transport.mess_permfault,
            "ESME_RX_R_APPN"        : self.transport.mess_permfault,
            "ESME_RQUERYFAIL"       : self.transport.mess_permfault,
            "ESME_RINVOPTPARSTREAM" : self.transport.mess_permfault,
            "ESME_ROPTPARNOTALLWD"  : self.transport.mess_permfault,
            "ESME_RINVPARLEN"       : self.transport.mess_permfault,
            "ESME_RMISSINGOPTPARAM" : self.transport.mess_permfault,
            "ESME_RINVOPTPARAMVAL"  : self.transport.mess_permfault,

            "ESME_RDELIVERYFAILURE" : self.transport.mess_tempfault,
            "ESME_RUNKNOWNERR"      : self.transport.mess_tempfault,
        }

        for code, method in bind_dispatch_methods.items():
            #print code, method
            response = BindTransceiverResp(1, code)
            # check the dispatcher returns the correct transport method
            self.assertEquals(method,
                    self.esme.command_status_dispatch(response.get_obj()))

        for code, method in submit_dispatch_methods.items():
            #print code, method
            response = SubmitSMResp(1, "2", code)
            # check the dispatcher returns the correct transport method
            self.assertEquals(method,
                    self.esme.command_status_dispatch(response.get_obj()))