mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-26 02:38:48 +02:00
* feat(users): Add support for enabling/disabling Tokens Introduce an `enabled` flag on the `Token` model to allow temporarily revoking API tokens without deleting them. Update forms, serializers, and views to expose the new field. Enforce the `enabled` flag in token authentication. Add model, API, and authentication tests for the new behavior. Fixes #20834 * Fix authentication test --------- Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
@@ -20,6 +20,32 @@ class TokenTest(TestCase):
|
||||
"""
|
||||
cls.user = create_test_user('User 1')
|
||||
|
||||
def test_is_active(self):
|
||||
"""
|
||||
Test the is_active property.
|
||||
"""
|
||||
# Token with enabled status and no expiration date
|
||||
token = Token(user=self.user, enabled=True, expires=None)
|
||||
self.assertTrue(token.is_active)
|
||||
|
||||
# Token with disabled status
|
||||
token.enabled = False
|
||||
self.assertFalse(token.is_active)
|
||||
|
||||
# Token with enabled status and future expiration
|
||||
future_date = timezone.now() + timedelta(days=1)
|
||||
token = Token(user=self.user, enabled=True, expires=future_date)
|
||||
self.assertTrue(token.is_active)
|
||||
|
||||
# Token with past expiration
|
||||
token.expires = timezone.now() - timedelta(days=1)
|
||||
self.assertFalse(token.is_active)
|
||||
|
||||
# Token with disabled status and past expiration
|
||||
past_date = timezone.now() - timedelta(days=1)
|
||||
token = Token(user=self.user, enabled=False, expires=past_date)
|
||||
self.assertFalse(token.is_active)
|
||||
|
||||
def test_is_expired(self):
|
||||
"""
|
||||
Test the is_expired property.
|
||||
|
||||
Reference in New Issue
Block a user