mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
fix(accounts): an API token form sent twice makes one token
A double click made two tokens: the second key was shown, the first never, yet it stayed valid until it expired and took a place of the ten. A user's token names are now unique, checked under a lock on the user's row, which also keeps two forms sent at once from passing the limit together. tr and zh too.
This commit is contained in:
parent
be68009432
commit
c290cef21a
6 changed files with 70 additions and 44 deletions
|
|
@ -138,6 +138,14 @@ class ApiTokenTests(TestCase):
|
|||
self.assertNotRegex(response.content.decode(), r"wvc_[0-9a-f]{64}")
|
||||
self.assertIn("at most 10", response.content.decode())
|
||||
|
||||
def test_a_form_sent_twice_makes_one_token(self):
|
||||
self.make("ci")
|
||||
response = self.client.post(reverse("accounts:api_token_create"), {"name": "ci", "days": "90"})
|
||||
self.assertContains(response, "You have a token named ci: choose another name.")
|
||||
self.assertEqual(ApiToken.objects.filter(user=self.user).count(), 1)
|
||||
self.make("ci-2") # another name is fine
|
||||
self.assertEqual(ApiToken.objects.filter(user=self.user).count(), 2)
|
||||
|
||||
def test_expired_tokens_do_not_count_toward_the_limit(self):
|
||||
for number in range(10):
|
||||
self.make(name=f"t{number}")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue