コード例 #1
0
ファイル: test_auth.py プロジェクト: npavan063/ramses
    def test_routes_views_added(self, mock_policy):
        from ramses import auth
        config = Mock()
        config.registry.settings = {'my_secret': 12345}
        config.registry.auth_model = Mock()
        root = Mock()
        config.get_root_resource.return_value = root
        auth._setup_ticket_policy(
            config=config, params={'secret': 'my_secret'})
        assert root.add.call_count == 3
        login, logout, register = root.add.call_args_list
        login_kwargs = login[1]
        assert sorted(login_kwargs.keys()) == sorted([
            'view', 'prefix', 'factory'])
        assert login_kwargs['prefix'] == 'auth'
        assert login_kwargs['factory'] == 'nefertari.acl.AuthenticationACL'

        logout_kwargs = logout[1]
        assert sorted(logout_kwargs.keys()) == sorted([
            'view', 'prefix', 'factory'])
        assert logout_kwargs['prefix'] == 'auth'
        assert logout_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
        config = Mock()
        config.registry.settings = {'my_secret': 12345}
        config.registry.auth_model = Mock()
        root = Mock()
        config.get_root_resource.return_value = root
        auth._setup_ticket_policy(config=config,
                                  params={'secret': 'my_secret'})
        assert root.add.call_count == 3
        login, logout, register = root.add.call_args_list
        login_kwargs = login[1]
        assert sorted(login_kwargs.keys()) == sorted(
            ['view', 'prefix', 'factory'])
        assert login_kwargs['prefix'] == 'auth'
        assert login_kwargs['factory'] == 'nefertari.acl.AuthenticationACL'

        logout_kwargs = logout[1]
        assert sorted(logout_kwargs.keys()) == sorted(
            ['view', 'prefix', 'factory'])
        assert logout_kwargs['prefix'] == 'auth'
        assert logout_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
ファイル: test_auth.py プロジェクト: mjhea0/ramses
    def test_routes_views_added(self, mock_policy):
        from ramses import auth
        config = Mock()
        config.registry.settings = {'my_secret': 12345}
        config.registry.auth_model = Mock()
        auth._setup_ticket_policy(
            config=config, params={'secret': 'my_secret'})
        config.add_route.assert_has_calls([
            call('login', '/auth/login'),
            call('logout', '/auth/logout'),
            call('register', '/auth/register'),
        ])
        login, logout, register = config.add_view.call_args_list
        login_kwargs = login[1]
        assert sorted(login_kwargs.keys()) == sorted([
            'request_method', 'view', 'route_name', 'attr'])
        assert login_kwargs['route_name'] == 'login'
        assert login_kwargs['attr'] == 'login'
        assert login_kwargs['request_method'] == 'POST'

        logout_kwargs = logout[1]
        assert sorted(logout_kwargs.keys()) == sorted([
            'view', 'route_name', 'attr'])
        assert logout_kwargs['route_name'] == 'logout'
        assert logout_kwargs['attr'] == 'logout'

        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
ファイル: test_auth.py プロジェクト: atteeela/ramses
 def test_request_method_added(self, mock_policy):
     from ramses import auth
     config = Mock()
     config.registry.settings = {'my_secret': 12345}
     config.registry.auth_model = Mock()
     policy = auth._setup_ticket_policy(
         config=config, params={'secret': 'my_secret'})
     config.add_request_method.assert_called_once_with(
         config.registry.auth_model.get_authuser_by_userid,
         'user', reify=True)
     assert policy == mock_policy()
コード例 #5
0
 def test_params_converted(self, mock_policy):
     from ramses import auth
     params = dictset(
         secure=True,
         include_ip=True,
         http_only=False,
         wild_domain=True,
         debug=True,
         parent_domain=True,
         secret='my_secret_setting'
     )
     auth_model = Mock()
     config = Mock()
     config.registry.settings = {'my_secret_setting': 12345}
     config.registry.auth_model = auth_model
     auth._setup_ticket_policy(config=config, params=params)
     assert_called_with_at_least(mock_policy,
                                 include_ip=True, secure=True, parent_domain=True, secret=12345,
                                 wild_domain=True, debug=True, http_only=False
                                 )
コード例 #6
0
ファイル: test_auth.py プロジェクト: npavan063/ramses
 def test_params_converted(self, mock_policy):
     from ramses import auth
     params = dictset(
         secure=True,
         include_ip=True,
         http_only=False,
         wild_domain=True,
         debug=True,
         parent_domain=True,
         secret='my_secret_setting'
     )
     auth_model = Mock()
     config = Mock()
     config.registry.settings = {'my_secret_setting': 12345}
     config.registry.auth_model = auth_model
     auth._setup_ticket_policy(config=config, params=params)
     mock_policy.assert_called_once_with(
         include_ip=True, secure=True, parent_domain=True,
         callback=auth_model.get_groups_by_userid, secret=12345,
         wild_domain=True, debug=True, http_only=False
     )
コード例 #7
0
 def test_no_secret(self):
     from ramses import auth
     with pytest.raises(ValueError) as ex:
         auth._setup_ticket_policy(config='', params={})
     expected = 'Missing required security scheme settings: secret'
     assert expected == str(ex.value)
コード例 #8
0
ファイル: test_auth.py プロジェクト: npavan063/ramses
 def test_no_secret(self):
     from ramses import auth
     with pytest.raises(ValueError) as ex:
         auth._setup_ticket_policy(config='', params={})
     expected = 'Missing required security scheme settings: secret'
     assert expected == str(ex.value)