示例#1
0
    def test_routes_views_added(self, mock_policy):
        from ramses import auth
        auth_model = Mock()
        config = Mock()
        config.registry.auth_model = auth_model
        root = Mock()
        config.get_root_resource.return_value = root
        auth._setup_apikey_policy(config, {})
        assert root.add.call_count == 3
        token, reset_token, register = root.add.call_args_list
        token_kwargs = token[1]
        assert sorted(token_kwargs.keys()) == sorted(
            ['view', 'prefix', 'factory'])
        assert token_kwargs['prefix'] == 'auth'
        assert token_kwargs['factory'] == 'nefertari.acl.AuthenticationACL'

        reset_token_kwargs = reset_token[1]
        assert sorted(reset_token_kwargs.keys()) == sorted(
            ['view', 'prefix', 'factory'])
        assert reset_token_kwargs['prefix'] == 'auth'
        assert reset_token_kwargs[
            'factory'] == 'nefertari.acl.AuthenticationACL'

        register_kwargs = register[1]
        assert sorted(register_kwargs.keys()) == sorted(
            ['view', 'prefix', 'factory'])
        assert register_kwargs['prefix'] == 'auth'
        assert register_kwargs['factory'] == 'nefertari.acl.AuthenticationACL'
示例#2
0
    def test_routes_views_added(self, mock_policy):
        from ramses import auth
        auth_model = Mock()
        config = Mock()
        config.registry.auth_model = auth_model
        root = Mock()
        config.get_root_resource.return_value = root
        auth._setup_apikey_policy(config, {})
        assert root.add.call_count == 3
        token, reset_token, register = root.add.call_args_list
        token_kwargs = token[1]
        assert sorted(token_kwargs.keys()) == sorted([
            'view', 'prefix', 'factory'])
        assert token_kwargs['prefix'] == 'auth'
        assert token_kwargs['factory'] == 'nefertari.acl.AuthenticationACL'

        reset_token_kwargs = reset_token[1]
        assert sorted(reset_token_kwargs.keys()) == sorted([
            'view', 'prefix', 'factory'])
        assert reset_token_kwargs['prefix'] == 'auth'
        assert reset_token_kwargs['factory'] == 'nefertari.acl.AuthenticationACL'

        register_kwargs = register[1]
        assert sorted(register_kwargs.keys()) == sorted([
            'view', 'prefix', 'factory'])
        assert register_kwargs['prefix'] == 'auth'
        assert register_kwargs['factory'] == 'nefertari.acl.AuthenticationACL'
示例#3
0
    def test_routes_views_added(self, mock_policy):
        from ramses import auth
        auth_model = Mock()
        config = Mock()
        config.registry.auth_model = auth_model
        auth._setup_apikey_policy(config, {})
        config.add_route.assert_has_calls([
            call('token', '/auth/token'),
            call('reset_token', '/auth/reset_token'),
            call('register', '/auth/register'),
        ])

        token, reset_token, register = config.add_view.call_args_list
        token_kwargs = token[1]
        assert sorted(token_kwargs.keys()) == sorted([
            'request_method', 'view', 'route_name', 'attr'])
        assert token_kwargs['route_name'] == 'token'
        assert token_kwargs['attr'] == 'claim_token'
        assert token_kwargs['request_method'] == 'POST'

        reset_token_kwargs = reset_token[1]
        assert sorted(reset_token_kwargs.keys()) == sorted([
            'request_method', 'view', 'route_name', 'attr'])
        assert reset_token_kwargs['route_name'] == 'reset_token'
        assert reset_token_kwargs['attr'] == 'reset_token'
        assert reset_token_kwargs['request_method'] == 'POST'

        register_kwargs = register[1]
        assert sorted(register_kwargs.keys()) == sorted([
            'request_method', 'view', 'route_name', 'attr'])
        assert register_kwargs['route_name'] == 'register'
        assert register_kwargs['attr'] == 'register'
        assert register_kwargs['request_method'] == 'POST'
示例#4
0
 def test_policy_params(self, mock_policy):
     from ramses import auth
     auth_model = Mock()
     config = Mock()
     config.registry.auth_model = auth_model
     policy = auth._setup_apikey_policy(config, {'foo': 'bar'})
     mock_policy.assert_called_once_with(
         foo='bar', check=auth_model.get_groups_by_token,
         credentials_callback=auth_model.get_token_credentials,
         user_model=auth_model,
     )
     assert policy == mock_policy()