Exemple #1
0
    def test_non_existing_security_scheme(self, mock_parse):
        with pytest.raises(ValueError) as ex:
            acl.generate_acl(
                context_cls='Foo',
                raml_resource=Mock(securedBy=['foo']),
                parsed_raml=Mock(securitySchemes={'1': '2'}),
                es_based=True)

        assert 'Undefined ACL security scheme: foo' == str(ex.value)
Exemple #2
0
 def test_database_acls_option(self, mock_parse):
     raml_resource = Mock(security_schemes=[
         Mock(type='x-ACL', settings={'collection': 4, 'item': 7})
     ])
     kwargs = dict(
         model_cls='Foo',
         raml_resource=raml_resource,
         es_based=False,
     )
     config = config_mock()
     config.registry.database_acls = False
     acl_cls = acl.generate_acl(config, **kwargs)
     assert not issubclass(acl_cls, acl.DatabaseACLMixin)
     config.registry.database_acls = True
     acl_cls = acl.generate_acl(config, **kwargs)
     assert issubclass(acl_cls, acl.DatabaseACLMixin)
Exemple #3
0
 def test_database_acls_option(self, mock_parse):
     raml_resource = Mock(security_schemes=[
         Mock(type='x-ACL', settings={'collection': 4, 'item': 7})
     ])
     kwargs = dict(
         model_cls='Foo',
         raml_resource=raml_resource,
         es_based=False,
     )
     config = config_mock()
     config.registry.database_acls = False
     acl_cls = acl.generate_acl(config, **kwargs)
     assert not issubclass(acl_cls, acl.DatabaseACLMixin)
     config.registry.database_acls = True
     acl_cls = acl.generate_acl(config, **kwargs)
     assert issubclass(acl_cls, acl.DatabaseACLMixin)
Exemple #4
0
 def test_no_security(self, mock_parse):
     acl_cls = acl.generate_acl(
         context_cls='Foo',
         raml_resource=Mock(securedBy=None),
         parsed_raml=1123,
         es_based=True)
     assert acl_cls.__context_class__ == 'Foo'
     assert issubclass(acl_cls, acl.BaseACL)
     instance = acl_cls(request=None)
     assert instance.es_based
     assert instance.collection_acl == [acl.ALLOW_ALL]
     assert instance.item_acl == [acl.ALLOW_ALL]
     assert not mock_parse.called
Exemple #5
0
 def test_no_security(self, mock_parse):
     config = config_mock()
     acl_cls = acl.generate_acl(
         config, model_cls='Foo',
         raml_resource=Mock(security_schemes=[]),
         es_based=True)
     assert acl_cls.item_model == 'Foo'
     assert issubclass(acl_cls, acl.BaseACL)
     instance = acl_cls(request=None)
     assert instance.es_based
     assert instance._collection_acl == [acl.ALLOW_ALL]
     assert instance._item_acl == [acl.ALLOW_ALL]
     assert not mock_parse.called
Exemple #6
0
 def test_no_security(self, mock_parse):
     config = config_mock()
     acl_cls = acl.generate_acl(config,
                                model_cls='Foo',
                                raml_resource=Mock(security_schemes=[]),
                                es_based=True)
     assert acl_cls.item_model == 'Foo'
     assert issubclass(acl_cls, acl.BaseACL)
     instance = acl_cls(request=None)
     assert instance.es_based
     assert instance._collection_acl == [acl.ALLOW_ALL]
     assert instance._item_acl == [acl.ALLOW_ALL]
     assert not mock_parse.called
Exemple #7
0
 def test_wrong_security_scheme_type(self, mock_parse):
     raml_resource = Mock(security_schemes=[
         Mock(type='x-Foo', settings={'collection': 4, 'item': 7})
     ])
     config = config_mock()
     acl_cls = acl.generate_acl(
         config, model_cls='Foo',
         raml_resource=raml_resource,
         es_based=False)
     assert not mock_parse.called
     assert acl_cls.item_model == 'Foo'
     assert issubclass(acl_cls, acl.BaseACL)
     instance = acl_cls(request=None)
     assert not instance.es_based
     assert instance._collection_acl == [acl.ALLOW_ALL]
     assert instance._item_acl == [acl.ALLOW_ALL]
Exemple #8
0
 def test_wrong_security_scheme_type(self, mock_parse):
     raml_resource = Mock(security_schemes=[
         Mock(type='x-Foo', settings={'collection': 4, 'item': 7})
     ])
     config = config_mock()
     acl_cls = acl.generate_acl(
         config, model_cls='Foo',
         raml_resource=raml_resource,
         es_based=False)
     assert not mock_parse.called
     assert acl_cls.item_model == 'Foo'
     assert issubclass(acl_cls, acl.BaseACL)
     instance = acl_cls(request=None)
     assert not instance.es_based
     assert instance._collection_acl == []
     assert instance._item_acl == []
Exemple #9
0
 def test_existing_security_scheme(self, mock_parse):
     parsed_raml = Mock(securitySchemes={
         'foo': Mock(settings={'collection': 4, 'item': 7})
     })
     acl_cls = acl.generate_acl(
         context_cls='Foo',
         raml_resource=Mock(securedBy=['foo']),
         parsed_raml=parsed_raml,
         es_based=False)
     mock_parse.assert_has_calls([
         call(acl_string=4, methods_map=acl.collection_methods),
         call(acl_string=7, methods_map=acl.item_methods),
     ])
     instance = acl_cls(request=None)
     assert instance.collection_acl == mock_parse()
     assert instance.item_acl == mock_parse()
     assert not instance.es_based
Exemple #10
0
 def test_correct_security_scheme(self, mock_parse):
     raml_resource = Mock(security_schemes=[
         Mock(type='x-ACL', settings={'collection': 4, 'item': 7})
     ])
     config = config_mock()
     acl_cls = acl.generate_acl(
         config, model_cls='Foo',
         raml_resource=raml_resource,
         es_based=False)
     mock_parse.assert_has_calls([
         call(acl_string=4),
         call(acl_string=7),
     ])
     instance = acl_cls(request=None)
     assert instance._collection_acl == mock_parse()
     assert instance._item_acl == mock_parse()
     assert not instance.es_based
Exemple #11
0
 def test_correct_security_scheme(self, mock_parse):
     raml_resource = Mock(security_schemes=[
         Mock(type='x-ACL', settings={'collection': 4, 'item': 7})
     ])
     config = config_mock()
     acl_cls = acl.generate_acl(
         config, model_cls='Foo',
         raml_resource=raml_resource,
         es_based=False)
     mock_parse.assert_has_calls([
         call(acl_string=4),
         call(acl_string=7),
     ])
     instance = acl_cls(request=None)
     assert instance._collection_acl == mock_parse()
     assert instance._item_acl == mock_parse()
     assert not instance.es_based