-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increased key length maximum size to 128 characters (#138)
- Loading branch information
Showing
4 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
from django.test.utils import override_settings | ||
from ..forms import AUTO_DETECT_CONFIG_KEYWORD | ||
import json | ||
import hashlib | ||
|
||
|
||
class AddTests(SimpleTestCase): | ||
|
@@ -39,6 +40,30 @@ def test_add_invalid_key_status_code(self): | |
response = self.client.get('/add/**invalid-key**') | ||
assert response.status_code == 404 | ||
|
||
def test_key_lengths(self): | ||
""" | ||
Test our key lengths | ||
""" | ||
|
||
# our key to use | ||
h = hashlib.sha512() | ||
h.update(b'string') | ||
key = h.hexdigest() | ||
|
||
# Our limit | ||
assert len(key) == 128 | ||
|
||
# Add our URL | ||
response = self.client.post( | ||
'/add/{}'.format(key), {'urls': 'mailto://user:[email protected]'}) | ||
assert response.status_code == 200 | ||
|
||
# However adding just 1 more character exceeds our limit and the save | ||
# will fail | ||
response = self.client.post( | ||
'/add/{}'.format(key + 'x'), {'urls': 'mailto://user:[email protected]'}) | ||
assert response.status_code == 404 | ||
|
||
@override_settings(APPRISE_CONFIG_LOCK=True) | ||
def test_save_config_by_urls_with_lock(self): | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
from django.test import SimpleTestCase | ||
from django.test.utils import override_settings | ||
from unittest.mock import patch | ||
import hashlib | ||
|
||
|
||
class DelTests(SimpleTestCase): | ||
|
@@ -36,6 +37,36 @@ def test_del_get_invalid_key_status_code(self): | |
response = self.client.get('/del/**invalid-key**') | ||
assert response.status_code == 404 | ||
|
||
def test_key_lengths(self): | ||
""" | ||
Test our key lengths | ||
""" | ||
|
||
# our key to use | ||
h = hashlib.sha512() | ||
h.update(b'string') | ||
key = h.hexdigest() | ||
|
||
# Our limit | ||
assert len(key) == 128 | ||
|
||
# Add our URL | ||
response = self.client.post( | ||
'/add/{}'.format(key), {'urls': 'mailto://user:[email protected]'}) | ||
assert response.status_code == 200 | ||
|
||
# remove a key that is too long | ||
response = self.client.post('/del/{}'.format(key + 'x')) | ||
assert response.status_code == 404 | ||
|
||
# remove the key | ||
response = self.client.post('/del/{}'.format(key)) | ||
assert response.status_code == 200 | ||
|
||
# Test again; key is gone | ||
response = self.client.post('/del/{}'.format(key)) | ||
assert response.status_code == 204 | ||
|
||
@override_settings(APPRISE_CONFIG_LOCK=True) | ||
def test_del_with_lock(self): | ||
""" | ||
|
@@ -77,3 +108,7 @@ def test_del_post(self): | |
# We can now remove the key | ||
response = self.client.post('/del/{}'.format(key)) | ||
assert response.status_code == 200 | ||
|
||
# Key has already been removed | ||
response = self.client.post('/del/{}'.format(key)) | ||
assert response.status_code == 204 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters