コード例 #1
0
 def test_post_refresh_token(self):
     access_token, refresh_token = self.get_tokens()
     old_token_key = Token.query().get().key
     params = {
         'refresh_token': refresh_token,
         'grant_type': 'refresh_token',
         'client_id': TEST_CLIENT_ID,
         'client_secret': TEST_CLIENT_SECRET,
         'redirect_uri': TEST_REDIRECT_URI,
         'scope': 'data'
     }
     response = self.post(self.url, params)
     self.assertOK(response)
     self.assertEqual(1, Token.query().count())
     token = Token.query().get()
     self.assertNotEqual(token.key, old_token_key)
     self.assertNotEqual(token.access_token, access_token)
     self.assertNotEqual(token.refresh_token, refresh_token)
     self.assertIsNotNone(token)
     self.assertIsNotNone(token.access_token)
     self.assertIsNotNone(token.refresh_token)
     self.assertEqual(token.client_id, TEST_CLIENT_ID)
     self.assertEqual(token.user_key, self.user.key)
     self.assertEqual(token.token_type, 'Bearer')
     self.assertGreater(token.expires_in, 0)
     self.assertFalse(token.is_expired)
     body = json.loads(response.body)
     self.assertLength(4, body)
     self.assertEqual(body['access_token'], token.access_token)
     self.assertEqual(body['refresh_token'], token.refresh_token)
     self.assertEqual(body['token_type'], token.token_type)
     self.assertEqual(body['expires_in'], token.expires_in)
コード例 #2
0
ファイル: test_oauth.py プロジェクト: RubyCoin/mc-coal
 def test_post_refresh_token(self):
     access_token, refresh_token = self.get_tokens()
     old_token_key = Token.query().get().key
     params = {
         'refresh_token': refresh_token,
         'grant_type': 'refresh_token',
         'client_id': TEST_CLIENT_ID,
         'client_secret': TEST_CLIENT_SECRET,
         'redirect_uri': TEST_REDIRECT_URI,
         'scope': 'data'
     }
     response = self.post(self.url, params)
     self.assertOK(response)
     self.assertEqual(1, Token.query().count())
     token = Token.query().get()
     self.assertNotEqual(token.key, old_token_key)
     self.assertNotEqual(token.access_token, access_token)
     self.assertNotEqual(token.refresh_token, refresh_token)
     self.assertIsNotNone(token)
     self.assertIsNotNone(token.access_token)
     self.assertIsNotNone(token.refresh_token)
     self.assertEqual(token.client_id, TEST_CLIENT_ID)
     self.assertEqual(token.user_key, self.user.key)
     self.assertEqual(token.token_type, 'Bearer')
     self.assertGreater(token.expires_in, 0)
     self.assertFalse(token.is_expired)
     body = json.loads(response.body)
     self.assertLength(4, body)
     self.assertEqual(body['access_token'], token.access_token)
     self.assertEqual(body['refresh_token'], token.refresh_token)
     self.assertEqual(body['token_type'], token.token_type)
     self.assertEqual(body['expires_in'], token.expires_in)
コード例 #3
0
ファイル: test_oauth.py プロジェクト: RubyCoin/mc-coal
 def test_post_invalid_refresh_token(self):
     access_token, refresh_token = self.get_tokens()
     old_token_key = Token.query().get().key
     params = {
         'refresh_token': 'invalid_token',
         'grant_type': 'refresh_token',
         'client_id': TEST_CLIENT_ID,
         'client_secret': TEST_CLIENT_SECRET,
         'redirect_uri': TEST_REDIRECT_URI,
         'scope': 'data'
     }
     response = self.post(self.url, params)
     self.assertBadRequest(response)
     self.assertEqual(1, Token.query().count())
     token = Token.query().get()
     self.assertEqual(token.key, old_token_key)
     body = json.loads(response.body)
     self.assertLength(1, body)
     self.assertEqual(body['error'], 'invalid_grant')
コード例 #4
0
 def test_post_invalid_refresh_token(self):
     access_token, refresh_token = self.get_tokens()
     old_token_key = Token.query().get().key
     params = {
         'refresh_token': 'invalid_token',
         'grant_type': 'refresh_token',
         'client_id': TEST_CLIENT_ID,
         'client_secret': TEST_CLIENT_SECRET,
         'redirect_uri': TEST_REDIRECT_URI,
         'scope': 'data'
     }
     response = self.post(self.url, params)
     self.assertBadRequest(response)
     self.assertEqual(1, Token.query().count())
     token = Token.query().get()
     self.assertEqual(token.key, old_token_key)
     body = json.loads(response.body)
     self.assertLength(1, body)
     self.assertEqual(body['error'], 'invalid_grant')
コード例 #5
0
ファイル: test_oauth.py プロジェクト: RubyCoin/mc-coal
 def test_post_invalid(self):
     self.get_authorization_code()
     params = {}
     logging.disable(logging.ERROR)
     response = self.post(self.url, params)
     logging.disable(logging.NOTSET)
     self.assertBadRequest(response)
     self.assertEqual(0, Token.query().count())
     body = json.loads(response.body)
     self.assertLength(1, body)
     self.assertEqual(body['error'], 'invalid_request')
コード例 #6
0
 def test_post_invalid(self):
     self.get_authorization_code()
     params = {}
     logging.disable(logging.ERROR)
     response = self.post(self.url, params)
     logging.disable(logging.NOTSET)
     self.assertBadRequest(response)
     self.assertEqual(0, Token.query().count())
     body = json.loads(response.body)
     self.assertLength(1, body)
     self.assertEqual(body['error'], 'invalid_request')
コード例 #7
0
ファイル: test_oauth.py プロジェクト: RubyCoin/mc-coal
 def test_post_invalid_redirect_uri(self):
     code = self.get_authorization_code()
     params = {
         'code': code,
         'grant_type': 'authorization_code',
         'client_id': TEST_CLIENT_ID,
         'client_secret': TEST_CLIENT_SECRET,
         'redirect_uri': 'http:/invalid.com',
     }
     response = self.post(self.url, params)
     self.assertBadRequest(response)
     self.assertEqual(0, Token.query().count())
     body = json.loads(response.body)
     self.assertLength(1, body)
     self.assertEqual(body['error'], 'invalid_grant')
コード例 #8
0
 def test_post_invalid_redirect_uri(self):
     code = self.get_authorization_code()
     params = {
         'code': code,
         'grant_type': 'authorization_code',
         'client_id': TEST_CLIENT_ID,
         'client_secret': TEST_CLIENT_SECRET,
         'redirect_uri': 'http:/invalid.com',
     }
     response = self.post(self.url, params)
     self.assertBadRequest(response)
     self.assertEqual(0, Token.query().count())
     body = json.loads(response.body)
     self.assertLength(1, body)
     self.assertEqual(body['error'], 'invalid_grant')
コード例 #9
0
ファイル: cron.py プロジェクト: atmasphere/mc-coal
 def get(self):
     now = datetime.datetime.utcnow()
     token_query = Token.query_expired(now)
     for keys in grouper(50, token_query.iter(keys_only=True)):
         ndb.delete_multi_async(keys)
コード例 #10
0
ファイル: cron.py プロジェクト: RubyCoin/mc-coal
 def get(self):
     now = datetime.datetime.utcnow()
     token_query = Token.query_expired(now)
     for keys in grouper(50, token_query.iter(keys_only=True)):
         ndb.delete_multi_async(keys)