Exemplo n.º 1
0
 def test_lti_launch_wrong_signature(self):
     """Hopefully gives redirect with state = BAD_AUTH."""
     self.request["oauth_timestamp"] = str(int(time.time()))
     self.request["oauth_nonce"] = oauth2.generate_nonce()
     self.request["user_id"] = "awefd"
     self.request["oauth_signature"] = "1a2f3r"
     request = self.factory.post('http://127.0.0.1:8000/lti/launch',
                                 self.request)
     response = lti_view.lti_launch(request)
     self.assertEquals(response.status_code, 302)
     self.assertIn('state={0}'.format(lti_view.LTI_STATES.BAD_AUTH.value),
                   response.url)
Exemplo n.º 2
0
 def test_lti_launch_no_user_no_info(self):
     """Hopefully gives redirect with state = NO_USER."""
     self.request["oauth_timestamp"] = str(int(time.time()))
     self.request["oauth_nonce"] = oauth2.generate_nonce()
     oauth_request = oauth2.Request.from_request(
         'POST', 'http://testserver/lti/launch', parameters=self.request)
     signature = oauth2.SignatureMethod_HMAC_SHA1().sign(
         oauth_request, self.oauth_consumer, {}).decode('utf-8')
     self.request['oauth_signature'] = signature
     request = self.factory.post('http://127.0.0.1:8000/lti/launch',
                                 self.request)
     response = lti_view.lti_launch(request)
     self.assertEquals(response.status_code, 302)
     self.assertIn('state={0}'.format(lti_view.LTI_STATES.NO_USER.value),
                   response.url)
Exemplo n.º 3
0
def lti_launch(request_body={},
               response_value=lti_view.LTI_STATES.NO_USER.value,
               timestamp=str(int(time.time())),
               nonce=str(oauth2.generate_nonce()),
               status=302,
               assert_msg='',
               delete_field=False):

    request = create_request(request_body, timestamp, nonce, delete_field)
    request = RequestFactory().post('http://127.0.0.1:8000/lti/launch',
                                    request)
    response = lti_view.lti_launch(request)
    assert response.status_code == status
    assert 'state={0}'.format(response_value) in response.url, assert_msg
    return response
Exemplo n.º 4
0
 def test_lti_launch_unknown_role(self):
     """Hopefully gives redirect with state = LOGGED_IN."""
     self.request["oauth_timestamp"] = str(int(time.time()))
     self.request["oauth_nonce"] = oauth2.generate_nonce()
     self.request["user_id"] = "awefd"
     self.request["roles"] = 'urn:lti:instrole:ims/lis/Administrator'
     oauth_request = oauth2.Request.from_request(
         'POST', 'http://testserver/lti/launch', parameters=self.request)
     signature = oauth2.SignatureMethod_HMAC_SHA1().sign(
         oauth_request, self.oauth_consumer, {}).decode('utf-8')
     self.request['oauth_signature'] = signature
     request = self.factory.post('http://127.0.0.1:8000/lti/launch',
                                 self.request)
     response = lti_view.lti_launch(request)
     self.assertEquals(response.status_code, 302)
     self.assertIn('state={0}'.format(lti_view.LTI_STATES.LOGGED_IN.value),
                   response.url)
Exemplo n.º 5
0
 def test_lti_launch_multiple_roles(self):
     """Hopefully gives redirect with state = LOGGED_IN."""
     self.request["oauth_timestamp"] = str(int(time.time()))
     self.request["oauth_nonce"] = oauth2.generate_nonce()
     self.request["user_id"] = "awefd"
     self.request["roles"] = 'Learner,Instructor'
     oauth_request = oauth2.Request.from_request(
         'POST', 'http://testserver/lti/launch', parameters=self.request)
     signature = oauth2.SignatureMethod_HMAC_SHA1().sign(
         oauth_request, self.oauth_consumer, {}).decode('utf-8')
     self.request['oauth_signature'] = signature
     request = self.factory.post('http://127.0.0.1:8000/lti/launch',
                                 self.request)
     response = lti_view.lti_launch(request)
     self.assertEquals(response.status_code, 302)
     self.assertIn('state={0}'.format(lti_view.LTI_STATES.LOGGED_IN.value),
                   response.url)
     self.assertTrue(User.objects.filter(lti_id='awefd')[0].is_teacher)