コード例 #1
0
    def test_delivery_HttpConnector_message_payload_when_short_message_empty(
            self):
        """Related to #470
        Consider 'message_payload' when 'short_message' is empty"""
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a deliver_sm from the SMSC
        assert_content = b'Some content'
        pdu = DeliverSM(source_addr='1234',
                        destination_addr='4567',
                        short_message='',
                        message_payload=assert_content)
        yield self.triggerDeliverSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEqual(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_POST.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq[b'content'], [assert_content])
        self.assertEqual(receivedHttpReq[b'binary'],
                         [binascii.hexlify(assert_content)])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
コード例 #2
0
ファイル: test_pdu_encoding.py プロジェクト: devtud/smpp.pdu
 def test_DeliverSM_with_subaddress(self):
     pdu = DeliverSM(
         1,
         service_type='BM8',
         source_addr_ton=AddrTon.INTERNATIONAL,
         source_addr_npi=AddrNpi.ISDN,
         source_addr='46123456789',
         dest_addr_ton=AddrTon.INTERNATIONAL,
         dest_addr_npi=AddrNpi.ISDN,
         destination_addr='14046653410',
         esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT),
         protocol_id=0,
         priority_flag=PriorityFlag.LEVEL_0,
         registered_delivery=RegisteredDelivery(
             RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED),
         replace_if_present_flag=ReplaceIfPresentFlag.DO_NOT_REPLACE,
         data_coding=DataCoding(
             DataCodingScheme.GSM_MESSAGE_CLASS,
             DataCodingGsmMsg(DataCodingGsmMsgCoding.DEFAULT_ALPHABET,
                              DataCodingGsmMsgClass.CLASS_2)),
         short_message=b"Hello I'm a bigg fan of you",
         source_subaddress=Subaddress(SubaddressTypeTag.USER_SPECIFIED,
                                      b'742'),
         dest_subaddress=Subaddress(SubaddressTypeTag.USER_SPECIFIED,
                                    b'4131'),
     )
     self.do_conversion_test(
         PDUEncoder(), pdu,
         b'00000066000000050000000000000001424d38000101343631323334353637383900010131343034363635333431300000000000000000f2001b48656c6c6f2049276d206120626967672066616e206f6620796f7502020004a037343202030005a034313331'
     )
コード例 #3
0
    def test_delivery_HttpConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a deliver_sm from the SMSC
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='any content',
        )
        yield self.triggerDeliverSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEqual(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_POST.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq[b'from'], [pdu.params['source_addr']])
        self.assertEqual(receivedHttpReq[b'to'],
                         [pdu.params['destination_addr']])
        self.assertEqual(receivedHttpReq[b'content'],
                         [pdu.params['short_message']])
        self.assertEqual(receivedHttpReq[b'binary'],
                         [binascii.hexlify(pdu.params['short_message'])])
        self.assertEqual(receivedHttpReq[b'origin-connector'],
                         [source_connector.cid.encode()])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
コード例 #4
0
ファイル: test_pdu_encoding.py プロジェクト: devtud/smpp.pdu
 def test_DeliverSM_handset_ack_conversion(self):
     pdu = DeliverSM(
         10,
         service_type='CMT',
         source_addr_ton=AddrTon.INTERNATIONAL,
         source_addr_npi=AddrNpi.UNKNOWN,
         source_addr='6515555678',
         dest_addr_ton=AddrTon.INTERNATIONAL,
         dest_addr_npi=AddrNpi.UNKNOWN,
         destination_addr='123',
         esm_class=EsmClass(EsmClassMode.DEFAULT,
                            EsmClassType.SMSC_DELIVERY_RECEIPT),
         protocol_id=0,
         priority_flag=PriorityFlag.LEVEL_0,
         registered_delivery=RegisteredDelivery(
             RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED),
         replace_if_present_flag=ReplaceIfPresentFlag.DO_NOT_REPLACE,
         data_coding=DataCoding(
             scheme_data=DataCodingDefault.SMSC_DEFAULT_ALPHABET),
         short_message=
         b'id:1891273321 sub:001 dlvrd:001 submit date:1305050826 done date:1305050826 stat:DELIVRD err:000 Text:DLVRD TO MOBILE\x00',
         message_state=MessageState.DELIVERED,
         receipted_message_id='70BA8A69',
     )
     self.do_conversion_test(
         PDUEncoder(), pdu,
         b'000000b900000005000000000000000a434d5400010036353135353535363738000100313233000400000000000000007669643a31383931323733333231207375623a30303120646c7672643a303031207375626d697420646174653a3133303530353038323620646f6e6520646174653a3133303530353038323620737461743a44454c49565244206572723a30303020546578743a444c56524420544f204d4f42494c45000427000102001e0009373042413841363900'
     )
コード例 #5
0
ファイル: test_pdu_encoding.py プロジェクト: devtud/smpp.pdu
 def test_DeliverSM_sybase_MO_conversion(self):
     pdu = DeliverSM(
         1,
         service_type='CMT',
         source_addr_ton=AddrTon.INTERNATIONAL,
         source_addr_npi=AddrNpi.UNKNOWN,
         source_addr='3411149500001',
         dest_addr_ton=AddrTon.INTERNATIONAL,
         dest_addr_npi=AddrNpi.UNKNOWN,
         destination_addr='12345455',
         esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT),
         protocol_id=0,
         priority_flag=PriorityFlag.LEVEL_0,
         registered_delivery=RegisteredDelivery(
             RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED),
         replace_if_present_flag=ReplaceIfPresentFlag.DO_NOT_REPLACE,
         data_coding=DataCoding(
             DataCodingScheme.GSM_MESSAGE_CLASS,
             DataCodingGsmMsg(DataCodingGsmMsgCoding.DEFAULT_ALPHABET,
                              DataCodingGsmMsgClass.CLASS_2)),
         short_message=b'HELLO\x00',
     )
     self.do_conversion_test(
         PDUEncoder(), pdu,
         b'0000003f000000050000000000000001434d540001003334313131343935303030303100010031323334353435350000000000000000f2000648454c4c4f00'
     )
コード例 #6
0
    def setUp(self):
        yield SMPPClientTestCases.setUp(self)

        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        deliverSmThrowerConfigInstance = deliverSmThrowerConfig()
        # Lower the timeout config to pass the timeout tests quickly
        deliverSmThrowerConfigInstance.timeout = 2
        deliverSmThrowerConfigInstance.retry_delay = 1
        deliverSmThrowerConfigInstance.max_retries = 2

        # Launch the deliverSmThrower
        self.deliverSmThrower = deliverSmThrower(
            deliverSmThrowerConfigInstance)

        # Add the broker to the deliverSmThrower
        yield self.deliverSmThrower.addAmqpBroker(self.amqpBroker)

        # Add SMPPs factory to DLRThrower
        self.deliverSmThrower.addSmpps(self.smpps_factory)

        # Test vars:
        self.testDeliverSMPdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='hello !',
        )
コード例 #7
0
ファイル: test_smpp_server.py プロジェクト: zidru/jasmin
    def setUp(self):
        SMPPServerTestCases.setUp(self)

        self.SubmitSmPDU = SubmitSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='hello !',
            seqNum=1,
        )
        self.DeliverSmPDU = DeliverSM(
            source_addr='4567',
            destination_addr='1234',
            short_message='hello !',
            seqNum=1,
        )
        self.DataSmPDU = DataSM(
            source_addr='4567',
            destination_addr='1234',
            short_message='hello !',
            seqNum=1,
        )

        # SMPPClientConfig init
        args = {
            'id': 'smppc_01',
            'port': self.smpps_config.port,
            'log_level': logging.DEBUG,
            'reconnectOnConnectionLoss': False,
            'username': '******',
            'password': '******'
        }
        self.smppc_config = SMPPClientConfig(**args)

        # SMPPClientFactory init
        self.smppc_factory = LastProtoSMPPClientFactory(self.smppc_config)
コード例 #8
0
 def connectionMade(self):
     pdu = DeliverSM(
         source_addr='1234',
         destination_addr='4567',
         short_message='test',
     )
     self.sendPDU(pdu)
コード例 #9
0
    def test_delivery_failover_route(self):
        """#467: Will ensure a failover route will deliver the message"""

        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        wrong_port = self.AckServer.getHost().port + 1000
        route = FailoverMORoute([TransparentFilter()], [
            HttpConnector(id_generator(),
                          'http://127.0.0.1:%s/send' % wrong_port, 'POST'),
            HttpConnector(
                id_generator(), 'http://127.0.0.1:%s/send' %
                self.AckServer.getHost().port, 'POST')
        ])
        yield self.prepareRoutingsAndStartConnector(source_connector, route)

        # Send a deliver_sm from the SMSC
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='any content',
        )
        yield self.triggerDeliverSmFromSMSC([pdu])

        # Run tests
        # Test callback in router
        self.assertEqual(self.pbRoot_f.deliver_sm_callback.call_count, 1)
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_POST.call_count, 1)

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
コード例 #10
0
    def setUp(self):
        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        AMQPServiceConfigInstance = AmqpConfig()
        AMQPServiceConfigInstance.reconnectOnConnectionLoss = False

        self.amqpBroker = AmqpFactory(AMQPServiceConfigInstance)
        yield self.amqpBroker.connect()
        yield self.amqpBroker.getChannelReadyDeferred()

        # Initiating config objects without any filename
        # will lead to setting defaults and that's what we
        # need to run the tests
        deliverSmThrowerConfigInstance = deliverSmThrowerConfig()
        # Lower the timeout config to pass the timeout tests quickly
        deliverSmThrowerConfigInstance.timeout = 2
        deliverSmThrowerConfigInstance.retry_delay = 1
        deliverSmThrowerConfigInstance.max_retries = 2

        # Launch the deliverSmThrower
        self.deliverSmThrower = deliverSmThrower(
            deliverSmThrowerConfigInstance)

        # Add the broker to the deliverSmThrower
        yield self.deliverSmThrower.addAmqpBroker(self.amqpBroker)

        # Test vars:
        self.testDeliverSMPdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='hello !',
        )
