Beispiel #1
0
  def test_request_loader_user_not_registered(self):
    """HTTP400 if user header contains json with unknown user."""
    # imitate no user found
    self.person_mock.query.filter_by.return_value.first.return_value = None

    with self.assertRaises(exceptions.BadRequest):
      login_appengine.request_loader(self.request)
Beispiel #2
0
    def test_request_loader_user_not_registered(self):
        """HTTP400 if user header contains json with unknown user."""
        # imitate no user found
        self.person_mock.query.filter_by.return_value.first.return_value = None

        with self.assertRaises(exceptions.BadRequest):
            login_appengine.request_loader(self.request)
Beispiel #3
0
  def test_request_loader_user_non_dict_json(self):
    """HTTP400 if user header contains json with not a dict."""
    self.request.headers["X-ggrc-user"] = "******"

    with self.assertRaises(exceptions.BadRequest):
      login_appengine.request_loader(self.request)

    self.request.headers["X-ggrc-user"] = "******"

    with self.assertRaises(exceptions.BadRequest):
      login_appengine.request_loader(self.request)
Beispiel #4
0
    def test_request_loader_user_non_dict_json(self):
        """HTTP400 if user header contains json with not a dict."""
        self.request.headers["X-ggrc-user"] = "******"

        with self.assertRaises(exceptions.BadRequest):
            login_appengine.request_loader(self.request)

        self.request.headers["X-ggrc-user"] = "******"

        with self.assertRaises(exceptions.BadRequest):
            login_appengine.request_loader(self.request)
Beispiel #5
0
    def test_request_loader_no_appid_header(self):
        """No app2app auth if Appid header is missing."""
        self.request.headers.pop("X-appengine-inbound-appid")

        result = login_appengine.request_loader(self.request)

        self.assertIs(result, None)
Beispiel #6
0
  def test_request_loader_no_appid_header(self):
    """No app2app auth if Appid header is missing."""
    self.request.headers.pop("X-appengine-inbound-appid")

    result = login_appengine.request_loader(self.request)

    self.assertIs(result, None)
Beispiel #7
0
    def test_request_loader_valid_auth(self):
        """User logged in if Appid and user headers are correct."""
        person = mock.MagicMock()
        self.person_mock.query.filter_by.return_value.first.return_value = person

        result = login_appengine.request_loader(self.request)

        self.assertIs(result, person)
        self.person_mock.query.filter_by.assert_called_with(email=self.EMAIL)
Beispiel #8
0
  def test_request_loader_valid_auth(self):
    """User logged in if Appid and user headers are correct."""
    person = mock.MagicMock()
    self.person_mock.query.filter_by.return_value.first.return_value = person

    result = login_appengine.request_loader(self.request)

    self.assertIs(result, person)
    self.person_mock.query.filter_by.assert_called_with(email=self.EMAIL)
Beispiel #9
0
  def test_request_loader_valid_external_app_user(self):
    """External App User logged in if Appid and user headers are correct."""
    person = mock.MagicMock()
    self.is_ext_user_email_mock.return_value = True
    self.find_or_create_ext_app_user_mock.return_value = person

    result = login_appengine.request_loader(self.request)

    self.assertIs(result, person)
    self.person_mock.query.filter_by.assert_not_called()
    self.is_ext_user_email_mock.assert_called_once_with(self.EMAIL)
Beispiel #10
0
  def test_request_loader_user_not_registered(self):
    """HTTP400 if user header contains json with unknown user."""
    # imitate no user found
    self.person_mock.query.filter_by.return_value.first.return_value = None
    self.is_ext_user_email_mock.return_value = False

    with self.assertRaises(exceptions.BadRequest):
      user = login_appengine.request_loader(self.request)
      print user

    self.is_ext_user_email_mock.assert_called_once_with(self.EMAIL)
Beispiel #11
0
    def test_request_loader_user_not_registered(self):
        """HTTP400 if user header contains json with unknown user."""
        # imitate no user found
        self.person_mock.query.filter_by.return_value.first.return_value = None
        self.is_ext_user_email_mock.return_value = False

        with self.assertRaises(exceptions.BadRequest):
            user = login_appengine.request_loader(self.request)
            print user

        self.is_ext_user_email_mock.assert_called_once_with(self.EMAIL)
