def setUp(self): self.PDU = SubmitSM( source_addr='20203060', destination_addr='20203060', short_message='hello world', ) self.connector = Connector('abc') self.user = User(1, Group(100), 'username', 'password')
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.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.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, )
def setUp(self): self.connector = Connector('abc') self.PDU = SubmitSM( source_addr='20203060', destination_addr='20203060', short_message='hello world', ) self.group = Group(100) self.user = User(1, self.group, 'username', 'password') self.routable = SimpleRoutablePDU(self.connector, self.PDU, self.user)
def setUp(self): RouteTestCase.setUp(self) self.PDU_dst_1 = SubmitSM( source_addr='20203060', destination_addr='1', short_message='hello world', ) self.routable_user1 = RoutableSubmitSm(self.PDU_dst_1, self.user1)
def test_message_payload(self): """Related to #380 Consider 'message_payload' when there is no 'short_message' parameter """ PDU_message_payload = SubmitSM( source_addr='20203060', destination_addr='20203060', message_payload='hello world', ) del PDU_message_payload.params['short_message'] _routable = SimpleRoutablePDU(self.connector, PDU_message_payload, self.user) self.assertTrue(self.f.match(_routable))
def setUp(self): RouteTestCase.setUp(self) self.PDU_dst_1 = SubmitSM( 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) self.connectors = [self.connector1, self.connector2]
def setUp(self, authentication=False): # Initiating config objects without any filename # will lead to setting defaults and that's what we # need to run the tests self.InterceptorPBConfigInstance = InterceptorPBConfig() self.InterceptorPBConfigInstance.authentication = authentication # Launch the interceptor pb server pbRoot = InterceptorPB() pbRoot.setConfig(self.InterceptorPBConfigInstance) p = portal.Portal(JasminPBRealm(pbRoot)) if not authentication: p.registerChecker(AllowAnonymousAccess()) else: c = InMemoryUsernamePasswordDatabaseDontUse() c.addUser('test_user', md5('test_password').digest()) p.registerChecker(c) jPBPortalRoot = JasminPBPortalRoot(p) self.IPBServer = reactor.listenTCP(0, pb.PBServerFactory(jPBPortalRoot)) self.ipbPort = self.IPBServer.getHost().port # Test fixtures self.SubmitSMPDU = SubmitSM( source_addr='20203060', destination_addr='20203060', short_message='MT hello world', ) self.DeliverSMPDU = DeliverSM( source_addr='20203060', destination_addr='20203060', short_message='MO hello world', ) self.connector = Connector('abc') self.user = User(1, Group(100), 'username', 'password') # Routables fixtures self.routable_simple = SimpleRoutablePDU(self.connector, self.SubmitSMPDU, self.user, datetime.now()) # Scripts fixtures self.script_generic = InterceptorScript( 'somevar = "something in MOIS"') self.script_3_second = InterceptorScript('import time;time.sleep(3)') self.script_syntax_error = InterceptorScript('somevar = sssss') self.script_http_status = InterceptorScript('http_status = 404') self.script_smpp_status = InterceptorScript('smpp_status = 64')
def SubmitSM(self, short_message, data_coding=0, **kwargs): """Depending on the short_message length, this method will return a classical SubmitSM or a serie of linked SubmitSMs (parted message) """ kwargs['short_message'] = short_message kwargs['data_coding'] = data_coding # Possible data_coding values : 0,1,2,3,4,5,6,7,8,9,10,13,14 # Set the max short message length depending on the # coding (7, 8 or 16 bits) if kwargs['data_coding'] in [3, 6, 7, 10]: # 8 bit coding maxSmLength = 140 slicedMaxSmLength = maxSmLength - 6 elif kwargs['data_coding'] in [2, 4, 5, 8, 9, 13, 14]: # 16 bit coding maxSmLength = 70 slicedMaxSmLength = maxSmLength - 3 else: # 7 bit coding is the default # for data_coding in [0, 1] or any other invalid value maxSmLength = 160 slicedMaxSmLength = 153 longMessage = kwargs['short_message'] smLength = len(kwargs['short_message']) # if SM is longer than maxSmLength, build multiple SubmitSMs # and link them if smLength > maxSmLength: total_segments = int(math.ceil(smLength / float(slicedMaxSmLength))) # Obey to configured longContentMaxParts if total_segments > self.long_content_max_parts: total_segments = self.long_content_max_parts msg_ref_num = self.claimLongSmSeqNum() for i in range(total_segments): segment_seqnum = i + 1 # Keep in memory previous PDU in order to set nextPdu in it later try: tmpPdu previousPdu = tmpPdu except NameError: previousPdu = None kwargs['short_message'] = longMessage[slicedMaxSmLength * i:slicedMaxSmLength * (i + 1)] tmpPdu = self._setConfigParamsInPDU(SubmitSM(**kwargs), kwargs) if self.long_content_split == 'sar': # Slice short_message and create the PDU using SAR options tmpPdu.params['sar_total_segments'] = total_segments tmpPdu.params['sar_segment_seqnum'] = segment_seqnum tmpPdu.params['sar_msg_ref_num'] = msg_ref_num elif self.long_content_split == 'udh': # Slice short_message and create the PDU using UDH options tmpPdu.params['esm_class'] = EsmClass( EsmClassMode.DEFAULT, EsmClassType.DEFAULT, [EsmClassGsmFeatures.UDHI_INDICATOR_SET]) if segment_seqnum < total_segments: tmpPdu.params[ 'more_messages_to_send'] = MoreMessagesToSend.MORE_MESSAGES else: tmpPdu.params[ 'more_messages_to_send'] = MoreMessagesToSend.NO_MORE_MESSAGES # UDH composition: udh = [] udh.append(struct.pack('!B', 5)) # Length of User Data Header udh.append( struct.pack('!B', 0) ) # Information Element Identifier, equal to 00 (Concatenated short messages, 8-bit reference number) udh.append( struct.pack('!B', 3) ) # Length of the header, excluding the first two fields; equal to 03 udh.append(struct.pack('!B', msg_ref_num)) udh.append(struct.pack('!B', total_segments)) udh.append(struct.pack('!B', segment_seqnum)) tmpPdu.params['short_message'] = ''.join( udh) + kwargs['short_message'] # - The first PDU is the one we return back # - sar_msg_ref_num takes the seqnum of the initial submit_sm if i == 0: pdu = tmpPdu # PDU chaining if previousPdu is not None: previousPdu.nextPdu = tmpPdu else: pdu = self._setConfigParamsInPDU(SubmitSM(**kwargs), kwargs) return pdu