Skip to content

Commit

Permalink
Changed default proto to http to support chalice local mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Beach committed Jun 24, 2018
1 parent 1416088 commit c4c3391
Showing 1 changed file with 112 additions and 28 deletions.
140 changes: 112 additions & 28 deletions pylti/tests/test_chalice.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ def test_access_to_oauth_resource_unknown_protection(self):
"""
self.localGateway.handle_request(method='GET',
path='/unknown_protection',
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())
self.assertIsInstance(self.get_exception(), LTIException)
Expand All @@ -178,7 +181,10 @@ def test_access_to_oauth_resource_without_authorization_any(self):
"""
self.localGateway.handle_request(method='GET',
path='/any',
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())
self.assertIsInstance(self.get_exception(), LTIException)
Expand All @@ -194,7 +200,10 @@ def test_access_to_oauth_resource_without_authorization_session(self):
"""
self.localGateway.handle_request(method='GET',
path='/session',
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())
self.assertIsInstance(self.get_exception(), LTIException)
Expand All @@ -210,7 +219,10 @@ def test_access_to_oauth_resource_without_authorization_initial_get(self):
"""
self.localGateway.handle_request(method='GET',
path='/initial',
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())
self.assertIsInstance(self.get_exception(), LTIException)
Expand Down Expand Up @@ -263,7 +275,10 @@ def test_access_to_oauth_resource_get(self):
new_url = self.generate_launch_request(consumers, url)
self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())

Expand All @@ -277,7 +292,10 @@ def test_access_to_oauth_resource_post(self):
(path, body) = new_url.split("?")
self.localGateway.handle_request(method='POST',
path=path,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body=body)
self.assertFalse(self.has_exception())

Expand All @@ -294,7 +312,10 @@ def test_access_to_oauth_resource_name_passed(self):
)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())
self.assertEqual(ret['body'], u'person')
Expand All @@ -312,7 +333,10 @@ def test_access_to_oauth_resource_email_passed(self):
)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())
self.assertEqual(ret['body'], u'email@email.com')
Expand All @@ -331,7 +355,10 @@ def test_access_to_oauth_resource_name_and_email_passed(self):
)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())
self.assertEqual(ret['body'], u'person')
Expand All @@ -347,7 +374,10 @@ def test_access_to_oauth_resource_staff_only_as_student(self):
)
self.localGateway.handle_request(method='GET',
path=student_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())

Expand All @@ -356,7 +386,10 @@ def test_access_to_oauth_resource_staff_only_as_student(self):
)
self.localGateway.handle_request(method='GET',
path=learner_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())

Expand All @@ -371,7 +404,10 @@ def test_access_to_oauth_resource_staff_only_as_administrator(self):
)
self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())

Expand All @@ -386,7 +422,10 @@ def test_access_to_oauth_resource_staff_only_as_unknown_role(self):
)
self.localGateway.handle_request(method='GET',
path=admin_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())

Expand All @@ -403,7 +442,10 @@ def test_access_to_oauth_resource_student_as_student(self):
)
self.localGateway.handle_request(method='GET',
path=learner_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())

Expand All @@ -412,7 +454,10 @@ def test_access_to_oauth_resource_student_as_student(self):
)
self.localGateway.handle_request(method='GET',
path=student_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())

Expand All @@ -425,7 +470,10 @@ def test_access_to_oauth_resource_student_as_staff(self):
)
self.localGateway.handle_request(method='GET',
path=staff_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())

Expand All @@ -438,7 +486,10 @@ def test_access_to_oauth_resource_student_as_unknown(self):
)
self.localGateway.handle_request(method='GET',
path=unknown_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())

Expand Down Expand Up @@ -467,7 +518,10 @@ def test_access_to_oauth_resource_initial_norole(self):
new_url = self.generate_launch_request(self.consumers, url, roles=None)
self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())

Expand All @@ -481,7 +535,10 @@ def test_access_to_oauth_resource_any_nonstandard_role(self):
roles=u'ThisIsNotAStandardRole')
self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())

Expand All @@ -495,7 +552,10 @@ def test_access_to_oauth_resource_invalid(self):
bad_url = "{}&FAIL=TRUE".format(new_url)
self.localGateway.handle_request(method='GET',
path=bad_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())
self.assertIsInstance(self.get_exception(), LTIException)
Expand Down Expand Up @@ -540,7 +600,10 @@ def test_access_to_oauth_resource_post_grade(self):
new_url = self.generate_launch_request(consumers, url)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())
self.assertEqual(ret['body'], "grade=True")
Expand All @@ -549,7 +612,10 @@ def test_access_to_oauth_resource_post_grade(self):
new_url = self.generate_launch_request(consumers, url)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())
self.assertEqual(ret['body'], "grade=False")
Expand Down Expand Up @@ -581,7 +647,10 @@ def request_callback(request, cburi, headers):
new_url = self.generate_launch_request(consumers, url)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())
self.assertEqual(ret['body'], "error")
Expand Down Expand Up @@ -631,7 +700,10 @@ def test_access_to_oauth_resource_post_grade2(self):
new_url = self.generate_launch_request(consumers, url)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())
self.assertEqual(ret['body'], "grade=True")
Expand All @@ -640,7 +712,10 @@ def test_access_to_oauth_resource_post_grade2(self):
new_url = self.generate_launch_request(consumers, url)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())
self.assertEqual(ret['body'], "grade=False")
Expand Down Expand Up @@ -670,7 +745,10 @@ def request_callback(request, cburi, headers):
new_url = self.generate_launch_request(consumers, url)
ret = self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertTrue(self.has_exception())
self.assertEqual(ret['body'], "error")
Expand All @@ -683,7 +761,10 @@ def test_default_decorator(self):
new_url = self.generate_launch_request(self.consumers, url)
self.localGateway.handle_request(method='GET',
path=new_url,
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
self.assertFalse(self.has_exception())

Expand All @@ -696,7 +777,10 @@ def test_default_decorator_bad(self):
# pylint: disable=maybe-no-member
ret = self.localGateway.handle_request(method='GET',
path='/default_lti',
headers={'host': 'localhost'},
headers={
'host': 'localhost',
'x-forwarded-proto': 'https'
},
body='')
print(ret)
self.assertEqual(ret['statusCode'], 500)

0 comments on commit c4c3391

Please sign in to comment.