Commit graph

73 commits

Author SHA1 Message Date
Aleksi Häkli
9df4f858ed
Add tests for cool off thresholds
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-03-09 21:49:45 +02:00
Aleksi Häkli
b46e7cce01
Drop Python 3.5 support
Most of our users are already running on Python 3.6+
and dropping 3.5 and below in a future oriented release
allows us to focus on implementing more readable codebases.

Fixes #417

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-03-09 21:49:45 +02:00
Aleksi Häkli
3bece1aaaa
Set Axes request attributes in middleware
Fixes #415

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-03-03 22:13:13 +02:00
Aleksi Häkli
488cd04856
Use LocMemCache in the development setup
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-26 16:49:35 +02:00
Aleksi Häkli
62c9dc73e7
Fix cache test parametrization
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-26 16:39:58 +02:00
Aleksi Häkli
7d9265cd3c
Add check test for missing case branch
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-26 12:45:37 +02:00
Aleksi Häkli
ff6cb8bffd
Move utils to helpers module
In order to offer backwards compatible import path for the
axes.utils.reset function it has to have a separate
implementation that can be imported independently from
the axes.helpers functions that are used by the
AxesBaseHandler implementation.

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-25 22:54:40 +02:00
Aleksi Häkli
8b3c5e7b5a
Refactor cache checks
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-25 21:05:18 +02:00
Aleksi Häkli
677d4c48f4
Improve documentation
- Add information on handlers
- Document configuration options and precedences
- Restructure documentation for better readability

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-25 17:04:03 +02:00
Aleksi Häkli
1ab8d89869
Fix bug in missing cache backends
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-25 16:45:56 +02:00
Aleksi Häkli
13b807d647
Add dummy handler implementation
A handler is always loaded if Axes is active,
and the dummy handler is intended for use when
the user wishes to use either the middleware
or authentication backends but does not want
Axes to handle or emit signals from
authentication events.

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-24 22:37:23 +02:00
Aleksi Häkli
46fc538193
Add cache handler and refactor tests
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-23 20:19:37 +02:00
Aleksi Häkli
ccace29270
Clean up handler naming and documentation
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 20:13:20 +02:00
Aleksi Häkli
42f8c86997
Improve handler design
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:56:05 +02:00
Aleksi Häkli
864bfe3f00
Clean up database handler code and queries
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:56:03 +02:00
Aleksi Häkli
e69d479f6a
Refactor handlers to a more pluggable format
- Define a base handler API with method signatures
- Move proxy handler to a separate path for importability
- Implement a database handler with clean external dependencies
- Change the authentication backend and decorators to use the authentication backend

This enables clean pluggable authentication backend definitions that users
can override and specialize with e.g. cached handlers in their own packages.

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:57 +02:00
Aleksi Häkli
b07a513b30
Cleanup for utils
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:45 +02:00
Aleksi Häkli
a4c4ba6fb7
Refactor utils and attempts internal API
Clean up internal implementations and tests while keeping the
APIs as similar as possible where feasible.

The goal of this change is to not change any documented
or stable APIs that might be in use by users, but to improve
the internal implementations for maintainability and usability.

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:41 +02:00
Aleksi Häkli
bc24d12975
Add support for string type AXES_USERNAME_CALLABLE
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:39 +02:00
Aleksi Häkli
97410a7b06
Clean up old test code
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:37 +02:00
Aleksi Häkli
8b4c522f5b
Rename Axes appconfig startup method to initialize
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:22 +02:00
Aleksi Häkli
d1eb64679b
Add support for reconfiguring handlers in tests
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:17 +02:00
Aleksi Häkli
b120fc6fde
Remove redundant AccessAttempt.failures property
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 19:55:10 +02:00
Aleksi Häkli
5a78d41828
Fix buggy test case and improve test speed
- Cool off time was overly long on a number of test
- Cool off time on test was fetched with the wrong method
  resulting in bugs on non-integer second cool off values

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-22 07:58:28 +02:00
Aleksi Häkli
c17db16253
Use pytest for test runner
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-20 23:05:21 +02:00
Aleksi Häkli
820ecca236
Add missing test case for disabled lockouts
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-13 20:22:16 +02:00
Aleksi Häkli
09fe330957
Fix test compatibility on Python 3.5
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-13 19:02:10 +02:00
Aleksi Häkli
cd56631865
Refactor attempts and add NEVER_LOCKOUT_GET flag
- Move cache and cool off utility functions to the axes.utils module
- Clean up axes.attempts duplicate code in attempt and cache calculations
- Add stable implementation for AccessAttempt attribute calculation
  in the axes.attempts.get_filter_kwargs function

