Ejemplo n.º 1
0
    def test_exposed_value(self):
        mock_type = MagicMock()
        mock_type.get_value = lambda user: '******'
        mock_type.from_value_secure = lambda value, spec: mock_type
        info = {'gob_type': mock_type, 'spec': 'any spec'}
        value = Authority.exposed_value('any value', info)
        self.assertEqual(value, 'protected value')

        value = Authority.exposed_value(None, info)
        self.assertEqual(value, None)
Ejemplo n.º 2
0
    def test_handle_secured_columns(self):
        authority = Authority('secure catalog', 'any col')
        authority.get_secured_columns = lambda: {'col': 'any info'}
        authority.exposed_value = lambda value, info: 'exposed value'

        row = {}
        authority._handle_secured_columns({}, row)
        self.assertEqual(row, {})

        row = {'col': 'any value', 'any other col': 'any value'}
        authority._handle_secured_columns({}, row)
        self.assertEqual(row, {
            'col': 'exposed value',
            'any other col': 'any value'
        })

        row = {'mapped col': 'any value', 'any other col': 'any value'}
        mapping = {'col': 'mapped col'}
        authority._handle_secured_columns(mapping, row)
        self.assertEqual(row, {
            'mapped col': 'exposed value',
            'any other col': 'any value'
        })