|
|
|
@ -173,8 +173,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
flask.session['testing'] = 42 |
|
|
|
|
return 'Hello World' |
|
|
|
|
rv = app.test_client().get('/', 'http://example.com/') |
|
|
|
|
self.assert_true('domain=.example.com' in rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_true('httponly' in rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_in('domain=.example.com', rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_in('httponly', rv.headers['set-cookie'].lower()) |
|
|
|
|
|
|
|
|
|
def test_session_using_server_name_and_port(self): |
|
|
|
|
app = flask.Flask(__name__) |
|
|
|
@ -187,8 +187,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
flask.session['testing'] = 42 |
|
|
|
|
return 'Hello World' |
|
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/') |
|
|
|
|
self.assert_true('domain=.example.com' in rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_true('httponly' in rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_in('domain=.example.com', rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_in('httponly', rv.headers['set-cookie'].lower()) |
|
|
|
|
|
|
|
|
|
def test_session_using_server_name_port_and_path(self): |
|
|
|
|
app = flask.Flask(__name__) |
|
|
|
@ -202,9 +202,9 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
flask.session['testing'] = 42 |
|
|
|
|
return 'Hello World' |
|
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/foo') |
|
|
|
|
self.assert_true('domain=example.com' in rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_true('path=/foo' in rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_true('httponly' in rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_in('domain=example.com', rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_in('path=/foo', rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_in('httponly', rv.headers['set-cookie'].lower()) |
|
|
|
|
|
|
|
|
|
def test_session_using_application_root(self): |
|
|
|
|
class PrefixPathMiddleware(object): |
|
|
|
@ -226,7 +226,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
flask.session['testing'] = 42 |
|
|
|
|
return 'Hello World' |
|
|
|
|
rv = app.test_client().get('/', 'http://example.com:8080/') |
|
|
|
|
self.assert_true('path=/bar' in rv.headers['set-cookie'].lower()) |
|
|
|
|
self.assert_in('path=/bar', rv.headers['set-cookie'].lower()) |
|
|
|
|
|
|
|
|
|
def test_session_using_session_settings(self): |
|
|
|
|
app = flask.Flask(__name__) |
|
|
|
@ -245,10 +245,10 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
return 'Hello World' |
|
|
|
|
rv = app.test_client().get('/', 'http://www.example.com:8080/test/') |
|
|
|
|
cookie = rv.headers['set-cookie'].lower() |
|
|
|
|
self.assert_true('domain=.example.com' in cookie) |
|
|
|
|
self.assert_true('path=/;' in cookie) |
|
|
|
|
self.assert_true('secure' in cookie) |
|
|
|
|
self.assert_true('httponly' not in cookie) |
|
|
|
|
self.assert_in('domain=.example.com', cookie) |
|
|
|
|
self.assert_in('path=/;', cookie) |
|
|
|
|
self.assert_in('secure', cookie) |
|
|
|
|
self.assert_not_in('httponly', cookie) |
|
|
|
|
|
|
|
|
|
def test_missing_session(self): |
|
|
|
|
app = flask.Flask(__name__) |
|
|
|
@ -280,7 +280,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
|
|
|
|
|
client = app.test_client() |
|
|
|
|
rv = client.get('/') |
|
|
|
|
self.assert_true('set-cookie' in rv.headers) |
|
|
|
|
self.assert_in('set-cookie', rv.headers) |
|
|
|
|
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie']) |
|
|
|
|
expires = parse_date(match.group()) |
|
|
|
|
expected = datetime.utcnow() + app.permanent_session_lifetime |
|
|
|
@ -293,7 +293,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
|
|
|
|
|
permanent = False |
|
|
|
|
rv = app.test_client().get('/') |
|
|
|
|
self.assert_true('set-cookie' in rv.headers) |
|
|
|
|
self.assert_in('set-cookie', rv.headers) |
|
|
|
|
match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie']) |
|
|
|
|
self.assert_true(match is None) |
|
|
|
|
|
|
|
|
@ -448,12 +448,12 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
return response |
|
|
|
|
@app.route('/') |
|
|
|
|
def index(): |
|
|
|
|
self.assert_true('before' in evts) |
|
|
|
|
self.assert_true('after' not in evts) |
|
|
|
|
self.assert_in('before', evts) |
|
|
|
|
self.assert_not_in('after', evts) |
|
|
|
|
return 'request' |
|
|
|
|
self.assert_true('after' not in evts) |
|
|
|
|
self.assert_not_in('after', evts) |
|
|
|
|
rv = app.test_client().get('/').data |
|
|
|
|
self.assert_true(b'after' in evts) |
|
|
|
|
self.assert_in(b'after', evts) |
|
|
|
|
self.assert_equal(rv, b'request|after') |
|
|
|
|
|
|
|
|
|
def test_after_request_processing(self): |
|
|
|
@ -483,7 +483,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
return "Response" |
|
|
|
|
rv = app.test_client().get('/') |
|
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
|
self.assert_true(b'Response' in rv.data) |
|
|
|
|
self.assert_in(b'Response', rv.data) |
|
|
|
|
self.assert_equal(len(called), 1) |
|
|
|
|
|
|
|
|
|
def test_teardown_request_handler_debug_mode(self): |
|
|
|
@ -499,7 +499,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
return "Response" |
|
|
|
|
rv = app.test_client().get('/') |
|
|
|
|
self.assert_equal(rv.status_code, 200) |
|
|
|
|
self.assert_true(b'Response' in rv.data) |
|
|
|
|
self.assert_in(b'Response', rv.data) |
|
|
|
|
self.assert_equal(len(called), 1) |
|
|
|
|
|
|
|
|
|
def test_teardown_request_handler_error(self): |
|
|
|
@ -532,7 +532,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
1/0 |
|
|
|
|
rv = app.test_client().get('/') |
|
|
|
|
self.assert_equal(rv.status_code, 500) |
|
|
|
|
self.assert_true(b'Internal Server Error' in rv.data) |
|
|
|
|
self.assert_in(b'Internal Server Error', rv.data) |
|
|
|
|
self.assert_equal(len(called), 2) |
|
|
|
|
|
|
|
|
|
def test_before_after_request_order(self): |
|
|
|
@ -664,8 +664,8 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
try: |
|
|
|
|
c.post('/fail', data={'foo': 'index.txt'}) |
|
|
|
|
except DebugFilesKeyError as e: |
|
|
|
|
self.assert_true('no file contents were transmitted' in str(e)) |
|
|
|
|
self.assert_true('This was submitted: "index.txt"' in str(e)) |
|
|
|
|
self.assert_in('no file contents were transmitted', str(e)) |
|
|
|
|
self.assert_in('This was submitted: "index.txt"', str(e)) |
|
|
|
|
else: |
|
|
|
|
self.fail('Expected exception') |
|
|
|
|
|
|
|
|
@ -974,7 +974,7 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
def broken(): |
|
|
|
|
return 'Meh' |
|
|
|
|
except AssertionError as e: |
|
|
|
|
self.assert_true('A setup function was called' in str(e)) |
|
|
|
|
self.assert_in('A setup function was called', str(e)) |
|
|
|
|
else: |
|
|
|
|
self.fail('Expected exception') |
|
|
|
|
|
|
|
|
@ -1008,9 +1008,9 @@ class BasicFunctionalityTestCase(FlaskTestCase):
|
|
|
|
|
try: |
|
|
|
|
c.post('/foo', data={}) |
|
|
|
|
except AssertionError as e: |
|
|
|
|
self.assert_true('http://localhost/foo/' in str(e)) |
|
|
|
|
self.assert_true('Make sure to directly send your POST-request ' |
|
|
|
|
'to this URL' in str(e)) |
|
|
|
|
self.assert_in('http://localhost/foo/', str(e)) |
|
|
|
|
self.assert_in('Make sure to directly send your POST-request ' |
|
|
|
|
'to this URL', str(e)) |
|
|
|
|
else: |
|
|
|
|
self.fail('Expected exception') |
|
|
|
|
|
|
|
|
|