Esempio n. 1
0
    def test_all(self):
        _cred = SmppsCredential()
        _cred.setAuthorization('bind', False)
        _cred.setQuota('max_bindings', 11)

        # Assert User adding
        extraCommands = [{
            'command': 'uid user_1'
        }, {
            'command': 'smpps_cred authorization bind no'
        }, {
            'command': 'smpps_cred quota max_bindings 11'
        }]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup',
                                             'AnyUsername', _cred)

        # Assert User updating
        _cred.setAuthorization('bind', True)
        _cred.setQuota('max_bindings', 66)
        extraCommands = [{
            'command': 'smpps_cred authorization bind y'
        }, {
            'command': 'smpps_cred quota max_bindings 66'
        }]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup',
                                             'AnyUsername', _cred)
Esempio n. 2
0
    def test_default(self):
        "Default user is created with a default SmppsCredential() instance"

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', SmppsCredential())

        # Assert User updating
        extraCommands = [{'command': 'password anypassword'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', SmppsCredential())
Esempio n. 3
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)
Esempio n. 4
0
    def test_quota(self):
        _cred = SmppsCredential()
        _cred.setQuota('max_bindings', 10)

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'smpps_cred quota max_bindings 10'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

        # Assert User updating
        _cred.setQuota('max_bindings', 20)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings 20'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
Esempio n. 5
0
    def test_authorization(self):
        _cred = SmppsCredential()
        _cred.setAuthorization('bind', False)

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'smpps_cred authorization bind no'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

        # Assert User updating
        _cred.setAuthorization('bind', True)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred authorization bind 1'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
Esempio n. 6
0
    def test_increase_decrease_quota_int(self):
        # Add with initial quota
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'smpps_cred quota max_bindings 100'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        _cred = SmppsCredential()
        _cred.setQuota('max_bindings', 20)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings -90'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings +10'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
Esempio n. 7
0
    def test_increase_decrease_quota_int(self):
        # Add with initial quota
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'smpps_cred quota max_bindings 100'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        _cred = SmppsCredential()
        _cred.setQuota('max_bindings', 20)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings -90'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings +10'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
Esempio n. 8
0
    def test_increase_decrease_quota_invalid_type(self):
        # Add with initial quota
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'smpps_cred quota max_bindings 100'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        # Quota will remain the same since the following updates are using incorrect type
        _cred = SmppsCredential()
        _cred.setQuota('max_bindings', 100)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings -90.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings +10.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
Esempio n. 9
0
    def test_increase_decrease_quota_invalid_type(self):
        # Add with initial quota
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'smpps_cred quota max_bindings 100'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        # Quota will remain the same since the following updates are using incorrect type
        _cred = SmppsCredential()
        _cred.setQuota('max_bindings', 100)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings -90.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'smpps_cred quota max_bindings +10.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
Esempio n. 10
0
    def test_quota(self):
        _cred = SmppsCredential()
        _cred.setQuota('max_bindings', 10)

        # Assert User adding
        extraCommands = [{
            'command': 'uid user_1'
        }, {
            'command': 'smpps_cred quota max_bindings 10'
        }]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup',
                                             'AnyUsername', _cred)

        # Assert User updating
        _cred.setQuota('max_bindings', 20)
        extraCommands = [{
            'command': 'password anypassword'
        }, {
            'command': 'smpps_cred quota max_bindings 20'
        }]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup',
                                             'AnyUsername', _cred)
Esempio n. 11
0
    def test_authorization(self):
        _cred = SmppsCredential()
        _cred.setAuthorization('bind', False)

        # Assert User adding
        extraCommands = [{
            'command': 'uid user_1'
        }, {
            'command': 'smpps_cred authorization bind no'
        }]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup',
                                             'AnyUsername', _cred)

        # Assert User updating
        _cred.setAuthorization('bind', True)
        extraCommands = [{
            'command': 'password anypassword'
        }, {
            'command': 'smpps_cred authorization bind 1'
        }]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup',
                                             'AnyUsername', _cred)
Esempio n. 12
0
    def test_all(self):
        _cred = SmppsCredential()
        _cred.setAuthorization('bind', False)
        _cred.setQuota('max_bindings', 11)

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'smpps_cred authorization bind no'},
                         {'command': 'smpps_cred quota max_bindings 11'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

        # Assert User updating
        _cred.setAuthorization('bind', True)
        _cred.setQuota('max_bindings', 66)
        extraCommands = [{'command': 'smpps_cred authorization bind y'},
                         {'command': 'smpps_cred quota max_bindings 66'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_SmppsCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
Esempio n. 13
0
def castToBuiltCorrectCredType(cred, section, key, value):
    'Will cast value to the correct type depending on the cred class, section and key'

    if cred == 'MtMessagingCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif key == 'balance' or key == 'early_decrement_balance_percent':
                value = float(value)
            elif key == 'submit_sm_count':
                value = int(value)
            elif key in ['http_throughput', 'smpps_throughput']:
                value = float(value)

        # Make a final validation: pass value to a temporarly MtMessagingCredential
        # object, an exception will be raised if the type is not correct
        _o = MtMessagingCredential()
        getattr(_o, 'set%s' % section)(key, value)
    elif cred == 'SmppsCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif key == 'max_bindings':
                value = int(value)

        # Make a final validation: pass value to a temporarly SmppsCredential
        # object, an exception will be raised if the type is not correct
        _o = SmppsCredential()
        getattr(_o, 'set%s' % section)(key, value)

    return value
Esempio n. 14
0
def castToBuiltCorrectCredType(cred, section, key, value, update=False):
    'Will cast value to the correct type depending on the cred class, section and key'
    keep_original_value = None

    if cred == 'MtMessagingCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif update and value[:1] in ['+', '-']:
                if (key in [
                        'balance', 'early_decrement_balance_percent',
                        'http_throughput', 'smpps_throughput'
                ]):
                    keep_original_value = float(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+f%s' % float(value)
                    value = abs(float(value))
                elif key == 'submit_sm_count':
                    keep_original_value = int(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+i%s' % int(value)
                    value = abs(int(value))
            elif (key in [
                    'balance', 'early_decrement_balance_percent',
                    'http_throughput', 'smpps_throughput'
            ]):
                value = float(value)
            elif key == 'submit_sm_count':
                value = int(value)

        # Make a final validation: pass value to a temporarly MtMessagingCredential
        # object, an exception will be raised if the type is not correct
        _o = MtMessagingCredential()
        getattr(_o, 'set%s' % section)(key, value)
    elif cred == 'SmppsCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif update and value[:1] in ['+', '-']:
                if key == 'max_bindings':
                    keep_original_value = int(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+i%s' % int(value)
                    value = abs(int(value))
            elif key == 'max_bindings':
                value = int(value)

        # Make a final validation: pass value to a temporarly SmppsCredential
        # object, an exception will be raised if the type is not correct
        _o = SmppsCredential()
        getattr(_o, 'set%s' % section)(key, value)

    if keep_original_value is not None:
        return keep_original_value
    else:
        return value