-
Notifications
You must be signed in to change notification settings - Fork 18
/
test_zmi_logout.py
77 lines (64 loc) · 2.78 KB
/
test_zmi_logout.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
##############################################################################
#
# Copyright (c) 2022 Zope Foundation and Contributors
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this
# distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from Testing.ZopeTestCase import ZopeTestCase
from zope.interface import directlyProvides
from ..interfaces.plugins import ICredentialsResetPlugin
from ..interfaces.plugins import ICredentialsUpdatePlugin
from ..interfaces.plugins import IExtractionPlugin
from .pastc import PASTestCase
from .pastc import user_name
from .pastc import user_password
from .test_PluggableAuthService import DummyCredentialsStore
class PasMixin(object):
def _setupUserFolder(self):
super(PasMixin, self)._setupUserFolder()
pas = self.folder.acl_users
plugins = pas.plugins
creds_store = DummyCredentialsStore('creds')
directlyProvides(creds_store, IExtractionPlugin,
ICredentialsUpdatePlugin, ICredentialsResetPlugin)
pas._setObject('creds', creds_store)
plugins.deactivatePlugin(IExtractionPlugin, 'http_auth')
plugins.activatePlugin(IExtractionPlugin, 'creds')
plugins.activatePlugin(ICredentialsUpdatePlugin, 'creds')
plugins.activatePlugin(ICredentialsResetPlugin, 'creds')
request = self.folder.REQUEST
request["login"] = user_name
creds_store.updateCredentials(
request, request.response, user_name, user_password)
def verify_logout(self):
folder = self.folder
request = folder.REQUEST
return not folder.acl_users.creds.extractCredentials(request)
class ZopeMixin(object):
def verify_logout(self):
response = self.folder.REQUEST.response
return response.getStatus() == 401
class Tests(object):
def test_logout(self):
folder = self.folder
request = folder.REQUEST
folder.manage_zmi_logout(request, request.response)
self.assertTrue(self.verify_logout())
class PasLogoutTests(PasMixin, Tests, PASTestCase):
def test_not_logged_in(self):
from AccessControl.SecurityManagement import noSecurityManager
noSecurityManager()
folder = self.folder
request = folder.REQUEST
self.assertEqual(
folder.manage_zmi_logout(request, request.response),
"You are not/no longer logged in")
class ZopeLogoutTests(ZopeMixin, Tests, ZopeTestCase):
pass