コード例 #11
0
 def test_data_handler_return_none(self):
     smpp = self.getProtocolObject()
     smpp.sendPDU = Mock()
     reqPDU = DeliverSM(5)
     smpp.PDURequestSucceeded(None, reqPDU)
     self.assertEquals(1, smpp.sendPDU.call_count)
     sent = smpp.sendPDU.call_args[0][0]
     self.assertEquals(DeliverSMResp(5), sent)
コード例 #12
0
 def test_data_handler_return_status(self):
     smpp = self.getProtocolObject()
     smpp.sendPDU = Mock()
     reqPDU = DeliverSM(5)
     smpp.PDURequestSucceeded(CommandStatus.ESME_RINVSRCTON, reqPDU)
     self.assertEquals(1, smpp.sendPDU.call_count)
     sent = smpp.sendPDU.call_args[0][0]
     self.assertEquals(DeliverSMResp(5, CommandStatus.ESME_RINVSRCTON),
                       sent)
コード例 #13
0
    def test_graceful_unbind(self):
        smpp = self.getProtocolObject()
        smpp.sendPDU = Mock()
        smpp.sessionState = SMPPSessionStates.BOUND_TRX

        #setup outbound txn
        outPdu = SubmitSM(
            seqNum=98790,
            source_addr='mobileway',
            destination_addr='1208230',
            short_message='HELLO1',
        )
        outRespPdu = outPdu.requireAck(seqNum=outPdu.seqNum)
        outDeferred = smpp.startOutboundTransaction(outPdu, 1)
        #setup inbound txn
        inPdu = DeliverSM(
            seqNum=764765,
            source_addr='mobileway',
            destination_addr='1208230',
            short_message='HELLO1',
        )
        inDeferred = smpp.startInboundTransaction(inPdu)

        #Call unbind
        unbindDeferred = smpp.unbind()

        #Assert unbind request not sent and deferred not fired
        self.assertEquals(0, smpp.sendPDU.call_count)
        self.assertFalse(unbindDeferred.called)

        #Simulate inbound txn finishing
        smpp.endInboundTransaction(inPdu)

        #Assert unbind request not sent and deferred not fired
        self.assertEquals(0, smpp.sendPDU.call_count)
        self.assertFalse(unbindDeferred.called)

        #Simulate outbound txn finishing
        smpp.endOutboundTransaction(outRespPdu)

        #Assert unbind request was sent but deferred not yet fired
        self.assertEquals(1, smpp.sendPDU.call_count)
        sentPdu = smpp.sendPDU.call_args[0][0]
        self.assertTrue(isinstance(sentPdu, Unbind))
        self.assertFalse(unbindDeferred.called)

        bindResp = UnbindResp(seqNum=sentPdu.seqNum)

        #Simulate unbind_resp
        smpp.endOutboundTransaction(bindResp)

        #Assert unbind deferred fired
        self.assertTrue(unbindDeferred.called)
        self.assertTrue(
            isinstance(unbindDeferred.result, SMPPOutboundTxnResult))
        expectedResult = SMPPOutboundTxnResult(smpp, sentPdu, bindResp)
        self.assertEquals(expectedResult, unbindDeferred.result)
コード例 #14
0
    def sendDeliverSM(self, reqPDU):
        self.sendSuccessResponse(reqPDU)

        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='test',
        )
        self.sendPDU(pdu)
