Exemple #1
0
import unittest
Exemple #2
0
def startup():
    validators['uid'] = Validator("UID/TOKEN validator", r"^[0-9a-f]{32}$")
    validators['token'] = validators['uid']
    validators['slot'] = Validator("PORT/SLOT validator", r"^[0-9]+$")
    validators['port'] = validators['slot']
    validators['config'] = Validator("CONFIG validator", r".*")
Exemple #3
0
from validators import Validator
username = '******'
validator = Validator()
if validator.username_is_valid(username):
    print("username is valid ")
else:
    print("username is invalid ")


if __name__ == "__main__":
    main = Main()
    communicator = Communicator()
    # import pydevd
    # port_mapping = [43777, 42797, 40239, 43883]
    # pydevd.settrace('localhost', port=port_mapping[communicator.rank], stdoutToServer=True, stderrToServer=True)

    if communicator.comm.rank == 0:
        beacon = Beacon()
        beacon.boot_beacon()
        beacon.send_acc_info()
    communicator.comm.barrier()
    if communicator.comm.rank != 0:
        validators = Validator()
        notarries = Nottaries()
    if communicator.rank == 1:  # one rank works as timer. First one, beacouse 0-th is more busy. Needed for examination
        time_list = [0]
        transactions_nb = [0]
        gg = True
    for tick in range(main.get__sim_time()):
        if communicator.rank == 0:
            if tick % 10 == 0:
                beacon.choose_rotated_nodes(beacon.notary_acc_info,
                                            beacon.nb_notary_migrates, 3)
            if tick % 25 == 0:
                beacon.choose_rotated_nodes(beacon.val_acc_info,
                                            beacon.nb_val_migrates, 4)
        communicator.comm.barrier()
        if communicator.rank != 0:
Exemple #5
0
        def authorize(self,
                      user,
                      act_as,
                      resource,
                      data,
                      content_type,
                      action=None):
            if not action:
                action = 'GET'
            if not user or not act_as or not resource:
                return AuthorizeResult(False)

            if user not in self.data.keys() or act_as not in self.data.keys():
                logger.warning("Invalid user [{}] or act as user [{}]".format(
                    user, act_as))
                return AuthorizeResult(False)

            if user != act_as:
                if 'can_act_as' not in self.data[user]:
                    logger.warning(
                        "User {} not authorized to act as {}".format(
                            user, act_as))
                    return AuthorizeResult(False)

            allowed_users_list = self._get_act_as_list(user)

            if act_as not in allowed_users_list:
                logger.warning("User {} not authorized to act as {}".format(
                    user, act_as))
                return AuthorizeResult(False)

            allowed_users_list = []
            allowed_actions = []
            if 'action' in self.data[
                    act_as] and self.data[act_as]['action'] != None:
                for item in self.data[act_as]['action'][action]:
                    temp_item = {}
                    if type(item) == str:
                        temp_item = {}
                        temp_item[item] = {}
                    else:
                        if type(item) == dict:
                            temp_item = item

                    if not temp_item in allowed_actions:
                        allowed_actions.append(temp_item)

            self._get_merged_data(act_as, allowed_users_list, allowed_actions,
                                  self.data, action)

            result = self.resource_check(resource, data, allowed_actions,
                                         content_type)
            if result == False:
                logger.warning(
                    "User {} acting as {} is not authorized to access [{}]".
                    format(user, act_as, resource))
                return AuthorizeResult(False)

            try:
                validator = Validator()
                framework = FrameworkUtils().getFramework(resource)
                if not validator.validate(act_as, resource, action, data,
                                          framework):
                    logger.warning("Validation failed. Reasons - {}".format(
                        validator.messages))
                    return AuthorizeResult(False, validator.messages)
            except (Exception) as e:
                logger.error("Failed in request validation - {}".format(
                    str(e)))
                return AuthorizeResult(False)

            return AuthorizeResult(True)
Exemple #6
0
# Define Validators
########################################

#############
stop_validator = KeywordValidator('stop')
validators.append(stop_validator)


@stop_validator.set('action')
def validator_action(contact, message):
    print 'STOP messaging for {}'.format(contact)
    contact.set_status('stopped', 'Participant sent stop keyword')


############
validation_validator = Validator('validation')
validators.append(validation_validator)


@validation_validator.set('check')
def validator_action(contact, message):
    if re.match('^\d{5}$', message) and not contact.is_validated:
        if contact.validation_key == message.strip():
            message = 'Validation Code Correct: ' + message
            return True, {
                'topic': 'validation',
                'is_related': True,
                'is_viewed': True
            }, message
        else:
            message = 'Validation Code Incorrect: ' + message
Exemple #7
0
import json

import rlp
from casper_messages import PrepareMessage
from validators import Validator
from ethereum.utils import encode_hex

validators = [
    Validator(
        id=0,
        deposit=100000000000000000000,
        dynasty_start=0,
        dynasty_end=100000000000000000,
        withdrawal_time=100000000000000000000,
        withdrawal_addr='',
        addr='',
        max_prepared=0,
        max_committed=0
    )
]


class LevelDBStore(object):

    def __init__(self, db):
        self.db = db

        try:
            self.db.get('HEAD')
        except KeyError:
            self.init_db()
Exemple #8
0
@stop_validator.set('action')
def validator_action(message):
    print 'STOP messaging for {}'.format(message.contact)
    message.contact.set_status('stopped', 'Participant sent stop keyword')
    message.text += ' - participant withdrew'
    message.contact.send_automated_message(send_base='stop',
                                           send_offset=0,
                                           group='one-way',
                                           hiv_messaging=False,
                                           control=True)
    return False


###############
validation_validator = Validator('validation')
validators.append(validation_validator)


@validation_validator.set('check')
def validator_action(message):
    if re.match('^\d{5}$', message.text) and not message.contact.is_validated:
        message.topic = 'validation'
        message.is_related = True
        message.is_viewed = True
        if message.contact.validation_key == message.text.strip():
            message.text = 'Validation Code Correct: ' + message.text
            return True
        else:
            message.text = 'Validation Code Incorrect: ' + message.text
            return False