-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'issue/django-setup-configuration-tokens' into issue/dja…
…ngo-setup-configuration-mozilla-django-oidc-db
- Loading branch information
Showing
6 changed files
with
48 additions
and
27 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
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 |
---|---|---|
|
@@ -19,7 +19,33 @@ def test_valid_token(self): | |
) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_invalid_token(self): | ||
def test_valid_token_with_no_spaces(self): | ||
token_auth = TokenAuth.objects.create( | ||
contact_person="contact_person", | ||
email="[email protected]", | ||
identifier="token-1", | ||
token="1234-Token-5678", | ||
) | ||
response = self.client.get( | ||
reverse("v2:objecttype-list"), | ||
HTTP_AUTHORIZATION=f"Token {token_auth.token}", | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_invalid_token_with_spaces(self): | ||
token_auth = TokenAuth.objects.create( | ||
contact_person="contact_person", | ||
email="[email protected]", | ||
identifier="token-1", | ||
token="1234 Token 5678", | ||
) | ||
response = self.client.get( | ||
reverse("v2:objecttype-list"), | ||
HTTP_AUTHORIZATION=f"Token {token_auth.token}", | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
|
||
def test_invalid_token_existing(self): | ||
response = self.client.get( | ||
reverse("v2:objecttype-list"), | ||
HTTP_AUTHORIZATION="Token 1234-Token-5678", | ||
|
@@ -28,7 +54,7 @@ def test_invalid_token(self): | |
|
||
def test_empty_token(self): | ||
response = self.client.get( | ||
reverse("v2:objecttype-list"), HTTP_AUTHORIZATION="Token" | ||
reverse("v2:objecttype-list"), HTTP_AUTHORIZATION="Token " | ||
) | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
|
||
|
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 |
---|---|---|
@@ -1,45 +1,41 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.test import SimpleTestCase | ||
|
||
from objecttypes.token.validators import validate_whitespace | ||
from objecttypes.token.validators import validate_no_whitespace | ||
|
||
|
||
class WhiteSpaceValidatorTestCase(SimpleTestCase): | ||
def test_characters_only(self): | ||
self.assertIsNone(validate_whitespace("test123")) | ||
self.assertIsNone(validate_no_whitespace("test123")) | ||
|
||
def test_trailing_whitespace(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace("test123 ") | ||
validate_no_whitespace("test123 ") | ||
|
||
def test_leading_whitespace(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace(" test123") | ||
validate_no_whitespace(" test123") | ||
|
||
def test_whitespace_in_between(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace("test 123") | ||
validate_no_whitespace("test 123") | ||
|
||
def test_whitespace_only(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace(" ") | ||
validate_no_whitespace(" ") | ||
|
||
def test_trailing_tab_character(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace("test123\t") | ||
validate_no_whitespace("test123\t") | ||
|
||
def test_leading_tab_character(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace("\ttest123") | ||
validate_no_whitespace("\ttest123") | ||
|
||
def test_tab_character_in_between(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace("test\t123") | ||
validate_no_whitespace("test\t123") | ||
|
||
def test_tab_characters_only(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace("\t\t") | ||
|
||
def test_blank_value(self): | ||
with self.assertRaises(ValidationError): | ||
validate_whitespace("") | ||
validate_no_whitespace("\t\t") |
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