コード例 #15
0
ファイル: test_router_smpps.py プロジェクト: zidru/jasmin
    def setUp(self, interceptorpb_client=None):
        yield HappySMSCTestCase.setUp(self)

        self.encoder = pdu_encoding.PDUEncoder()

        # SMPPServerConfig init
        self.smpps_config = SMPPServerConfig()

        # Portal init
        _portal = portal.Portal(SmppsRealm(self.smpps_config.id,
                                           self.pbRoot_f))
        _portal.registerChecker(RouterAuthChecker(self.pbRoot_f))

        # Install mocks
        self.clientManager_f.perspective_submit_sm = Mock(
            wraps=self.clientManager_f.perspective_submit_sm)

        # SMPPServerFactory init
        self.smpps_factory = LastProtoSMPPServerFactory(
            self.smpps_config,
            auth_portal=_portal,
            RouterPB=self.pbRoot_f,
            SMPPClientManagerPB=self.clientManager_f,
            interceptorpb_client=interceptorpb_client)
        self.smpps_port = reactor.listenTCP(self.smpps_config.port,
                                            self.smpps_factory)

        # Init protocol for testing
        self.smpps_proto = self.smpps_factory.buildProtocol(('127.0.0.1', 0))
        self.smpps_tr = proto_helpers.StringTransport()
        self.smpps_proto.makeConnection(self.smpps_tr)

        # Add SMPPs factory to DLRThrower
        self.DLRThrower.addSmpps(self.smpps_factory)

        # Install mocks
        self.smpps_proto.sendPDU = Mock(wraps=self.smpps_proto.sendPDU)

        # PDUs used for tests
        self.SubmitSmPDU = SubmitSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='hello !',
            seqNum=1,
        )
        self.DeliverSmPDU = DeliverSM(
            source_addr='4567',
            destination_addr='1234',
            short_message='any content',
            seqNum=1,
        )
        self.DataSmPDU = DataSM(
            source_addr='4567',
            destination_addr='1234',
            message_payload='any content',
            seqNum=1,
        )
コード例 #16
0
 def test_data_handler_return_junk(self):
     smpp = self.getProtocolObject()
     smpp.sendPDU = Mock()
     smpp.shutdown = Mock()
     reqPDU = DeliverSM(5)
     smpp.PDURequestSucceeded(3, reqPDU)
     self.assertEquals(1, smpp.shutdown.call_count)
     self.assertEquals(1, smpp.sendPDU.call_count)
     sent = smpp.sendPDU.call_args[0][0]
     self.assertEquals(DeliverSMResp(5, CommandStatus.ESME_RX_T_APPN), sent)
コード例 #17
0
    def test_unordered_long_content_delivery_HttpConnector(self):
        yield self.connect('127.0.0.1', self.pbPort)
        # Connect to SMSC
        source_connector = Connector(id_generator())
        yield self.prepareRoutingsAndStartConnector(source_connector)

        # Send a deliver_sm from the SMSC
        basePdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message='',
            sar_total_segments=3,
            sar_msg_ref_num=int(id_generator(size=2, chars=string.digits)),
        )
        pdu_part1 = copy.deepcopy(basePdu)
        pdu_part2 = copy.deepcopy(basePdu)
        pdu_part3 = copy.deepcopy(basePdu)
        pdu_part1.params[
            'short_message'] = b'__1st_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part1.params['sar_segment_seqnum'] = 1
        pdu_part2.params[
            'short_message'] = b'__2nd_part_with_153_char________________________________________________________________________________________________________________________________.'
        pdu_part2.params['sar_segment_seqnum'] = 2
        pdu_part3.params['short_message'] = b'__3rd_part_end.'
        pdu_part3.params['sar_segment_seqnum'] = 3
        yield self.triggerDeliverSmFromSMSC([pdu_part2, pdu_part1, pdu_part3])

        # Run tests
        # Destination connector must receive the message one time (no retries)
        self.assertEqual(self.AckServerResource.render_POST.call_count, 1)
        # Assert received args
        receivedHttpReq = self.AckServerResource.last_request.args
        self.assertEqual(len(receivedHttpReq), 8)
        self.assertEqual(receivedHttpReq[b'from'],
                         [basePdu.params['source_addr']])
        self.assertEqual(receivedHttpReq[b'to'],
                         [basePdu.params['destination_addr']])
        self.assertEqual(receivedHttpReq[b'content'], [
            pdu_part1.params['short_message'] +
            pdu_part2.params['short_message'] +
            pdu_part3.params['short_message']
        ])
        self.assertEqual(receivedHttpReq[b'binary'], [
            binascii.hexlify(pdu_part1.params['short_message'] +
                             pdu_part2.params['short_message'] +
                             pdu_part3.params['short_message'])
        ])
        self.assertEqual(receivedHttpReq[b'origin-connector'],
                         [source_connector.cid.encode()])

        # Disconnector from SMSC
        yield self.stopConnector(source_connector)
コード例 #18
0
ファイル: test_Interceptors.py プロジェクト: zidru/jasmin
    def setUp(self):
        InterceptorTestCase.setUp(self)

        self.PDU_dst_1 = DeliverSM(
            source_addr='20203060',
            destination_addr='1',
            short_message='hello world',
        )

        self.routable_connector1 = RoutableDeliverSm(self.PDU_dst_1,
                                                     self.connector1)
        self.routable_connector2 = RoutableDeliverSm(self.PDU_dst_1,
                                                     self.connector2)
コード例 #19
0
    def setUp(self):
        self.connector = SmppServerSystemIdConnector('jkl')
        self.script1 = MOInterceptorScript('abc')
        self.script2 = MOInterceptorScript('def')
        self.script3 = MOInterceptorScript('ghi')
        self.script4 = MOInterceptorScript('jkl')

        self.mt_filter1 = [SourceAddrFilter('^10\d+')]
        self.mt_filter2 = [DestinationAddrFilter('^90\d+')]
        self.transparent_filter = [TransparentFilter()]
        self.interceptor1 = StaticMOInterceptor(self.mt_filter1, self.script1)
        self.interceptor2 = StaticMOInterceptor(self.mt_filter2, self.script2)
        self.interceptor3 = StaticMOInterceptor(self.transparent_filter,
                                                self.script3)
        self.interceptor4 = DefaultInterceptor(self.script4)

        self.PDU_dst_1 = DeliverSM(
            source_addr=b'100',
            destination_addr=b'200',
            short_message=b'hello world',
        )
        self.PDU_dst_2 = DeliverSM(
            source_addr=b'x',
            destination_addr=b'900',
            short_message=b'hello world',
        )
        self.PDU_dst_3 = DeliverSM(
            source_addr=b'x',
            destination_addr=b'y',
            short_message=b'hello world',
        )

        self.routable_matching_interceptor1 = RoutableDeliverSm(
            self.PDU_dst_1, self.connector)
        self.routable_matching_interceptor2 = RoutableDeliverSm(
            self.PDU_dst_2, self.connector)
        self.routable_notmatching_any = RoutableDeliverSm(
            self.PDU_dst_3, self.connector)
コード例 #20
0
ファイル: smsc_simulator.py プロジェクト: zidru/jasmin
    def sendDeliverSM(self, reqPDU):
        self.sendSuccessResponse(reqPDU)

        message_id = '1891273321'
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message=
            'id:%s sub:001 dlvrd:001 submit date:1305050826 done date:1305050826 stat:DELIVRD err:000 text:DLVRD TO MOBILE'
            % message_id,
            message_state=MessageState.DELIVERED,
            receipted_message_id=message_id,
        )
        self.sendPDU(pdu)
コード例 #21
0
    def setUp(self):
        self.connector1 = HttpConnector('abc', 'http://127.0.0.1')
        self.connector2 = HttpConnector('def', 'http://127.0.0.1')
        self.connector3 = HttpConnector('ghi', 'http://127.0.0.1')
        self.connector4 = SmppServerSystemIdConnector('jkl')

        self.mt_filter1 = [SourceAddrFilter('^10\d+')]
        self.mt_filter2 = [DestinationAddrFilter('^90\d+')]
        self.transparent_filter = [TransparentFilter()]
        self.route1 = StaticMORoute(self.mt_filter1, self.connector1)
        self.route2 = StaticMORoute(self.mt_filter2, self.connector2)
        self.route3 = StaticMORoute(self.transparent_filter, self.connector3)
        self.route4 = DefaultRoute(self.connector4)

        self.PDU_dst_1 = DeliverSM(
            source_addr=b'100',
            destination_addr=b'200',
            short_message=b'hello world',
        )
        self.PDU_dst_2 = DeliverSM(
            source_addr=b'x',
            destination_addr=b'900',
            short_message=b'hello world',
        )
        self.PDU_dst_3 = DeliverSM(
            source_addr=b'x',
            destination_addr=b'y',
            short_message=b'hello world',
        )

        self.routable_matching_route1 = RoutableDeliverSm(
            self.PDU_dst_1, self.connector1)
        self.routable_matching_route2 = RoutableDeliverSm(
            self.PDU_dst_2, self.connector1)
        self.routable_notmatching_any = RoutableDeliverSm(
            self.PDU_dst_3, self.connector1)
コード例 #22
0
ファイル: test_operations.py プロジェクト: zidru/jasmin
    def test_is_delivery_empty_text(self):
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message=
            'id:1891273321 sub:001 dlvrd:001 submit date:1305050826 done date:1305050826 stat:DELIVRD err:000 text:',
        )

        isDlr = self.opFactory.isDeliveryReceipt(pdu)
        self.assertTrue(isDlr is not None)
        self.assertEqual(isDlr['id'], '1891273321')
        self.assertEqual(isDlr['sub'], '001')
        self.assertEqual(isDlr['dlvrd'], '001')
        self.assertEqual(isDlr['sdate'], '1305050826')
        self.assertEqual(isDlr['ddate'], '1305050826')
        self.assertEqual(isDlr['stat'], 'DELIVRD')
        self.assertEqual(isDlr['err'], '000')
        self.assertEqual(isDlr['text'], '')
コード例 #23
0
ファイル: smsc_simulator.py プロジェクト: zidru/jasmin
    def trigger_DLR(self, _id=None, pdu_type='deliver_sm', stat='DELIVRD'):
        if self.lastSubmitSmRestPDU is None:
            raise Exception(
                'A submit_sm must be sent to this SMSC before requesting sendDeliverSM !'
            )

        # Pick the last submit_sm
        submitsm_pdu = self.lastSubmitSmPDU

        # Pick the last submit_sm_resp
        submitsm_resp_pdu = self.lastSubmitSmRestPDU
        if _id is None:
            _id = submitsm_resp_pdu.params['message_id']

        if isinstance(_id, bytes):
            _id = _id.decode()
        if isinstance(pdu_type, bytes):
            pdu_type = pdu_type.decode()

        if pdu_type == 'deliver_sm':
            # Send back a deliver_sm with containing a DLR

            pdu = DeliverSM(
                source_addr=submitsm_pdu.params['source_addr'],
                destination_addr=submitsm_pdu.params['destination_addr'],
                short_message=
                'id:%s sub:001 dlvrd:001 submit date:1305050826 done date:1305050826 stat:%s err:000 text:%s'
                % (str(_id), stat, submitsm_pdu.params['short_message'][:20]),
                message_state=message_state_map[stat],
                receipted_message_id=str(_id),
            )
            return self.trigger_deliver_sm(pdu)
        elif pdu_type == 'data_sm':
            # Send back a data_sm with containing a DLR
            pdu = DataSM(
                source_addr=submitsm_pdu.params['source_addr'],
                destination_addr=submitsm_pdu.params['destination_addr'],
                message_state=message_state_map[stat],
                receipted_message_id=str(_id),
            )
            return self.trigger_data_sm(pdu)
        else:
            raise Exception(
                'Unknown pdu_type (%s) when calling trigger_DLR()' % pdu_type)
コード例 #24
0
ファイル: test_operations.py プロジェクト: zidru/jasmin
    def test_is_delivery_mmg_deliver_sm_224(self):
        """Related to #224, this is a Sicap's MMG deliver_sm receipt"""
        pdu = DeliverSM(
            source_addr='24206155423',
            destination_addr='JOOKIES',
            short_message='362d9701 2',
            message_state=MessageState.DELIVERED,
            receipted_message_id='362d9701',
        )

        isDlr = self.opFactory.isDeliveryReceipt(pdu)
        self.assertTrue(isDlr is not None)
        self.assertEqual(isDlr['id'], b'362d9701')
        self.assertEqual(isDlr['sub'], 'ND')
        self.assertEqual(isDlr['dlvrd'], 'ND')
        self.assertEqual(isDlr['sdate'], 'ND')
        self.assertEqual(isDlr['ddate'], 'ND')
        self.assertEqual(isDlr['stat'], 'DELIVRD')
        self.assertEqual(isDlr['err'], 'ND')
        self.assertEqual(isDlr['text'], '')
コード例 #25
0
ファイル: test_operations.py プロジェクト: zidru/jasmin
    def test_is_delivery_jasmin_195(self):
        """Related to #195
        Mandatory fields in short_message are parsed and optional fields are set to defaults when
        they dont exist in short_message"""
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message=
            'id:c87c2273-7edb-4bc7-8d3a-7f57f21b625e submit date:201506201641 done date:201506201641 stat:DELIVRD err:000',
        )

        isDlr = self.opFactory.isDeliveryReceipt(pdu)
        self.assertTrue(isDlr is not None)
        self.assertEqual(isDlr['id'], 'c87c2273-7edb-4bc7-8d3a-7f57f21b625e')
        self.assertEqual(isDlr['sub'], 'ND')
        self.assertEqual(isDlr['dlvrd'], 'ND')
        self.assertEqual(isDlr['sdate'], '201506201641')
        self.assertEqual(isDlr['ddate'], '201506201641')
        self.assertEqual(isDlr['stat'], 'DELIVRD')
        self.assertEqual(isDlr['err'], '000')
        self.assertEqual(isDlr['text'], '')
コード例 #26
0
ファイル: test_operations.py プロジェクト: zidru/jasmin
    def test_is_delivery_jasmin_153(self):
        """Related to #153
        Parsing jasmin's DLRs
        """
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message=
            'id:4a38dc46-5125-4969-90be-72104c340d5c sub:001 dlvrd:001 submit date:150519232657 done date:150519232657 stat:DELIVRD err:000 text:-',
        )

        isDlr = self.opFactory.isDeliveryReceipt(pdu)
        self.assertTrue(isDlr is not None)
        self.assertEqual(isDlr['id'], '4a38dc46-5125-4969-90be-72104c340d5c')
        self.assertEqual(isDlr['sub'], '001')
        self.assertEqual(isDlr['dlvrd'], '001')
        self.assertEqual(isDlr['sdate'], '150519232657')
        self.assertEqual(isDlr['ddate'], '150519232657')
        self.assertEqual(isDlr['stat'], 'DELIVRD')
        self.assertEqual(isDlr['err'], '000')
        self.assertEqual(isDlr['text'], '-')
