def test_authenticate_with_post_request_and_key_in_param_with_wrong_uid(self):
     '''
     Test auth for post request, auth id in post body, auth with wrong uid. Here uid is not authed, will found None token, auth will failed
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings, method='POST')
     user_key = self._gen_user_key(weibodb)
     request = TestAuthenticate.mock_request('/api/weibo/pub', method='POST', user_key=user_key, params={'uid': 123456, 'did': self.did})
     auth_decorator(func)(request)
     self.assertTrue(not func.called)
 def test_authenticate_with_get_request_and_key_in_param_fail(self):
     '''
     Test auth for get request, auth id in request params, with wrong user_key, will auth fail
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = self._gen_user_key(weibodb) + 'aa'
     request = TestAuthenticate.mock_request('/api/infostream.json', params={'uid': self.uid, 'did': self.did}, user_key=user_key)
     auth_decorator(func)(request)
     self.assertTrue(not func.called)
 def test_authenticate_with_get_request_and_anonymous_user(self):
     '''
     Test auth for anonymous user, with uid, did, user_key all None
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = None
     request = TestAuthenticate.mock_request('/api/infostream.json', user_key=user_key)
     response = auth_decorator(func)(request)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
 def test_authenticate_with_post_request_and_key_in_param_with_did(self):
     '''
     Test auth for post request, auth id in post body, auth with device id
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings, method='POST')
     user_key = self._gen_user_key(weibodb, did=self.did)
     request = TestAuthenticate.mock_request('/api/weibo/pub', method='POST', user_key=user_key, params={'did': self.did})
     response = auth_decorator(func)(request)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
 def test_authenticate_with_get_request_and_key_in_path_with_uid(self):
     '''
     Test auth for get request, user id in request uri, auth with user id
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings, key_pos=1)
     user_key = self._gen_user_key(weibodb)
     request = TestAuthenticate.mock_request('/api/weibolist/%d.json' % self.uid, user_key=user_key)
     response = auth_decorator(func)(request, self.uid)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
Beispiel #6
0
 def test_authenticate_with_get_request_and_anonymous_user(self):
     '''
     Test auth for anonymous user, with uid, did, user_key all None
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = None
     request = TestAuthenticate.mock_request('/api/infostream.json',
                                             user_key=user_key)
     response = auth_decorator(func)(request)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
 def test_authenticate_with_get_request_and_key_in_param_with_uid(self):
     '''
     Test auth for get request and auth id in param, auth with uid. did also in param, but because
     uid is provided, will auth with uid. Here the user is already authed, so token will be found
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = self._gen_user_key(weibodb)
     request = TestAuthenticate.mock_request('/api/infostream.json', params={'uid': self.uid, 'did': self.did}, user_key=user_key)
     response = auth_decorator(func)(request)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
 def test_authenticate_with_get_request_and_key_in_param_with_did(self):
     '''
     Test auth for get request, and auth id in param, auth with did. Here no uid because the user
     is not authed, just auth with did
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = self._gen_user_key(weibodb, did=self.did)
     request = TestAuthenticate.mock_request('/api/infostream.json', params={'did': self.did}, user_key=user_key)
     response = auth_decorator(func)(request)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
 def test_authenticate_with_get_request_and_key_in_param_with_wrong_uid(self):
     '''
     Test auth for get request and auth id in param, auth with uid. did also in param, but because
     uid is provided, will auth with uid. Here the user is not authed, so token will be None, will
     auth failed
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = self._gen_user_key(weibodb)
     request = TestAuthenticate.mock_request('/api/infostream.json', params={'uid': 123456, 'did': self.did}, user_key=user_key)
     auth_decorator(func)(request)
     self.assertTrue(not func.called)
Beispiel #10
0
 def test_authenticate_with_get_request_and_key_in_path_with_uid(self):
     '''
     Test auth for get request, user id in request uri, auth with user id
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings, key_pos=1)
     user_key = self._gen_user_key(weibodb)
     request = TestAuthenticate.mock_request('/api/weibolist/%d.json' %
                                             self.uid,
                                             user_key=user_key)
     response = auth_decorator(func)(request, self.uid)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
Beispiel #11
0
 def test_authenticate_with_post_request_and_key_in_param_with_did(self):
     '''
     Test auth for post request, auth id in post body, auth with device id
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings, method='POST')
     user_key = self._gen_user_key(weibodb, did=self.did)
     request = TestAuthenticate.mock_request('/api/weibo/pub',
                                             method='POST',
                                             user_key=user_key,
                                             params={'did': self.did})
     response = auth_decorator(func)(request)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
Beispiel #12
0
 def test_authenticate_with_get_request_and_key_in_param_with_did(self):
     '''
     Test auth for get request, and auth id in param, auth with did. Here no uid because the user
     is not authed, just auth with did
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = self._gen_user_key(weibodb, did=self.did)
     request = TestAuthenticate.mock_request('/api/infostream.json',
                                             params={'did': self.did},
                                             user_key=user_key)
     response = auth_decorator(func)(request)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
Beispiel #13
0
 def test_authenticate_with_get_request_and_key_in_param_fail(self):
     '''
     Test auth for get request, auth id in request params, with wrong user_key, will auth fail
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = self._gen_user_key(weibodb) + 'aa'
     request = TestAuthenticate.mock_request('/api/infostream.json',
                                             params={
                                                 'uid': self.uid,
                                                 'did': self.did
                                             },
                                             user_key=user_key)
     auth_decorator(func)(request)
     self.assertTrue(not func.called)
Beispiel #14
0
 def test_authenticate_with_get_request_and_key_in_param_with_uid(self):
     '''
     Test auth for get request and auth id in param, auth with uid. did also in param, but because
     uid is provided, will auth with uid. Here the user is already authed, so token will be found
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = self._gen_user_key(weibodb)
     request = TestAuthenticate.mock_request('/api/infostream.json',
                                             params={
                                                 'uid': self.uid,
                                                 'did': self.did
                                             },
                                             user_key=user_key)
     response = auth_decorator(func)(request)
     self.assertTrue(func.called)
     self.assertTrue(type(response) in [dict, list])
Beispiel #15
0
 def test_authenticate_with_post_request_and_key_in_param_with_wrong_uid(
         self):
     '''
     Test auth for post request, auth id in post body, auth with wrong uid. Here uid is not authed, will found None token, auth will failed
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings, method='POST')
     user_key = self._gen_user_key(weibodb)
     request = TestAuthenticate.mock_request('/api/weibo/pub',
                                             method='POST',
                                             user_key=user_key,
                                             params={
                                                 'uid': 123456,
                                                 'did': self.did
                                             })
     auth_decorator(func)(request)
     self.assertTrue(not func.called)
Beispiel #16
0
 def test_authenticate_with_get_request_and_key_in_param_with_wrong_uid(
         self):
     '''
     Test auth for get request and auth id in param, auth with uid. did also in param, but because
     uid is provided, will auth with uid. Here the user is not authed, so token will be None, will
     auth failed
     '''
     self._mock_settings()
     func = MockRequestFunc()
     weibodb = TestAuthenticate.mock_weibodb()
     auth_decorator = authenticate(weibodb, settings)
     user_key = self._gen_user_key(weibodb)
     request = TestAuthenticate.mock_request('/api/infostream.json',
                                             params={
                                                 'uid': 123456,
                                                 'did': self.did
                                             },
                                             user_key=user_key)
     auth_decorator(func)(request)
     self.assertTrue(not func.called)