test_request_validator.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # -*- coding: utf-8 -*-
  2. from oauthlib.oauth1 import RequestValidator
  3. from tests.unittest import TestCase
  4. class RequestValidatorTests(TestCase):
  5. def test_not_implemented(self):
  6. v = RequestValidator()
  7. self.assertRaises(NotImplementedError, v.get_client_secret, None, None)
  8. self.assertRaises(NotImplementedError, v.get_request_token_secret,
  9. None, None, None)
  10. self.assertRaises(NotImplementedError, v.get_access_token_secret,
  11. None, None, None)
  12. self.assertRaises(NotImplementedError, lambda: v.dummy_client)
  13. self.assertRaises(NotImplementedError, lambda: v.dummy_request_token)
  14. self.assertRaises(NotImplementedError, lambda: v.dummy_access_token)
  15. self.assertRaises(NotImplementedError, v.get_rsa_key, None, None)
  16. self.assertRaises(NotImplementedError, v.get_default_realms, None, None)
  17. self.assertRaises(NotImplementedError, v.get_realms, None, None)
  18. self.assertRaises(NotImplementedError, v.get_redirect_uri, None, None)
  19. self.assertRaises(NotImplementedError, v.validate_client_key, None, None)
  20. self.assertRaises(NotImplementedError, v.validate_access_token,
  21. None, None, None)
  22. self.assertRaises(NotImplementedError, v.validate_request_token,
  23. None, None, None)
  24. self.assertRaises(NotImplementedError, v.verify_request_token,
  25. None, None)
  26. self.assertRaises(NotImplementedError, v.verify_realms,
  27. None, None, None)
  28. self.assertRaises(NotImplementedError, v.validate_timestamp_and_nonce,
  29. None, None, None, None)
  30. self.assertRaises(NotImplementedError, v.validate_redirect_uri,
  31. None, None, None)
  32. self.assertRaises(NotImplementedError, v.validate_realms,
  33. None, None, None, None, None)
  34. self.assertRaises(NotImplementedError, v.validate_requested_realms,
  35. None, None, None)
  36. self.assertRaises(NotImplementedError, v.validate_verifier,
  37. None, None, None, None)
  38. self.assertRaises(NotImplementedError, v.save_access_token, None, None)
  39. self.assertRaises(NotImplementedError, v.save_request_token, None, None)
  40. self.assertRaises(NotImplementedError, v.save_verifier,
  41. None, None, None)
  42. def test_check_length(self):
  43. v = RequestValidator()
  44. for method in (v.check_client_key, v.check_request_token,
  45. v.check_access_token, v.check_nonce, v.check_verifier):
  46. for not_valid in ('tooshort', 'invalid?characters!',
  47. 'thisclientkeyisalittlebittoolong'):
  48. self.assertFalse(method(not_valid))
  49. for valid in ('itsjustaboutlongenough',):
  50. self.assertTrue(method(valid))
  51. def test_check_realms(self):
  52. v = RequestValidator()
  53. self.assertFalse(v.check_realms(['foo']))
  54. class FooRealmValidator(RequestValidator):
  55. @property
  56. def realms(self):
  57. return ['foo']
  58. v = FooRealmValidator()
  59. self.assertTrue(v.check_realms(['foo']))