Exemplo n.º 1
0
def test_generate_second_level_paths():
    d = {
        'firstname': 'john',
        'lastname': 'smith',
        'location': {
            'city': 'Osaka',
            'country': 'Japan',
            'geolocation': {
                'longitude': '90.00',
                'lattitude': '90.00'
            }
        },
        'birth_details': {
            'hospital': 'Kosei Nenkin',
            'dob': '12/2/1995'
        }
    }
    p = [str(x.full_path) for x in util.generate_paths(d)]
    logger.debug(p)
    assert len(p) == 8
    assert 'firstname' in p
    assert 'lastname' in p
    assert 'location.city' in p
    assert 'location.country' in p
    assert 'birth_details.hospital' in p
    assert 'birth_details.dob' in p
    assert 'location.geolocation.longitude' in p
    assert 'location.geolocation.lattitude' in p
Exemplo n.º 2
0
    def _encrypt(self, root_object, config_loader):
        if not config_loader or not callable(config_loader):
            return
        for unencrypted_value in util.generate_paths(root_object):
            path = str(unencrypted_value.full_path)
            if not self._can_crypto_path(path):
                continue

            if not self._can_crypto_type(unencrypted_value.value):
                logger.debug('Crypto ignored for: %s (%s)' %
                             (path, unencrypted_value.value))
                continue

            key = config_loader(DyStore.CONFIG_LOADER_LOAD_KEY,
                                path=path,
                                data=root_object)
            if key:
                cipher = AESCipher(key)
                json_path = parse(path)
                logger.debug('Encrypting item: %s' % path)
                encrypted_value = cipher.encrypt(unencrypted_value.value)
                logger.debug('Encrypted item: %s' % path)
                logger.debug('Before: %s' % root_object)
                json_path.update(root_object, encrypted_value)
                logger.debug('After: %s' % root_object)
Exemplo n.º 3
0
def test_generate_list_paths():
    d = {'firstname': 'john', 'lastname': 'smith', 'friends': ['john', 'bob']}
    p = [str(x.full_path) for x in util.generate_paths(d)]
    logger.debug(p)
    assert len(p) == 5
    assert 'firstname' in p
    assert 'lastname' in p
    assert 'friends' in p
    assert 'friends.[0]' in p
    assert 'friends.[1]' in p
Exemplo n.º 4
0
def test_generate_second_level_non_dict_list_paths():
    d = {
        'firstname': 'john',
        'lastname': 'smith',
        'person': {
            'locations': ['Japan', 'Africa']
        }
    }
    logger.debug(d)
    p = [str(x.full_path) for x in util.generate_paths(d)]
    logger.debug(p)
    assert len(p) == 5
    assert 'firstname' in p
    assert 'lastname' in p
    assert 'person.locations' in p
    assert 'person.locations.[0]' in p
    assert 'person.locations.[1]' in p
Exemplo n.º 5
0
def test_generate_second_level_list_paths():
    d = {
        'firstname': 'john',
        'lastname': 'smith',
        'person': {
            'locations': [{
                'city': 'Osaka',
                'country': 'Japan'
            }, {
                'city': 'Bejing',
                'country': 'China'
            }]
        }
    }
    p = [str(x.full_path) for x in util.generate_paths(d)]
    logger.debug(p)
    assert len(p) == 7
    assert 'firstname' in p
    assert 'lastname' in p
    assert 'person.locations' in p
    assert 'person.locations.[0].city' in p
    assert 'person.locations.[0].country' in p
    assert 'person.locations.[1].city' in p
    assert 'person.locations.[1].country' in p
Exemplo n.º 6
0
def test_generate_empty_dict_paths():
    d = {}
    p = [str(x.full_path) for x in util.generate_paths(d)]
    logger.debug(p)
    assert len(p) == 0