diff options
| author | Matthew Wilkes <git@matthewwilkes.name> | 2016-12-09 11:25:03 +0100 |
|---|---|---|
| committer | Matthew Wilkes <git@matthewwilkes.name> | 2017-04-12 12:14:12 +0100 |
| commit | fe0d223ad08bcab724d216b3a877b690c5795f73 (patch) | |
| tree | abd09e5757cd31856f36c33bfc562f1eb6263c1f | |
| parent | 8f60e2c397a4c781d3ac2dc7fcff9321cdb16a42 (diff) | |
| download | pyramid-fe0d223ad08bcab724d216b3a877b690c5795f73.tar.gz pyramid-fe0d223ad08bcab724d216b3a877b690c5795f73.tar.bz2 pyramid-fe0d223ad08bcab724d216b3a877b690c5795f73.zip | |
Rename implementation to ICSRFStoragePolicy
| -rw-r--r-- | docs/api/interfaces.rst | 2 | ||||
| -rw-r--r-- | docs/narr/security.rst | 2 | ||||
| -rw-r--r-- | pyramid/config/security.py | 6 | ||||
| -rw-r--r-- | pyramid/config/views.py | 2 | ||||
| -rw-r--r-- | pyramid/csrf.py | 18 | ||||
| -rw-r--r-- | pyramid/interfaces.py | 2 | ||||
| -rw-r--r-- | pyramid/tests/test_csrf.py | 8 |
7 files changed, 20 insertions, 20 deletions
diff --git a/docs/api/interfaces.rst b/docs/api/interfaces.rst index b88209a36..e542a6be0 100644 --- a/docs/api/interfaces.rst +++ b/docs/api/interfaces.rst @@ -44,7 +44,7 @@ Other Interfaces .. autointerface:: IRoutePregenerator :members: - .. autointerface:: ICSRFPolicy + .. autointerface:: ICSRFStoragePolicy :members: .. autointerface:: ISession diff --git a/docs/narr/security.rst b/docs/narr/security.rst index 6962a0fe3..04c236e0b 100644 --- a/docs/narr/security.rst +++ b/docs/narr/security.rst @@ -787,7 +787,7 @@ a :term:`session factory` as described in a cookie-based implementation :class:`pyramid.csrf.CookieCSRF` which gives some additional flexibility as it does not require a session for each user. You can also define your own implementation of -:class:`pyramid.interfaces.ICSRFPolicy` and register it with the +:class:`pyramid.interfaces.ICSRFStoragePolicy` and register it with the :meth:`pyramid.config.Configurator.set_default_csrf_options` directive. For example: diff --git a/pyramid/config/security.py b/pyramid/config/security.py index 102a61e0c..c8becce1f 100644 --- a/pyramid/config/security.py +++ b/pyramid/config/security.py @@ -3,7 +3,7 @@ from zope.interface import implementer from pyramid.interfaces import ( IAuthorizationPolicy, IAuthenticationPolicy, - ICSRFPolicy, + ICSRFStoragePolicy, IDefaultCSRFOptions, IDefaultPermission, PHASE1_CONFIG, @@ -181,7 +181,7 @@ class SecurityConfiguratorMixin(object): Set the default CSRF options used by subsequent view registrations. ``implementation`` is a class that implements the - :meth:`pyramid.interfaces.ICSRFPolicy` interface that will be used for all + :meth:`pyramid.interfaces.ICSRFStoragePolicy` interface that will be used for all CSRF functionality. Default: :class:`pyramid.csrf.SessionCSRF`. ``require_csrf`` controls whether CSRF checks will be automatically @@ -220,7 +220,7 @@ class SecurityConfiguratorMixin(object): if implementation is None: implementation = SessionCSRF() def register(): - self.registry.registerUtility(implementation, ICSRFPolicy) + self.registry.registerUtility(implementation, ICSRFStoragePolicy) self.registry.registerUtility(options, IDefaultCSRFOptions) intr = self.introspectable('default csrf view options', None, diff --git a/pyramid/config/views.py b/pyramid/config/views.py index 4ebd014de..e037f7706 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -644,7 +644,7 @@ class ViewsConfiguratorMixin(object): If CSRF checking is performed, the checked value will be the value of ``request.params[check_name]``. This value will be compared against the value of ``policy.get_csrf_token()`` (where ``policy`` is an - implementation of :meth:`pyramid.interfaces.ICSRFPolicy`), and the + implementation of :meth:`pyramid.interfaces.ICSRFStoragePolicy`), and the check will pass if these two values are the same. If the check passes, the associated view will be permitted to execute. If the check fails, the associated view will not be permitted to execute. diff --git a/pyramid/csrf.py b/pyramid/csrf.py index 7adbc9fee..b2788a764 100644 --- a/pyramid/csrf.py +++ b/pyramid/csrf.py @@ -11,7 +11,7 @@ from pyramid.exceptions import ( BadCSRFOrigin, BadCSRFToken, ) -from pyramid.interfaces import ICSRFPolicy +from pyramid.interfaces import ICSRFStoragePolicy from pyramid.settings import aslist from pyramid.util import ( is_same_domain, @@ -19,7 +19,7 @@ from pyramid.util import ( ) -@implementer(ICSRFPolicy) +@implementer(ICSRFStoragePolicy) class SessionCSRF(object): """ The default CSRF implementation, which mimics the behavior from older versions of Pyramid. The ``new_csrf_token`` and ``get_csrf_token`` methods @@ -48,7 +48,7 @@ class SessionCSRF(object): bytes_(supplied_token, 'ascii'), ) -@implementer(ICSRFPolicy) +@implementer(ICSRFStoragePolicy) class CookieCSRF(object): """ An alternative CSRF implementation that stores its information in unauthenticated cookies, known as the 'Double Submit Cookie' method in the @@ -108,7 +108,7 @@ def csrf_token_template_global(event): except AttributeError: return else: - csrf = registry.getUtility(ICSRFPolicy) + csrf = registry.getUtility(ICSRFStoragePolicy) event['get_csrf_token'] = partial(csrf.get_csrf_token, request) @@ -120,7 +120,7 @@ def get_csrf_token(request): .. versionadded :: 1.8a1 """ registry = request.registry - csrf = registry.getUtility(ICSRFPolicy) + csrf = registry.getUtility(ICSRFStoragePolicy) return csrf.get_csrf_token(request) @@ -132,7 +132,7 @@ def new_csrf_token(request): .. versionadded :: 1.8a1 """ registry = request.registry - csrf = registry.getUtility(ICSRFPolicy) + csrf = registry.getUtility(ICSRFStoragePolicy) return csrf.new_csrf_token(request) @@ -141,7 +141,7 @@ def check_csrf_token(request, header='X-CSRF-Token', raises=True): """ Check the CSRF token returned by the - :class:`pyramid.interfaces.ICSRFPolicy` implementation against the value in + :class:`pyramid.interfaces.ICSRFStoragePolicy` implementation against the value in ``request.POST.get(token)`` (if a POST request) or ``request.headers.get(header)``. If a ``token`` keyword is not supplied to this function, the string ``csrf_token`` will be used to look up the token @@ -151,7 +151,7 @@ def check_csrf_token(request, If the value supplied by post or by header doesn't match the value supplied by ``policy.get_csrf_token()`` (where ``policy`` is an implementation of - :class:`pyramid.interfaces.ICSRFPolicy`), and ``raises`` is ``True``, this + :class:`pyramid.interfaces.ICSRFStoragePolicy`), and ``raises`` is ``True``, this function will raise an :exc:`pyramid.exceptions.BadCSRFToken` exception. If the values differ and ``raises`` is ``False``, this function will return ``False``. If the CSRF check is successful, this function will return @@ -184,7 +184,7 @@ def check_csrf_token(request, if supplied_token == "" and token is not None: supplied_token = request.POST.get(token, "") - policy = request.registry.getUtility(ICSRFPolicy) + policy = request.registry.getUtility(ICSRFStoragePolicy) if not policy.check_csrf_token(request, supplied_token): if raises: raise BadCSRFToken('check_csrf_token(): Invalid token') diff --git a/pyramid/interfaces.py b/pyramid/interfaces.py index f58ee8b58..aab5647a1 100644 --- a/pyramid/interfaces.py +++ b/pyramid/interfaces.py @@ -982,7 +982,7 @@ class ISession(IDict): """ -class ICSRFPolicy(Interface): +class ICSRFStoragePolicy(Interface): """ An object that offers the ability to verify CSRF tokens and generate new ones""" diff --git a/pyramid/tests/test_csrf.py b/pyramid/tests/test_csrf.py index 1b3f3fc3b..8866f3601 100644 --- a/pyramid/tests/test_csrf.py +++ b/pyramid/tests/test_csrf.py @@ -117,13 +117,13 @@ class TestSessionCSRF(unittest.TestCase): def test_register_session_csrf_policy(self): from pyramid.csrf import SessionCSRF - from pyramid.interfaces import ICSRFPolicy + from pyramid.interfaces import ICSRFStoragePolicy config = Configurator() config.set_default_csrf_options(implementation=self._makeOne()) config.commit() - policy = config.registry.queryUtility(ICSRFPolicy) + policy = config.registry.queryUtility(ICSRFStoragePolicy) self.assertTrue(isinstance(policy, SessionCSRF)) @@ -163,13 +163,13 @@ class TestCookieCSRF(unittest.TestCase): def test_register_cookie_csrf_policy(self): from pyramid.csrf import CookieCSRF - from pyramid.interfaces import ICSRFPolicy + from pyramid.interfaces import ICSRFStoragePolicy config = Configurator() config.set_default_csrf_options(implementation=self._makeOne()) config.commit() - policy = config.registry.queryUtility(ICSRFPolicy) + policy = config.registry.queryUtility(ICSRFStoragePolicy) self.assertTrue(isinstance(policy, CookieCSRF)) |