コード例 #27
0
ファイル: test_operations.py プロジェクト: zidru/jasmin
    def test_is_delivery_clickatell_70(self):
        """Related to #70
        Parsing clickatell's DLRs
        """
        pdu = DeliverSM(
            source_addr='1234',
            destination_addr='4567',
            short_message=
            'id:a29f6845555647139e5c8f3b817f2c9a sub:001 dlvrd:001 submit date:141023215253 done date:141023215259 stat:DELIVRD err:000 text:HOLA',
        )

        isDlr = self.opFactory.isDeliveryReceipt(pdu)
        self.assertTrue(isDlr is not None)
        self.assertEqual(isDlr['id'], 'a29f6845555647139e5c8f3b817f2c9a')
        self.assertEqual(isDlr['sub'], '001')
        self.assertEqual(isDlr['dlvrd'], '001')
        self.assertEqual(isDlr['sdate'], '141023215253')
        self.assertEqual(isDlr['ddate'], '141023215259')
        self.assertEqual(isDlr['stat'], 'DELIVRD')
        self.assertEqual(isDlr['err'], '000')
        self.assertEqual(isDlr['text'], 'HOLA')
コード例 #28
0
ファイル: test_pdu_encoding.py プロジェクト: devtud/smpp.pdu
 def test_DeliverSM_syniverse_MO_conversion(self):
     pdu = DeliverSM(
         2676551972,
         service_type='AWSBD',
         source_addr_ton=AddrTon.INTERNATIONAL,
         source_addr_npi=AddrNpi.ISDN,
         source_addr='16505551234',
         dest_addr_ton=AddrTon.INTERNATIONAL,
         dest_addr_npi=AddrNpi.ISDN,
         destination_addr='17735554070',
         esm_class=EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT),
         protocol_id=0,
         priority_flag=PriorityFlag.LEVEL_0,
         registered_delivery=RegisteredDelivery(
             RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED),
         replace_if_present_flag=ReplaceIfPresentFlag.DO_NOT_REPLACE,
         data_coding=DataCoding(scheme_data=DataCodingDefault.LATIN_1),
         short_message=b'there is no spoon',
     )
     self.do_conversion_test(
         PDUEncoder(), pdu,
         b'0000004d00000005000000009f88f12441575342440001013136353035353531323334000101313737333535353430373000000000000000000300117468657265206973206e6f2073706f6f6e'
     )
コード例 #29
0
    async def send_deliver_sm(
            self,
            source_addr: str,
            destination_addr: str,
            text: str,
            source_addr_npi: AddrNpi,
            dest_addr_npi: AddrNpi,
            source_addr_ton: AddrTon,
            dest_addr_ton: AddrTon,
            priority_flag: PriorityFlag = PriorityFlag.LEVEL_0,
            registered_delivery: RegisteredDelivery = None):

        if registered_delivery is None:
            registered_delivery = RegisteredDelivery(
                RegisteredDeliveryReceipt.NO_SMSC_DELIVERY_RECEIPT_REQUESTED)

        def try_to_encode(text: str, codec: str) -> Optional[bytes]:
            try:
                return text.encode(codec)
            except UnicodeEncodeError:
                return None

        codec_data_coding_map = [('ascii',
                                  DataCodingDefault.SMSC_DEFAULT_ALPHABET),
                                 ('latin-1', DataCodingDefault.LATIN_1),
                                 ('cyrillic', DataCodingDefault.CYRILLIC),
                                 ('utf-16be', DataCodingDefault.UCS2)]

        short_message = None
        data_coding = None
        for pair in codec_data_coding_map:
            short_message = try_to_encode(text=text, codec=pair[0])
            if short_message:
                data_coding = pair[1]
                break

        if data_coding is None or short_message is None:
            raise Exception(f'Text {text} could not be encoded')

        deliver_sm_dict = {
            'sequence_number': self.next_sequence_number(),
            'service_type': None,
            'source_addr_ton': source_addr_ton,
            'source_addr_npi': source_addr_npi,
            'source_addr': source_addr,
            'dest_addr_ton': dest_addr_ton,
            'dest_addr_npi': dest_addr_npi,
            'destination_addr': destination_addr,
            'esm_class': EsmClass(EsmClassMode.DEFAULT, EsmClassType.DEFAULT),
            'protocol_id': None,
            'priority_flag': priority_flag,
            'registered_delivery': registered_delivery,
            'replace_if_present_flag': ReplaceIfPresentFlag.DO_NOT_REPLACE,
            'data_coding': DataCoding(scheme_data=data_coding),
            'short_message': short_message,
        }

        max_size = 100

        if len(short_message) <= max_size:
            deliver_sm = DeliverSM(**deliver_sm_dict)
            requests = [deliver_sm]
        else:
            requests = []

            short_messages = [
                short_message[x:x + max_size]
                for x in range(0, len(short_message), max_size)
            ]

            ref_num = self.next_ref_num()
            total_segments = len(short_messages)

            if total_segments > 255:
                raise Exception('Text is too long and it cannot be sent')

            for seq_num, trunk_short_message in enumerate(short_messages):
                deliver_sm_dict['short_message'] = trunk_short_message
                deliver_sm_dict['sequence_number'] = self.next_sequence_number(
                )
                deliver_sm = DeliverSM(**deliver_sm_dict,
                                       sar_msg_ref_num=ref_num,
                                       sar_total_segments=total_segments,
                                       sar_segment_seqnum=seq_num + 1)

                requests.append(deliver_sm)

        self._send_requests(requests=requests, merge=True)
コード例 #30
0
ファイル: operations.py プロジェクト: zidru/jasmin
    def getReceipt(self, dlr_pdu, msgid, source_addr, destination_addr,
                   message_status, err, sub_date, source_addr_ton,
                   source_addr_npi, dest_addr_ton, dest_addr_npi):
        """Will build a DataSm or a DeliverSm (depending on dlr_pdu) containing a receipt data"""

        if isinstance(message_status, bytes):
            message_status = message_status.decode()
        if isinstance(msgid, bytes):
            msgid = msgid.decode()
        sm_message_stat = message_status
        # Prepare message_state
        if message_status[:5] == 'ESME_':
            if message_status == 'ESME_ROK':
                message_state = MessageState.ACCEPTED
                sm_message_stat = 'ACCEPTD'
            else:
                message_state = MessageState.UNDELIVERABLE
                sm_message_stat = 'UNDELIV'
        elif message_status == 'UNDELIV':
            message_state = MessageState.UNDELIVERABLE
        elif message_status == 'REJECTD':
            message_state = MessageState.REJECTED
        elif message_status == 'DELIVRD':
            message_state = MessageState.DELIVERED
        elif message_status == 'EXPIRED':
            message_state = MessageState.EXPIRED
        elif message_status == 'DELETED':
            message_state = MessageState.DELETED
        elif message_status == 'ACCEPTD':
            message_state = MessageState.ACCEPTED
        elif message_status == 'ENROUTE':
            message_state = MessageState.ENROUTE
        elif message_status == 'UNKNOWN':
            message_state = MessageState.UNKNOWN
        else:
            raise UnknownMessageStatusError('Unknown message_status: %s' %
                                            message_status)

        # Build pdu
        if dlr_pdu == 'deliver_sm':
            short_message = r"id:%s submit date:%s done date:%s stat:%s err:%s" % (
                msgid,
                parser.parse(sub_date).strftime("%y%m%d%H%M"),
                datetime.datetime.now().strftime("%y%m%d%H%M"),
                sm_message_stat,
                err,
            )

            # Build DeliverSM pdu
            pdu = DeliverSM(
                source_addr=destination_addr,
                destination_addr=source_addr,
                esm_class=EsmClass(EsmClassMode.DEFAULT,
                                   EsmClassType.SMSC_DELIVERY_RECEIPT),
                receipted_message_id=msgid,
                short_message=short_message,
                message_state=message_state,
                source_addr_ton=self.get_enum(AddrTon, dest_addr_ton),
                source_addr_npi=self.get_enum(AddrNpi, dest_addr_npi),
                dest_addr_ton=self.get_enum(AddrTon, source_addr_ton),
                dest_addr_npi=self.get_enum(AddrNpi, source_addr_npi),
            )
        else:
            # Build DataSM pdu
            pdu = DataSM(
                source_addr=destination_addr,
                destination_addr=source_addr,
                esm_class=EsmClass(EsmClassMode.DEFAULT,
                                   EsmClassType.SMSC_DELIVERY_RECEIPT),
                receipted_message_id=msgid,
                message_state=message_state,
                source_addr_ton=self.get_enum(AddrTon, dest_addr_ton),
                source_addr_npi=self.get_enum(AddrNpi, dest_addr_npi),
                dest_addr_ton=self.get_enum(AddrTon, source_addr_ton),
                dest_addr_npi=self.get_enum(AddrNpi, source_addr_npi),
            )

        return pdu