コード例 #1
0
    def setUp(self):
        HTTPApiTestCases.setUp(self)

        # Provision Router with additional Users and Routes
        u2 = User(2, Group(2), 'user2', 'correct')
        u2.mt_credential.setQuota('balance', 100.2)
        u2.mt_credential.setQuota('submit_sm_count', 30)
        u3 = User(3, Group(2), 'user3', 'correct')
        u3.mt_credential.setQuota('balance', 10)
        self.RouterPB_f.users.append(u2)
        self.RouterPB_f.users.append(u3)
コード例 #2
0
    def setUp(self):
        HTTPApiTestCases.setUp(self)

        # Provision Router with additional Users and Routes
        u2 = User(2, Group(2), 'user2', 'correct')
        u3 = User(3, Group(2), 'user3', 'correct')
        u3.mt_credential.setQuota('balance', 10)
        self.RouterPB_f.users.append(u2)
        self.RouterPB_f.users.append(u3)
        filters = [GroupFilter(Group(2))]
        route = StaticMTRoute(filters, SmppClientConnector('abc'), 1.5)
        self.RouterPB_f.mt_routing_table.add(route, 2)
コード例 #3
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate jasmin.routing.jasminApi.User with sessBuffer content
        if cmd == 'ok':
            if ('uid' not in self.sessBuffer or 'group' not in self.sessBuffer
                    or 'username' not in self.sessBuffer
                    or 'password' not in self.sessBuffer):
                return self.protocol.sendData(
                    'You must set User id (uid), group (gid), username and password before saving !'
                )

            # Set defaults when not defined
            if 'mt_credential' not in self.sessBuffer:
                self.sessBuffer[UserKeyMap['mt_messaging_cred']
                                ['keyMapValue']] = globals()[
                                    UserKeyMap['mt_messaging_cred']['class']]()
            if 'smpps_credential' not in self.sessBuffer:
                self.sessBuffer[UserKeyMap['smpps_cred']
                                ['keyMapValue']] = globals()[
                                    UserKeyMap['smpps_cred']['class']]()

            user = {}
            for key, value in self.sessBuffer.iteritems():
                user[key] = value
            try:
                UserInstance = User(**user)
                # Hand the instance to fCallback
                return fCallback(self, UserInstance)
            except Exception, e:
                return self.protocol.sendData('Error: %s' % str(e))
コード例 #4
0
    def setUp(self):
        yield HappySMSCTestCase.setUp(self)

        # Init
        self.group1 = Group('g1')
        self.user1 = User('1', self.group1, 'u1', 'password')
        self.c1 = SmppClientConnector('smpp_c1')
コード例 #5
0
def fix_users_and_smppccs_09rc23(data, context=None):
    """Adding the new authorization 'set_hex_content' and fix smppccs with proto_id having a None string
    value"""

    if context == 'users':
        # Create new users and modify the mt_credential to include the new authorization
        new_data = []
        for old_user in data:
            user = User(
                uid=old_user.uid,
                group=Group(old_user.group.gid),
                username=old_user.username,
                password=old_user.password,
                password_crypted=True,
                mt_credential=old_user.mt_credential,
                smpps_credential=old_user.smpps_credential)

            user.mt_credential.authorizations['set_hex_content'] = True
            user.mt_credential.authorizations['set_schedule_delivery_time'] = True
            new_data.append(user)

        return new_data
    elif context == 'smppccs':
        # Fix smppccs proto_id value
        for smppcc in data:
            if isinstance(smppcc['config'].protocol_id, str) and smppcc['config'].protocol_id.lower() == 'none':
                smppcc['config'].protocol_id = None

        return data
コード例 #6
0
ファイル: test_managers.py プロジェクト: selimppc/jasminsms
    def setUp(self):
        yield SMSCSimulatorRecorder.setUp(self)

        self.SMSCPort.factory.buildProtocol = mock.Mock(
            wraps=self.SMSCPort.factory.buildProtocol)

        self.SubmitSmBill = SubmitSmBill(
            User('test_user', Group('test_group'), 'test_username', 'pwd'))
コード例 #7
0
 def setUp(self):
     self.opFactory = SMPPOperationFactory(SMPPClientConfig(id='test-id'))
     self.user = User(1, Group(100), 'username', 'password')
     self.pdu = self.opFactory.SubmitSM(
         source_addr=b'2',
         destination_addr=b'3',
         short_message=b'sunny day !',
     )
コード例 #8
0
    def setUp(self):
        SMPPClientTestCases.setUp(self)

        # Provision a user and default route into RouterPB
        # Add throughput limit on user
        self.foo = User('u1', Group('test'), 'username', 'password')
        self.foo.mt_credential.setQuota('smpps_throughput', 2)
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user=self.foo, defaultroute=self.defaultroute)

        self.stats = SMPPServerStatsCollector().get(cid=self.smpps_config.id)
コード例 #9
0
ファイル: test_managers.py プロジェクト: MessageCloud/jasmin
    def setUp(self):
        yield SMSCSimulatorRecorder.setUp(self)

        self.SMSCPort.factory.buildProtocol = mock.Mock(wraps=self.SMSCPort.factory.buildProtocol)

        config = SMPPClientConfig(id='defaultId')
        opFactory = SMPPOperationFactory(config)
        self.SubmitSmPDU = opFactory.SubmitSM(
            source_addr='1423',
            destination_addr='06155423',
            short_message='Hello world !',
        )

        self.SubmitSmBill = SubmitSmBill(User('test_user', Group('test_group'), 'test_username', 'pwd'))
コード例 #10
0
def runScenario(Request, method):
    try:
        proxy_router = RouterPBProxy()
        yield proxy_router.connect('127.0.0.1', 8988, 'radmin', 'rpwd')

        if method == "POST":
            smppUser = Request['username']
            smppPass = Request['password']
            smppThroughput = Request['tp']
            smppBindSessions = Request['sessions']

            if not smppUser:
                raise NameError('user')

            if len(smppPass) == 0 or len(smppPass) > 8:
                raise NameError('pass')

            if not smppThroughput.isdigit():
                raise NameError('tp')

            if not smppBindSessions.isdigit():
                raise NameError('session')

            # Provisiong router with users
            smpp_cred = SmppsCredential()
            yield smpp_cred.setQuota('max_bindings', int(smppBindSessions))
            mt_cred = MtMessagingCredential()
            yield mt_cred.setQuota('smpps_throughput', smppThroughput)
            #yield mt_cred.setQuota('submit_sm_count' , 500)

            g1 = Group('clients')
            u1 = User(uid=smppUser,
                      group=g1,
                      username=smppUser,
                      password=smppPass,
                      mt_credential=mt_cred,
                      smpps_credential=smpp_cred)
            yield proxy_router.group_add(g1)
            yield proxy_router.user_add(u1)
            print "Success"
        if method == 'DELETE':

            smppUser = Request['username']

            if not smppUser:
                raise NameError('user')

            yield proxy_router.user_remove(smppUser)
    except Exception, e:
        print "%s" % str(e)
コード例 #11
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
        self.routerpb_config = RouterPBConfig()

        # Instanciate RouterPB but will not launch a server
        # we only need the instance to access its .users attribute
        # for authentication
        self.routerpb_factory = RouterPB(self.routerpb_config, persistenceTimer=False)

        # Provision a user and default route into RouterPB
        self.foo = User('u1', Group('test'), 'username', 'password')
        self.c1 = SmppClientConnector(id_generator())
        self.defaultroute = DefaultRoute(self.c1)
        self.provision_user_defaultroute(user=self.foo, defaultroute=self.defaultroute)
