Beispiel #1
0
 def test07_access_token_handler(self):
     with dummy_app.test_request_context('/a_request'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         response = auth.access_token_handler()
         self.assertEqual( response.status_code, 200 )
         self.assertEqual( response.headers['Content-type'], 'application/json' )
         j = json.loads(response.get_data())
         self.assertEqual( j['error_description'], "No login details received" )
         self.assertEqual( j['error'], "client_unauthorized" )
     # add callback but no account cookie
     with dummy_app.test_request_context('/a_request?callback=CB'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         response = auth.access_token_handler()
         self.assertEqual( response.status_code, 200 )
         self.assertEqual( response.headers['Content-type'], 'application/javascript' )
         # strip JavaScript wrapper and then check JSON
         js = response.get_data()
         self.assertTrue( re.match('CB\(.*\);',js) )
         j = json.loads(js.lstrip('CB(').rstrip(');'))
         self.assertEqual( j['error_description'], "No login details received" )
         self.assertEqual( j['error'], "client_unauthorized" )
     # add an account cookie
     h = Headers()
     h.add('Cookie', 'lol_account=ACCOUNT_TOKEN')
     with dummy_app.test_request_context('/a_request', headers=h):
         auth = IIIFAuthGoogle(client_secret_file=csf, cookie_prefix='lol_')
         response = auth.access_token_handler()
         self.assertEqual( response.status_code, 200 )
         self.assertEqual( response.headers['Content-type'], 'application/json' )
         j = json.loads(response.get_data())
         self.assertEqual( j['access_token'], "ACCOUNT_TOKEN" )
         self.assertEqual( j['token_type'], "Bearer" )
Beispiel #2
0
 def test07_access_token_handler(self):
     """Test access_token_handler method."""
     with dummy_app.test_request_context('/a_request'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.headers['Content-type'],
                          'application/json')
         j = json.loads(response.get_data().decode('utf-8'))
         self.assertEqual(j['description'],
                          "No authorization details received")
         self.assertEqual(j['error'], "client_unauthorized")
     # add callback but no account cookie
     with dummy_app.test_request_context('/a_request?messageId=1234'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.headers['Content-type'], 'text/html')
         # Check HTML is postMessage, includes an error
         html = response.get_data().decode('utf-8')
         self.assertTrue(re.search(r'postMessage\(', html))
         self.assertTrue(re.search(r'"error"', html))
     # add an account cookie
     h = Headers()
     h.add('Cookie', 'lol_account=ACCOUNT_TOKEN')
     with dummy_app.test_request_context('/a_request', headers=h):
         auth = IIIFAuthGoogle(client_secret_file=csf, cookie_prefix='lol_')
         # stub token gen:
         auth._generate_random_string = lambda x: 'lkjhg'
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.headers['Content-type'],
                          'application/json')
         j = json.loads(response.get_data().decode('utf-8'))
         self.assertEqual(j['accessToken'], 'lkjhg')
     # add an account cookie and a messageId
     h = Headers()
     h.add('Cookie', 'lol_account=ACCOUNT_TOKEN')
     with dummy_app.test_request_context('/a_request?messageId=2345',
                                         headers=h):
         auth = IIIFAuthGoogle(client_secret_file=csf, cookie_prefix='lol_')
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.headers['Content-type'], 'text/html')
         # Check HTML is postMessage, includes messageId,
         # does not include an error
         html = response.get_data().decode('utf-8')
         self.assertTrue(re.search(r'postMessage\(', html))
         self.assertTrue(re.search(r'"messageId":\s*"2345"', html))
         self.assertFalse(re.search(r'"error"', html))
Beispiel #3
0
 def test07_access_token_handler(self):
     """Test access_token_handler method."""
     with dummy_app.test_request_context('/a_request'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.headers['Content-type'],
                          'application/json')
         j = json.loads(response.get_data().decode('utf-8'))
         self.assertEqual(j['error_description'],
                          "No login details received")
         self.assertEqual(j['error'], "client_unauthorized")
     # add callback but no account cookie
     with dummy_app.test_request_context('/a_request?callback=CB'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.headers['Content-type'],
                          'application/javascript')
         # strip JavaScript wrapper and then check JSON
         js = response.get_data().decode('utf-8')
         self.assertTrue(re.match('CB\(.*\);', js))
         j = json.loads(js.lstrip('CB(').rstrip(');'))
         self.assertEqual(j['error_description'],
                          "No login details received")
         self.assertEqual(j['error'], "client_unauthorized")
     # add an account cookie
     h = Headers()
     h.add('Cookie', 'lol_account=ACCOUNT_TOKEN')
     with dummy_app.test_request_context('/a_request', headers=h):
         auth = IIIFAuthGoogle(client_secret_file=csf, cookie_prefix='lol_')
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.headers['Content-type'],
                          'application/json')
         j = json.loads(response.get_data().decode('utf-8'))
         self.assertEqual(j['access_token'], "ACCOUNT_TOKEN")
         self.assertEqual(j['token_type'], "Bearer")
Beispiel #4
0
 def test07_access_token_handler(self):
     """Test access_token_handler method."""
     with dummy_app.test_request_context('/a_request'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(
             response.headers['Content-type'],
             'application/json')
         j = json.loads(response.get_data().decode('utf-8'))
         self.assertEqual(
             j['description'],
             "No authorization details received")
         self.assertEqual(j['error'], "client_unauthorized")
     # add callback but no account cookie
     with dummy_app.test_request_context('/a_request?messageId=1234'):
         auth = IIIFAuthGoogle(client_secret_file=csf)
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(
             response.headers['Content-type'],
             'text/html')
         # Check HTML is postMessage, includes an error
         html = response.get_data().decode('utf-8')
         self.assertTrue(re.search(
             r'postMessage\(',
             html))
         self.assertTrue(re.search(
             r'"error"',
             html))
     # add an account cookie
     h = Headers()
     h.add('Cookie', 'lol_account=ACCOUNT_TOKEN')
     with dummy_app.test_request_context('/a_request', headers=h):
         auth = IIIFAuthGoogle(client_secret_file=csf, cookie_prefix='lol_')
         # stub token gen:
         auth._generate_random_string = lambda x: 'lkjhg'
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(
             response.headers['Content-type'],
             'application/json')
         j = json.loads(response.get_data().decode('utf-8'))
         self.assertEqual(j['accessToken'], 'lkjhg')
     # add an account cookie and a messageId
     h = Headers()
     h.add('Cookie', 'lol_account=ACCOUNT_TOKEN')
     with dummy_app.test_request_context('/a_request?messageId=2345', headers=h):
         auth = IIIFAuthGoogle(client_secret_file=csf, cookie_prefix='lol_')
         response = auth.access_token_handler()
         self.assertEqual(response.status_code, 200)
         self.assertEqual(
             response.headers['Content-type'],
             'text/html')
         # Check HTML is postMessage, includes messageId,
         # does not include an error
         html = response.get_data().decode('utf-8')
         self.assertTrue(re.search(
             r'postMessage\(',
             html))
         self.assertTrue(re.search(
             r'"messageId":\s*"2345"',
             html))
         self.assertFalse(re.search(
             r'"error"',
             html))