Esempio n. 1
0
    def testCertCacheControl(self):
        """Test that cache control headers are respected."""
        self.mox.StubOutWithMock(urlfetch, 'fetch')
        tests = [({
            'Cache-Control': 'max-age=3600',
            'Age': '1200'
        }, True), ({
            'Cache-Control': 'max-age=100',
            'Age': '100'
        }, False), ({}, False)]
        for test_headers, value_set in tests:

            class DummyResponse(object):
                status_code = 200
                content = json.dumps(self._SAMPLE_OAUTH_TOKEN_INFO)
                headers = test_headers

            urlfetch.fetch(mox.IsA(basestring)).AndReturn(DummyResponse())
            cache = TestCache()

            self.mox.ReplayAll()
            users_id_token._get_cached_certs('some_uri', cache)
            self.mox.VerifyAll()
            self.mox.ResetAll()

            self.assertEqual(value_set, cache.value_was_set)
  def testCertCacheControl(self, mock_fetch):
    """Test that cache control headers are respected."""
    tests = [({'Cache-Control': 'max-age=3600', 'Age': '1200'}, True),
             ({'Cache-Control': 'max-age=100', 'Age': '100'}, False),
             ({}, False)]
    for test_headers, value_set in tests:

      class DummyResponse(object):
        status_code = 200
        content = json.dumps(self._SAMPLE_OAUTH_TOKEN_INFO)
        headers = test_headers

      mock_fetch.return_value = DummyResponse()
      cache = TestCache()

      users_id_token._get_cached_certs('some_uri', cache)
      mock_fetch.assert_called_once_with('some_uri')
      mock_fetch.reset_mock()

      self.assertEqual(value_set, cache.value_was_set)
Esempio n. 3
0
  def testCertCacheControl(self, mock_fetch):
    """Test that cache control headers are respected."""
    tests = [({'Cache-Control': 'max-age=3600', 'Age': '1200'}, True),
             ({'Cache-Control': 'max-age=100', 'Age': '100'}, False),
             ({}, False)]
    for test_headers, value_set in tests:

      class DummyResponse(object):
        status_code = 200
        content = json.dumps(self._SAMPLE_OAUTH_TOKEN_INFO)
        headers = test_headers

      mock_fetch.return_value = DummyResponse()
      cache = TestCache()

      users_id_token._get_cached_certs('some_uri', cache)
      mock_fetch.assert_called_once_with('some_uri')
      mock_fetch.reset_mock()

      self.assertEqual(value_set, cache.value_was_set)
  def testCertCacheControl(self):
    """Test that cache control headers are respected."""
    self.mox.StubOutWithMock(urlfetch, 'fetch')
    tests = [({'Cache-Control': 'max-age=3600', 'Age': '1200'}, True),
             ({'Cache-Control': 'max-age=100', 'Age': '100'}, False),
             ({}, False)]
    for test_headers, value_set in tests:

      class DummyResponse(object):
        status_code = 200
        content = json.dumps(self._SAMPLE_OAUTH_TOKEN_INFO)
        headers = test_headers

      urlfetch.fetch(mox.IsA(basestring)).AndReturn(DummyResponse())
      cache = TestCache()

      self.mox.ReplayAll()
      users_id_token._get_cached_certs('some_uri', cache)
      self.mox.VerifyAll()
      self.mox.ResetAll()

      self.assertEqual(value_set, cache.value_was_set)