-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
93 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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
TEST_SECRET = "TEST_SECRET" | ||
TEST_TOKEN_NAME = "dcTestToken" | ||
TEST_TOKEN = ('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjQ4NDM1ODY2MDYxNjUs' | ||
'ImlhdCI6MTY4Nzg5MTM2OSwiZW50aXRsZW1lbnRzIjpbXSwiaXNMb2dnZWRJbiI6d' | ||
'HJ1ZSwic3ViIjoidGVzdFVzZXIifQ.vIZag1pHE1YyrxsKKlakXX_44ckAvkg7xWOoA_w4x58') |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from copy import deepcopy | ||
from test.fixtures.apitoken import TEST_TOKEN_NAME, TEST_TOKEN | ||
|
||
POST_EVENT = { | ||
"version": "2.0", | ||
"routeKey": "$default", | ||
"rawPath": "/chat", | ||
"cookies": [ | ||
"cookie_1=cookie_value_1", | ||
"cookie_2=cookie_value_2", | ||
], | ||
"headers": { | ||
"Authorization": f"Bearer {TEST_TOKEN}", | ||
"origin": "https://example.edu" | ||
}, | ||
"queryStringParameters": { | ||
"param1": "value1", | ||
"param2": "value2", | ||
}, | ||
"requestContext": { | ||
"accountId": "123456789012", | ||
"apiId": "api-id", | ||
"domainName": "id.execute-api.us-east-1.amazonaws.com", | ||
"domainPrefix": "id", | ||
"http": { | ||
"method": "POST", | ||
"path": "/chat", | ||
"protocol": "HTTP/1.1", | ||
"sourceIp": "192.168.0.1/32", | ||
"userAgent": "agent" | ||
}, | ||
"requestId": "id", | ||
"routeKey": "$default", | ||
"stage": "$default", | ||
"time": "12/Mar/2020:19:03:58 +0000", | ||
"timeEpoch": 1583348638390 | ||
}, | ||
"body": "UE9TVGVkIENvbnRlbnQ=", | ||
"pathParameters": {}, | ||
"isBase64Encoded": True, | ||
"stageVariables": {} | ||
} | ||
|
||
PLAIN_BODY_EVENT = deepcopy(POST_EVENT) | ||
PLAIN_BODY_EVENT["isBase64Encoded"] = False | ||
PLAIN_BODY_EVENT["body"] = "POSTed Content" | ||
|
||
NO_BODY_EVENT = deepcopy(POST_EVENT) | ||
NO_BODY_EVENT["isBase64Encoded"] = False | ||
NO_BODY_EVENT["body"] = "" | ||
|
||
NO_TOKEN_EVENT = deepcopy(POST_EVENT) | ||
del NO_TOKEN_EVENT["headers"]["Authorization"] | ||
|
||
COOKIE_TOKEN_EVENT = deepcopy(NO_TOKEN_EVENT) | ||
COOKIE_TOKEN_EVENT["cookies"].append(f"{TEST_TOKEN_NAME}={TEST_TOKEN}") |
Empty file.
Empty file.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import os | ||
from src.helpers.apitoken import ApiToken | ||
from test.fixtures.apitoken import TEST_SECRET, TEST_TOKEN | ||
from unittest import mock, TestCase | ||
|
||
@mock.patch.dict( | ||
os.environ, | ||
{ | ||
"API_TOKEN_SECRET": TEST_SECRET | ||
} | ||
) | ||
class TestFunction(TestCase): | ||
def test_empty_token(self): | ||
subject = ApiToken() | ||
self.assertFalse(subject.is_logged_in()) | ||
|
||
def test_valid_token(self): | ||
subject = ApiToken(TEST_TOKEN) | ||
self.assertTrue(subject.is_logged_in()) | ||
|
||
def test_invalid_token(self): | ||
subject = ApiToken("INVALID_TOKEN") | ||
self.assertFalse(subject.is_logged_in()) | ||
|
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