Beispiel #12
0
    def test_request_loader_valid_external_app_user(self):
        """External App User logged in if Appid and user headers are correct."""
        person = mock.MagicMock()
        self.is_ext_user_email_mock.return_value = True
        self.find_or_create_ext_app_user_mock.return_value = person

        result = login_appengine.request_loader(self.request)

        self.assertIs(result, person)
        self.person_mock.query.filter_by.assert_not_called()
        self.is_ext_user_email_mock.assert_called_once_with(self.EMAIL)
Beispiel #13
0
  def handle_loaded_user(self, request):
    """Wrapper for request_loader that handles result/exceptions."""
    try:
      user = request_loader(request)
    except Exception as exc:
      self.raised_exception = exc
      raise

    if user:
      self.loaded_email = user.email

    return user
Beispiel #14
0
    def handle_loaded_user(self, request):
        """Wrapper for request_loader that handles result/exceptions."""
        try:
            user = request_loader(request)
        except Exception as exc:
            self.raised_exception = exc
            raise

        if user:
            self.loaded_email = user.email

        return user
Beispiel #15
0
  def test_request_loader_no_user_header(self):
    """HTTP400 if user header is missing."""
    self.request.headers.pop("X-ggrc-user")

    with self.assertRaises(exceptions.BadRequest):
      login_appengine.request_loader(self.request)
Beispiel #16
0
    def test_request_loader_no_user_header(self):
        """HTTP400 if user header is missing."""
        self.request.headers.pop("X-ggrc-user")

        with self.assertRaises(exceptions.BadRequest):
            login_appengine.request_loader(self.request)
Beispiel #17
0
    def test_request_loader_disallowed_appid(self):
        """HTTP400 if Appid header value is not whitelisted."""
        self.request.headers["X-appengine-inbound-appid"] = "disallowed"

        with self.assertRaises(exceptions.BadRequest):
            login_appengine.request_loader(self.request)
Beispiel #18
0
 def test_request_loader_user_non_dict_json(self, header):
   """HTTP400 if user header contains json with not a dict."""
   for value in ("[]", "12"):
     self.request.headers[header] = value
     with self.assertRaises(exceptions.BadRequest):
       login_appengine.request_loader(self.request)
Beispiel #19
0
 def test_request_loader_user_non_dict_json(self, header):
     """HTTP400 if user header contains json with not a dict."""
     for value in ("[]", "12"):
         self.request.headers[header] = value
         with self.assertRaises(exceptions.BadRequest):
             login_appengine.request_loader(self.request)
Beispiel #20
0
    def test_request_loader_user_incomplete_json(self, header):
        """HTTP400 if user header contains json with no email."""
        self.request.headers[header] = "{}"

        with self.assertRaises(exceptions.BadRequest):
            login_appengine.request_loader(self.request)
Beispiel #21
0
    def test_request_loader_user_invalid_json(self, header):
        """HTTP400 if user header contains invalid json."""
        self.request.headers[header] = "not a valid json"

        with self.assertRaises(exceptions.BadRequest):
            login_appengine.request_loader(self.request)
Beispiel #22
0
  def test_request_loader_user_incomplete_json(self):
    """HTTP400 if user header contains json with no email."""
    self.request.headers["X-ggrc-user"] = "******"

    with self.assertRaises(exceptions.BadRequest):
      login_appengine.request_loader(self.request)
Beispiel #23
0
  def test_request_loader_user_invalid_json(self):
    """HTTP400 if user header contains invalid json."""
    self.request.headers["X-ggrc-user"] = "******"

    with self.assertRaises(exceptions.BadRequest):
      login_appengine.request_loader(self.request)
Beispiel #24
0
  def test_request_loader_disallowed_appid(self):
    """HTTP400 if Appid header value is not whitelisted."""
    self.request.headers["X-appengine-inbound-appid"] = "disallowed"

    with self.assertRaises(exceptions.BadRequest):
      login_appengine.request_loader(self.request)