Exemplo n.º 1
0
  def testGet(self):
    """Test get()."""
    valid_session_name = 'cn_2'
    models.AuthSession(
        key_name='t_1', state='OK',
        mtime=datetime.datetime.fromtimestamp(0)).put()
    models.AuthSession(
        key_name='cn_1', state=None,
        mtime=datetime.datetime.fromtimestamp(0)).put()
    models.AuthSession(
        key_name=valid_session_name, mtime=datetime.datetime.utcnow()).put()
    self.testapp.get('/cron/maintenance/authsession_cleanup')

    taskqueue_stub = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    tasks = taskqueue_stub.get_filtered_tasks()

    for i in range(len(tasks)):
      deferred.run(tasks[i].payload)

    sessions = models.AuthSession.all().fetch(10)

    self.assertEqual(1, len(sessions))
    self.assertEqual(valid_session_name, sessions[0].key().name())
Exemplo n.º 2
0
  def testMultipleRequestsReturnSameToken(self):
    # We don't want change CatalogURL too often.
    testapp = webtest.TestApp(gae_app)

    headers = {
        applesus.MUNKI_CLIENT_ID_HEADER_KEY: 'track=stable|os_version=10.11'}

    ss = models.AuthSession(uuid='34')
    with mock.patch.object(gaeserver, 'DoMunkiAuth', return_value=ss):
      token1 = testapp.post(
          '/applesus/', status=httplib.OK,
          headers=headers).body
      token2 = testapp.post(
          '/applesus/', status=httplib.OK,
          headers=headers).body
    self.assertEqual(token1, token2)
Exemplo n.º 3
0
  def testSupplyClientIdAndTokenInUrl(self):
    testapp = webtest.TestApp(gae_app)

    plist = 'PLIST'
    models.AppleSUSCatalog(key_name='10.11_stable', plist=plist).put()

    headers = {
        applesus.MUNKI_CLIENT_ID_HEADER_KEY: 'track=stable|os_version=10.11'}

    ss = models.AuthSession(uuid='34')
    with mock.patch.object(gaeserver, 'DoMunkiAuth', return_value=ss):
      resp = testapp.post(
          '/applesus/', status=httplib.OK,
          headers=headers)
    resp = testapp.get('/applesus/%s' % resp.body, status=httplib.OK)
    self.assertEqual(plist, resp.body)
Exemplo n.º 4
0
  def _TestExpireOneSession(self, session_prefix, session_age_seconds):
    """Test ExpireOne() with a token session item.

    Args:
      session_prefix: str, like 'foo_'
      session_age_seconds: int, allowable session age data seconds
    """
    session = models.AuthSession(
        mtime=datetime.datetime.utcnow() - datetime.timedelta(
            seconds=session_age_seconds),
        key_name=session_prefix + '123')
    session.put()

    asd = gaeserver.AuthSessionSimianServer()
    self.assertEqual(True, asd.ExpireOne(session))

    self.assertEqual(0, len(models.AuthSession.all().fetch(None)))