-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for Private-Network (#367)
- Loading branch information
1 parent
7ae310c
commit 561ed26
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ..base_test import FlaskCorsTestCase | ||
from flask import Flask | ||
|
||
from flask_cors import * | ||
from flask_cors.core import * | ||
|
||
|
||
class SupportsCredentialsCase(FlaskCorsTestCase): | ||
def setUp(self): | ||
self.app = Flask(__name__) | ||
|
||
@self.app.route('/test_allow_private_network_access_supported') | ||
@cross_origin(allow_private_network=True) | ||
def test_private_network_supported(): | ||
return 'Private network!' | ||
|
||
@self.app.route('/test_allow_private_network_access_unsupported') | ||
@cross_origin(allow_private_network=False) | ||
def test_credentials_unsupported(): | ||
return 'Private network!' | ||
|
||
@self.app.route('/test_default') | ||
@cross_origin() | ||
def test_default(): | ||
return 'Open!' | ||
|
||
def test_credentials_supported(self): | ||
""" The specified route should return the | ||
Access-Control-Allow-Credentials header. | ||
""" | ||
resp = self.get('/test_allow_private_network_access_supported', origin='www.example.com', headers={ACL_REQUEST_HEADER_PRIVATE_NETWORK:'true'}) | ||
self.assertEqual(resp.headers.get(ACL_RESPONSE_PRIVATE_NETWORK), 'true') | ||
|
||
def test_default(self): | ||
""" The default behavior should be to allow private network access. | ||
""" | ||
resp = self.get('/test_default', origin='www.example.com', headers={ACL_REQUEST_HEADER_PRIVATE_NETWORK:'true'}) | ||
self.assertTrue(ACL_RESPONSE_PRIVATE_NETWORK in resp.headers) | ||
|
||
resp = self.get('/test_default') | ||
self.assertFalse(ACL_RESPONSE_PRIVATE_NETWORK in resp.headers) | ||
|
||
def test_credentials_unsupported(self): | ||
""" If private network access is disabled, the header should never be sent.""" | ||
resp = self.get('/test_allow_private_network_access_unsupported', origin='www.example.com') | ||
self.assertFalse(ACL_RESPONSE_PRIVATE_NETWORK in resp.headers) | ||
|
||
resp = self.get('/test_allow_private_network_access_unsupported', origin='www.example.com', headers={ACL_REQUEST_HEADER_PRIVATE_NETWORK:'true'}) | ||
self.assertEqual(resp.headers.get(ACL_RESPONSE_PRIVATE_NETWORK), 'false') | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |