Exemplo n.º 1
0
 def test_isConcatenatedSM_true(self):
     pduHex = '000000da0000000500000000da4b62474652414e4300010131353535313233343536370001013134303436363533343130004000000000000000009e0500032403016869206a757374696e20686f772061726520796f753f204d79206e616d6520697320706570652069276d206672656e636820616e6420692077616e74656420746f2074656c6c20796f7520686f77206d7563682069206c6f766520796f752c20796f75206b6e6f7720796f75207361766564206d79206c69666520616e642069207265616c6c79207468616e6b20796f7520666f72207468'
     pdu = self.getPDU(pduHex)
     self.assertTrue(SMStringEncoder().is_concatenated_SM(pdu))
     iElem = SMStringEncoder().get_concatenated_SM_info_element(pdu)
     self.assertEqual(
         InformationElement(InformationElementIdentifier.CONCATENATED_SM_8BIT_REF_NUM,
                            IEConcatenatedSM(0x24, 0x03, 0x01)), iElem)
Exemplo n.º 2
0
 def test_decode_latin1(self):
     pduHex = '0000004200000005000000002a603d56415753424400010131353535313233343536370001013137373338323834303730000000000000000003000645737061f161'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals('Espa\xf1a', smStr.bytes)
     self.assertEquals(u'Espa\xf1a', smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 3
0
 def test_decode_UCS2(self):
     pduHex = '000000480000000500000000dfd03a56415753424400010131353535313233343536370001013137373338323834303730000000000000000008000c00f10075014400ed00fc0073'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals('\x00\xf1\x00u\x01D\x00\xed\x00\xfc\x00s', smStr.bytes)
     self.assertEquals(u'\xf1u\u0144\xed\xfcs', smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 4
0
 def test_decode_default_alphabet_with_udh(self):
     pduHex = '000000da0000000500000000da4b62474652414e4300010131353535313233343536370001013134303436363533343130004000000000000000009e0500032403016869206a757374696e20686f772061726520796f753f204d79206e616d6520697320706570652069276d206672656e636820616e6420692077616e74656420746f2074656c6c20796f7520686f77206d7563682069206c6f766520796f752c20796f75206b6e6f7720796f75207361766564206d79206c69666520616e642069207265616c6c79207468616e6b20796f7520666f72207468'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals("\x05\x00\x03$\x03\x01hi justin how are you? My name is pepe i'm french and i wanted to tell you how much i love you, you know you saved my life and i really thank you for th", smStr.bytes)
     self.assertEquals("hi justin how are you? My name is pepe i'm french and i wanted to tell you how much i love you, you know you saved my life and i really thank you for th", smStr.unicode)
     self.assertEquals([InformationElement(InformationElementIdentifier.CONCATENATED_SM_8BIT_REF_NUM, IEConcatenatedSM(0x24, 0x03, 0x01))], smStr.udh)
Exemplo n.º 5
0
 def test_decode_ascii(self):
     pduHex = '00000054000000050000000008c72a4154454c4550000101313535353535353535353500010131343034363635333431300000ff010000000001000e49732074686973206a757374696e0201000100020d000101'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals('Is this justin', smStr.bytes)
     self.assertEquals('Is this justin', smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 6
0
 def test_message_payload_octet_unspecified_common(self):
     pduHex = '000000cc00000005000000000000000200010132333438303731303931303632000409353531310040000000000000040000000e00010100060001010424008c0900033202010402e400424547494e3a5643414c454e4441520d0a56455253494f4e3a312e300d0a424547494e3a564556454e540d0a43415445474f524945533a4d495343454c4c414e454f55530d0a53554d4d4152593a4e6f7220666f7267657420472d6265740d0a445453544152543a3230313331313235543036353030300d0a44414c41524d3a3230'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals(
         u'BEGIN:VCALENDAR\r\nVERSION:1.0\r\nBEGIN:VEVENT\r\nCATEGORIES:MISCELLANEOUS\r\nSUMMARY:Nor forget G-bet\r\nDTSTART:20131125T065000\r\nDALARM:20',
         smStr.unicode)
Exemplo n.º 7
0
 def test_delivery_receipt_faulty_encoding(self):
     pduHex = '000000d6000000050000000000000282574150000101313233343531323334353100010131323334000400000000000008006b69643a323830333830313533383739393135207375623a30303120646c7672643a303031207375626d697420646174653a3133313231313134353020646f6e6520646174653a3133313231313134353020737461743a52454a45435444206572723a30303020746578743a1401000d313331323131313435303239001402000d31333132313131343530333000001e000d464630313137373935443642000427000108'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals(
         u'id:280380153879915 sub:001 dlvrd:001 submit date:1312111450 done date:1312111450 stat:REJECTD err:000 text:',
         smStr.unicode)
Exemplo n.º 8
0
    def test_deliver_sm_unknown_param_network_error_code(self):
        pduHex = '000000e40000000500000000542e0f21312e303030000101323434393335353535300005005a4150000400000000000000008069643a3661336564393861363634343465386162616333616364396262613836353666207375623a30303120646c7672643a303030207375626d697420646174653a31343130313630303336353020646f6e6520646174653a31343130313630303338303020737461743a554e44454c4956206572723a30303020746578743a042300033030300427000105001e0021366133656439386136363434346538616261633361636439626261383635366600'
        pdu = self.getPDU(pduHex)
        SMStringEncoder().decodeSM(pdu)

        # Asserts
        self.assertEqual(b'000', pdu.params['network_error_code'])
Exemplo n.º 9
0
 def test_message_payload_ucs2_accents(self):
     pduHex = '000000440000000500000000000005c800010133353831323334353637383930000409353531310000000000000000080000000e00010100060001010424000400c100e1'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals('\x00\xc1\x00\xe1', smStr.bytes)
     self.assertEquals(u'\xc1\xe1', smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 10
0
 def test_message_payload_default_alphabet_cp437(self):
     pduHex = '0000003400000005000000000082b931000101333538313233343536373839300000013139363000000000000000000000028f86'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu, 'cp437')
     self.assertEquals('\x8f\x86', smStr.bytes)
     self.assertEquals(u'\xc5\xe5', smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 11
0
 def test_message_payload_default_alphabet_latin_1(self):
     pduHex = '000000440000000500000000000005c500010133353831323334353637383930000409353531310000000000000000000000000e00010100060001010424000422c5e522'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu, 'latin_1')
     self.assertEquals('"\xc5\xe5"', smStr.bytes)
     self.assertEquals(u'"\xc5\xe5"', smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 12
0
 def test_message_payload(self):
     pduHex = '000000440000000500000000000004e700010132333438303535353734373732000409353531310000000000000000000000000e00010100060001010424000454657374'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals('Test', smStr.bytes)
     self.assertEquals(u'Test', smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 13
0
    def test_any_network_error_code(self):
        """Related to #117"""

        pduHex = '000000f3000000050000000000000001000101343931353235363739343838370001013034303531333036393939000400000000000000008569643a62633539623861612d326664322d343033352d383131332d313933303165303530303739207375623a30303120646c7672643a303031207375626d697420646174653a31353035303831343430353820646f6e6520646174653a31353035303831343430353820737461743a44454c49565244206572723a30303020746578743a2d042300030300000427000102001e002562633539623861612d326664322d343033352d383131332d31393330316530353030373900'
        pdu = self.getPDU(pduHex)
        SMStringEncoder().decodeSM(pdu)

        # Asserts
        self.assertEqual(b'\x03\x00\x00', pdu.params['network_error_code'])
Exemplo n.º 14
0
    def test_deliver_sm_with_message_payload(self):
        pduHex = '0000009200000005000000000001693c00000032313635333532303730330000003737383800040000000001000000000424004f69643a30303030343336393439207375626d697420646174653a3135303432313135303820646f6e6520646174653a3135303432313135303820737461743a44454c49565244206572723a30303000001e00063661616435000427000102'
        pdu = self.getPDU(pduHex)
        SMStringEncoder().decodeSM(pdu)

        # Asserts
        self.assertEqual(b'id:0000436949 submit date:1504211508 done date:1504211508 stat:DELIVRD err:000\x00',
                          pdu.params['message_payload'])
        self.assertEqual(b'6aad5', pdu.params['receipted_message_id'])
Exemplo n.º 15
0
    def test_any_network_type(self):
        """Related to #120"""

        pduHex = '0000004500000005000000000000000100020135393232393631383600040933373435320000000000000000000000000e00010100060001010424000848692066696b7279'
        pdu = self.getPDU(pduHex)
        SMStringEncoder().decodeSM(pdu)

        # Asserts
        self.assertEqual(NetworkType.GSM, pdu.params['source_network_type'])
        self.assertEqual(NetworkType.GSM, pdu.params['dest_network_type'])
Exemplo n.º 16
0
 def test_message_payload_ucs2_accents2(self):
     pduHex = '000000a80000000500000000000005c000010133353831323334353637383930000409353531310000000000000000080000000e00010100060001010424006800c000e0002c002000df002c002000e4002c002000e5002c002000e6002c002000e3002c002000f1002c002000e7002c002000e2002c00200153002c00200153002c002000f2002c002000f6002c002000f5002c002000f8002c002000f3002c002000ef002c0020'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals(
         '\x00\xc0\x00\xe0\x00,\x00 \x00\xdf\x00,\x00 \x00\xe4\x00,\x00 \x00\xe5\x00,\x00 \x00\xe6\x00,\x00 \x00\xe3\x00,\x00 \x00\xf1\x00,\x00 \x00\xe7\x00,\x00 \x00\xe2\x00,\x00 \x01S\x00,\x00 \x01S\x00,\x00 \x00\xf2\x00,\x00 \x00\xf6\x00,\x00 \x00\xf5\x00,\x00 \x00\xf8\x00,\x00 \x00\xf3\x00,\x00 \x00\xef\x00,\x00 ',
         smStr.bytes)
     self.assertEquals(
         u"\xc0\xe0, \xdf, \xe4, \xe5, \xe6, \xe3, \xf1, \xe7, \xe2, \u0153, \u0153, \xf2, \xf6, \xf5, \xf8, \xf3, \xef, ",
         smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 17
0
    def test_deliver_sm_resp_unknown_error(self):
        """Raises a 'builtins.UnicodeDecodeError: 'ascii' codec can't decode byte 0x84 in position 102: ordinal not in range(128)'
        ref: #937
        """
        pduHex = '000000c600000005000000000000000a000201363930373137373035380005003532303030000400000000000000007a69643a30343136333432303734207375623a30303120646c7672643a303031207375626d697420646174653a3231303130343135323220646f6e6520646174653a3231303130343135323220737461743a44454c49565244206572723a30303020746578743a8441894f8820454e544f84482e208c4150414b41000e0001010006000101001e00093138643065303361000427000102'
        pdu = self.getPDU(pduHex)
        SMStringEncoder().decodeSM(pdu)

        # Asserts
        self.assertEqual(b'id:0416342074 sub:001 dlvrd:001 submit date:2101041522 done date:2101041522 stat:DELIVRD err:000 text:\x84A\x89O\x88 ENTO\x84H. \x8cAPAKA',
                          pdu.params['short_message'])
        self.assertEqual(b'18d0e03a', pdu.params['receipted_message_id'])
Exemplo n.º 18
0
 def test_decode_default_alphabet(self):
     #'T- Mobile flip phone \xa7 \xa8 N random special charcters'
     pduHex = '0000006f00000005000000005d3fe724544d4f4249000101313535353132333435363700010131373733383238343037300000000000000000000033542d204d6f62696c6520666c69702070686f6e6520a720a8204e2072616e646f6d207370656369616c20636861726374657273'
     pdu = self.getPDU(pduHex)
     smStr = SMStringEncoder().decodeSM(pdu, 'latin_1')
     self.assertEquals(
         'T- Mobile flip phone \xa7 \xa8 N random special charcters',
         smStr.bytes)
     self.assertEquals(
         u'T- Mobile flip phone \xa7 \xa8 N random special charcters',
         smStr.unicode)
     self.assertEquals(None, smStr.udh)
Exemplo n.º 19
0
    def test_deliver_sm_resp_opt_param_not_allow_more_messages_to_send(self):
        """Raises a 'Optional Parameter not allowed: Invalid option more_messages_to_send'
        ref: #938
        """
        pduHex = '000000cb00000005000000000000000b000201363930373137373035380005003532303030000400000000000000007a69643a30343136333432303734207375623a30303120646c7672643a303031207375626d697420646174653a3231303130343135323220646f6e6520646174653a3231303130343135323220737461743a44454c49565244206572723a30303020746578743a8441894f8820454e544f84482e208c4150414b41000e0001010006000101001e000931386430653033610004270001020426000101'
        pdu = self.getPDU(pduHex)
        SMStringEncoder().decodeSM(pdu)

        # Asserts
        self.assertEqual(b'id:0416342074 sub:001 dlvrd:001 submit date:2101041522 done date:2101041522 stat:DELIVRD err:000 text:\x84A\x89O\x88 ENTO\x84H. \x8cAPAKA',
                          pdu.params['short_message'])
        self.assertEqual(b'18d0e03a', pdu.params['receipted_message_id'])
Exemplo n.º 20
0
 def test_isConcatenatedSM_false(self):
     pduHex = '000000490000000500000000b9b7e456544d4f424900010131353535313233343536370001013134303436363533343130000000000000000000000d49206c7576206a757374696e21'
     pdu = self.getPDU(pduHex)
     self.assertFalse(SMStringEncoder().isConcatenatedSM(pdu))
     iElem = SMStringEncoder().getConcatenatedSMInfoElement(pdu)
     self.assertEquals(None, iElem)
Exemplo n.º 21
0
 def test_decode_octet_unspecified_common(self):
     pduHex = '000000a900000005000000003cf78935415753424400010131353535313233343536370001013134303436363533343130004000000000000004006d06050423f40000424547494e3a56434152440d0a56455253494f4e3a322e310d0a4e3b434841525345543d5554462d383a4269656265723b4a757374696e0d0a54454c3b564f4943453b434841525345543d5554462d383a343034363635333431300d0a454e443a5643415244'
     pdu = self.getPDU(pduHex)
     self.assertRaises(NotImplementedError, SMStringEncoder().decodeSM, pdu)
Exemplo n.º 22
0
 def test_decode_gsm(self):
     # GSM
     pduHex = '0000003e0000000500000000000000060001013232393634343734343930000001373030330000000000000000f1000e54524f55564552204e554d45524f'
     pdu = PDUEncoder().decode(StringIO.StringIO(binascii.a2b_hex(pduHex)))
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals(u'TROUVER NUMERO', smStr.unicode)
Exemplo n.º 23
0
 def test_decode_raw(self):
     # RAW
     pduHex = '0000003b0000000500000000000010f0000101323239393438343739353200000137303033000000000000000011000b2727616374697665722727'
     pdu = PDUEncoder().decode(StringIO.StringIO(binascii.a2b_hex(pduHex)))
     smStr = SMStringEncoder().decodeSM(pdu)
     self.assertEquals(u"''activer''", smStr.unicode)
Exemplo n.º 24
0
 def test_decode_default_alphabet(self):
     #'T- Mobile flip phone \xa7 \xa8 N random special charcters'
     pduHex = '0000006f00000005000000005d3fe724544d4f4249000101313535353132333435363700010131373733383238343037300000000000000000000033542d204d6f62696c6520666c69702070686f6e6520a720a8204e2072616e646f6d207370656369616c20636861726374657273'
     pdu = self.getPDU(pduHex)
     self.assertRaises(UnicodeDecodeError, SMStringEncoder().decodeSM, pdu)
Exemplo n.º 25
0
    async def handle_data_received(self, data: bytes):
        self.app.logger.debug(f'Received {len(data)} bytes.')
        self.app.logger.debug(data)

        file = io.BytesIO(data)

        pdu = PDUEncoder().decode(file)

        self.app.logger.debug(f'Command received: {pdu.command_id}')

        if pdu.command_id == CommandId.submit_sm:
            submit_sm = SubmitSM(sequence_number=pdu.sequence_number,
                                 **pdu.params)
            sms = SMStringEncoder().decode_SM(submit_sm).str

            self._send_response(
                submit_sm.require_ack(
                    sequence_number=submit_sm.sequence_number))

            # Check if the message is only a part from a series
            while (submit_sm.params.get('more_messages_to_send') ==
                   MoreMessagesToSend.MORE_MESSAGES):

                pdu = PDUEncoder().decode(file)
                if pdu.command_id != CommandId.submit_sm:
                    raise Exception(
                        f'Received {pdu.command_id} instead '
                        f'of {CommandId.submit_sm} for concatenated messages')
                submit_sm = SubmitSM(sequence_number=pdu.sequence_number,
                                     **pdu.params)
                sms += SMStringEncoder().decode_SM(submit_sm).str

                self._send_response(
                    submit_sm.require_ack(
                        sequence_number=submit_sm.sequence_number))

            await self.app.handle_sms_received(
                client=self._client,
                source_number=submit_sm.params['source_addr'],
                dest_number=submit_sm.params['destination_addr'],
                text=sms)
        elif pdu.command_id == CommandId.bind_transceiver:
            request = BindTransceiver(sequence_number=pdu.sequence_number,
                                      **pdu.params)

            if self.is_bound:
                smpp_status = CommandStatus.ESME_RALYBND
            else:
                client = SmppClient(
                    protocol=self,
                    system_id=request.params['system_id'],
                    password=request.params['password'],
                    system_type=request.params['system_type'],
                    interface_version=request.params['interface_version'],
                    addr_ton=request.params['addr_ton'],
                    addr_npi=request.params['addr_npi'])

                self._client = client
                try:
                    client = await self.app.handle_bound_client(client=client)
                except Exception as e:
                    self.app.logger.error(
                        f'Exception in handle_bound_client: {e}')
                    smpp_status = CommandStatus.ESME_RBINDFAIL
                else:
                    if client:
                        self.is_bound = True
                        smpp_status = CommandStatus.ESME_ROK
                    else:
                        self.is_bound = False
                        # Generic bind error
                        smpp_status = CommandStatus.ESME_RBINDFAIL

            resp = BindTransceiverResp(sequence_number=request.sequence_number,
                                       status=smpp_status,
                                       system_id=self.app.name)
            self._send_response(resp)

        elif pdu.command_id == CommandId.unbind:
            self.is_bound = False

            request = Unbind(sequence_number=pdu.sequence_number, **pdu.params)
            resp = UnbindResp(sequence_number=request.sequence_number)

            self._send_response(resp)

            await self.app.handle_unbound_client(self._client)

        else:
            await self.request_handler(pdu)