Fixes #398

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-13 18:20:04 +02:00
Aleksi Häkli
42fe9c15fa
Unify import styling to use from ... imports 2019-02-13 14:05:24 +02:00
Aleksi Häkli
911de8f347
Refactor is_user_lockable
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-13 00:58:17 +02:00
Aleksi Häkli
c3e471a211
Improve handler tests 2019-02-13 00:04:50 +02:00
Aleksi Häkli
6240b20793
Clean up utils tests for get_client_username 2019-02-12 23:44:35 +02:00
Aleksi Häkli
40a0eae647
Improve tests
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-12 23:22:52 +02:00
Aleksi Häkli
19f84c5daa
Clean up and unify imports
- Use consistent alphabetical import ordering across files
- Use axes.conf.settings for internally loading settings

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-10 22:06:04 +02:00
Aleksi Häkli
0b6d84762a
Remove deprecated Six usages
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-10 21:47:02 +02:00
Aleksi Häkli
e3e69006a4
Improve management test branch coverage
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-10 20:05:02 +02:00
Aleksi Häkli
fa7f35dda5
Add tests for the new components
Use mocks and test new backends, handlers and middleware
on an API call level, aiming for a 100% coverage on behaviour.

Also add tests for old decorators which are not covered
after moving the default authentication checks from them
to the authentication backends, middleware and signal handlers.

Fixes #323

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-10 19:22:13 +02:00
Aleksi Häkli
5fe339dce6
Rename management tests
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-10 19:22:13 +02:00
Aleksi Häkli
fcef40748a
Deprecate old signature for AXES_USERNAME_CALLABLE and update documentation
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-07 22:09:21 +02:00
Aleksi Häkli
715dedc069
Use PEP257 compliant docstrings
Unify docstring representations based on PEP 257

https://www.python.org/dev/peps/pep-0257/

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-07 18:42:54 +02:00
Aleksi Häkli
30f90ad3bf
Clean up code layouting
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-07 18:42:53 +02:00
Aleksi Häkli
3c2fb2b335
Improve line separator conventions
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-07 18:42:53 +02:00
Aleksi Häkli
ae0c30af29
Remove deprecated JSON testing shims
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-07 17:40:05 +02:00
Aleksi Häkli
030810df79
Drop Python 2.7 and Python 3.4 support
Fixes #395

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-07 17:28:26 +02:00
Aleksi Häkli
ecadddbf5d
Improve management commands, docs, and tests
Fixes #362

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-03 16:03:30 +02:00
Aleksi Häkli
d33a55b927
Use single quotes for strings
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-03 16:03:30 +02:00
Aleksi Häkli
d215485a66
Remove broken JSON login test case
The test did not work correctly because the admin login view
does not accept JSON input, but instead produces an error on JSON POST.

It appeared to be functional and working because the
monkey-patched decorator returned a HTTP 403 when a user was accessing the view.

This did not actually result from a failed login,
but from a premature view permission checking that was not sane.

The HTTP 403 was produced by the login function decorator
before the user was ever accessing or using the actual view.

After modifying the view checking logic to run on a login attempt
instead of before attempt (ie when accessing the view)
the admin view error that resulted from missing form POST data
was discovered and since no easy fix was available without
writing a custom view the broken test case was removed altogether.

The correct fix for supporting JSON payloads and mimetypes
can be implemented by writing a login view that supports
JSON login via eg HTTP AJAX POST and produces the same errors.

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-03 16:03:29 +02:00
Aleksi Häkli
15d2f98980
Clean up database test case imports
Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-03 16:03:29 +02:00
Aleksi Häkli
9c328713e7
Use Django checks for cache configuration
Fixes #383

Signed-off-by: Aleksi Häkli <aleksi.hakli@iki.fi>
2019-02-03 16:03:28 +02:00
Aleksi Häkli
396d99ccc1
Fix tests for Django 2.1
Use HTML comparisons is assertContains instead of
normal text comparisons which can change with rendering.

Fixes #374
2018-12-23 15:52:21 +01:00