コード例 #12
0
def runScenario():
    try:
        ## First part, SMPP Client connector management
        ###############################################
        # Connect to SMPP Client management PB proxy
        proxy_smpp = SMPPClientManagerPBProxy()
        yield proxy_smpp.connect('127.0.0.1', 8989, 'cmadmin', 'cmpwd')

        # Provision SMPPClientManagerPBProxy with a connector and start it
        connector1 = {
            'id': 'abc',
            'username': '******',
            'reconnectOnConnectionFailure': True
        }
        config1 = SMPPClientConfig(**connector1)
        yield proxy_smpp.add(config1)
        yield proxy_smpp.start('abc')

        ## Second part, User and Routing management
        ###########################################
        # Connect to Router PB proxy
        proxy_router = RouterPBProxy()
        yield proxy_router.connect('127.0.0.1', 8988, 'radmin', 'rpwd')

        # Provision RouterPBProxy with MT routes
        yield proxy_router.mtroute_add(
            DefaultRoute(SmppClientConnector('abc')), 0)
        routes = yield proxy_router.mtroute_get_all()
        print("Configured routes: \n\t%s" % pickle.loads(routes))

        # Provisiong router with users
        g1 = Group(1)
        u1 = User(uid=1, group=g1, username='******', password='******')
        yield proxy_router.group_add(g1)
        yield proxy_router.user_add(u1)
        users = yield proxy_router.user_get_all()
        print("Users: \n\t%s" % pickle.loads(users))

        ## Last, tear down
        ##################
        # Stop connector
        yield proxy_smpp.stop('abc')
    except Exception as e:
        print("ERROR RUNNING SCENARIO: %s" % str(e))
    finally:
        reactor.stop()
コード例 #13
0
def user_status(data):
    """Changes impacted by #306

    Will migrate users to enable newly applied changes for enable/disable"""

    # Create new users, they will have the enable/disable methods
    new_data = []
    for old_user in data:
        user = User(uid=old_user.uid,
                    group=Group(old_user.group.gid),
                    username=old_user.username,
                    password=old_user.password,
                    password_crypted=True,
                    mt_credential=old_user.mt_credential,
                    smpps_credential=old_user.smpps_credential)
        new_data.append(user)

    return new_data
コード例 #14
0
    def setUp(self):
        # Instanciate a RouterPB (a requirement for HTTPApi)
        RouterPBConfigInstance = RouterPBConfig()
        self.RouterPB_f = RouterPB()
        self.RouterPB_f.setConfig(RouterPBConfigInstance)
        
        # Provision Router with User and Route
        self.u1 = User(1, Group(1), 'fourat', 'correct')
        self.RouterPB_f.users.append(self.u1)
        self.RouterPB_f.mt_routing_table.add(DefaultRoute(SmppClientConnector('abc')), 0)

        # Instanciate a SMPPClientManagerPB (a requirement for HTTPApi)
        SMPPClientPBConfigInstance = SMPPClientPBConfig()
        SMPPClientPBConfigInstance.authentication = False
        clientManager_f = SMPPClientManagerPB()
        clientManager_f.setConfig(SMPPClientPBConfigInstance)
        
        httpApiConfigInstance = HTTPApiConfig()
        self.web = DummySite(HTTPApi(self.RouterPB_f, clientManager_f, httpApiConfigInstance))
コード例 #15
0
def fix_users_09rc24(data, context=None):
    """Adding the new authorization 'set_schedule_delivery_time'
    value"""

    if context == 'users':
        # Create new users and modify the mt_credential to include the new authorization
        new_data = []
        for old_user in data:
            user = User(
                uid=old_user.uid,
                group=Group(old_user.group.gid),
                username=old_user.username,
                password=old_user.password,
                password_crypted=True,
                mt_credential=old_user.mt_credential,
                smpps_credential=old_user.smpps_credential)

            user.mt_credential.authorizations['set_schedule_delivery_time'] = True
            new_data.append(user)

        return new_data
コード例 #16
0
 def setUp(self):
     self.group = Group(1)
     self.user = User(1, self.group, 'foo', 'bar')
コード例 #17
0
    def parse_args_and_call_with_instance(self, *args, **kwargs):
        cmd = args[0]
        arg = args[1]

        # Empty line
        if cmd is None:
            return self.protocol.sendData()
        # Initiate jasmin.routing.jasminApi.User with sessBuffer content
        if cmd == 'ok':
            if ('uid' not in self.sessBuffer or 'group' not in self.sessBuffer
                    or 'username' not in self.sessBuffer
                    or 'password' not in self.sessBuffer):
                return self.protocol.sendData(
                    'You must set User id (uid), group (gid), username and password before saving !'
                )

            # Set defaults when not defined
            if 'mt_credential' not in self.sessBuffer:
                self.sessBuffer[UserKeyMap['mt_messaging_cred']
                                ['keyMapValue']] = globals()[
                                    UserKeyMap['mt_messaging_cred']['class']]()
            if 'smpps_credential' not in self.sessBuffer:
                self.sessBuffer[UserKeyMap['smpps_cred']
                                ['keyMapValue']] = globals()[
                                    UserKeyMap['smpps_cred']['class']]()

            user = {}
            for key, value in self.sessBuffer.iteritems():
                user[key] = value
            try:
                UserInstance = User(**user)
                # Hand the instance to fCallback
                return fCallback(self, UserInstance)
            except Exception as e:
                return self.protocol.sendData('Error: %s' % str(e))
        else:
            # Unknown key
            if cmd not in UserKeyMap:
                return self.protocol.sendData('Unknown User key: %s' % cmd)

            if isinstance(UserKeyMap[cmd], dict):
                # Provisioning a sub-User instance (MtMessagingCredential ...)
                subKeyMap = UserKeyMap[cmd]

                # Syntax validation
                _r = re.match(r'^(\S+) (\S+) (\S+.*$)', arg)
                if not _r:
                    return self.protocol.sendData(
                        'Error: expected syntax: %s section key value' % cmd)

                section = _r.group(1).lower()
                key = _r.group(2).lower()
                value = _r.group(3)

                # Validate section
                possible_values = subKeyMap.keys()
                possible_values.remove('class')
                possible_values.remove('keyMapValue')
                valid_section = False
                for pv in possible_values:
                    if section == pv.lower():
                        section = pv
                        valid_section = True
                        break
                if not valid_section:
                    return self.protocol.sendData(
                        'Error: invalid section name: %s, possible values: %s'
                        % (section, ', '.join(possible_values)))

                # Validate key
                if key not in subKeyMap[section].keys():
                    return self.protocol.sendData(
                        'Error: invalid key: %s, possible keys: %s' %
                        (key, ', '.join(subKeyMap[section].keys())))
                SectionKey = subKeyMap[section][key]

                try:
                    # Input value are received in string type, castToBuiltCorrectCredType will fix the
                    # type depending on class, section and SectionKey
                    SectionValue = castToBuiltCorrectCredType(
                        subKeyMap['class'], section, SectionKey, value)

                    # Instanciate a new sub-User object
                    if subKeyMap['keyMapValue'] not in self.sessBuffer:
                        self.sessBuffer[subKeyMap['keyMapValue']] = globals()[
                            subKeyMap['class']]()

                    # Set sub-User object value
                    getattr(self.sessBuffer[subKeyMap['keyMapValue']],
                            'set%s' % section)(SectionKey, SectionValue)
                except (jasminApiCredentialError, ValueError) as e:
                    return self.protocol.sendData('Error: %s' % str(e))
            else:
                # Provisioning User instance
                # IF we got the gid, instanciate a Group if gid exists or return an error
                if cmd == 'gid':
                    group = self.pb['router'].getGroup(arg)
                    if group is None:
                        return self.protocol.sendData(
                            'Unknown Group gid:%s, you must first create the Group'
                            % arg)

                    self.sessBuffer['group'] = group
                else:
                    # Buffer key for later User initiating
                    UserKey = UserKeyMap[cmd]
                    if UserKey not in UserConfigStringKeys:
                        self.sessBuffer[UserKey] = str2num(arg)
                    else:
                        self.sessBuffer[UserKey] = arg

            return self.protocol.sendData()