Esempio n. 1
0
  def test_get_current_identity_host(self):
    handler.configure([])

    class Handler(handler.AuthenticatingHandler):
      @api.public
      def get(self):
        self.response.write(api.get_current_identity_host() or '<none>')

    app = self.make_test_app('/request', Handler)
    def call(headers):
      api.reset_local_state()
      return app.get('/request', headers=headers).body

    # Good token.
    token = host_token.create_host_token('HOST.domain.com')
    self.assertEqual('host.domain.com', call({'X-Host-Token-V1': token}))

    # Missing or invalid tokens.
    self.assertEqual('<none>', call({}))
    self.assertEqual('<none>', call({'X-Host-Token-V1': 'broken'}))

    # Expired token.
    origin = datetime.datetime(2014, 1, 1, 1, 1, 1)
    self.mock_now(origin)
    token = host_token.create_host_token('HOST.domain.com', expiration_sec=60)
    self.mock_now(origin, 61)
    self.assertEqual('<none>', call({'X-Host-Token-V1': token}))
Esempio n. 2
0
    def test_get_peer_host(self):
        class Handler(handler.AuthenticatingHandler):
            @api.public
            def get(self):
                self.response.write(api.get_peer_host() or '<none>')

        app = self.make_test_app('/request', Handler)

        def call(headers):
            api.reset_local_state()
            return app.get('/request', headers=headers).body

        # Good token.
        token = host_token.create_host_token('HOST.domain.com')
        self.assertEqual('host.domain.com', call({'X-Host-Token-V1': token}))

        # Missing or invalid tokens.
        self.assertEqual('<none>', call({}))
        self.assertEqual('<none>', call({'X-Host-Token-V1': 'broken'}))

        # Expired token.
        origin = datetime.datetime(2014, 1, 1, 1, 1, 1)
        self.mock_now(origin)
        token = host_token.create_host_token('HOST.domain.com',
                                             expiration_sec=60)
        self.mock_now(origin, 61)
        self.assertEqual('<none>', call({'X-Host-Token-V1': token}))
Esempio n. 3
0
 def test_get_peer_host(self):
     """Validates caller host (from X-Host-Token) is stored in auth context."""
     tok = host_token.create_host_token('host-name.domain')
     self.call('127.0.0.1',
               '*****@*****.**',
               headers={'X-Host-Token-V1': tok})
     self.assertEqual('host-name.domain', api.get_peer_host())
Esempio n. 4
0
  def test_validate_host_token_expiration(self):
    origin = datetime.datetime(2014, 1, 1, 1, 1, 1)
    self.mock_now(origin)
    token = host_token.create_host_token('abcd-c4', expiration_sec=60)

    self.mock_now(origin, 59)
    self.assertEqual('abcd-c4', host_token.validate_host_token(token))

    self.mock_now(origin, 61)
    self.assertIsNone(host_token.validate_host_token(token))
Esempio n. 5
0
  def test_validate_host_token_expiration(self):
    origin = datetime.datetime(2014, 1, 1, 1, 1, 1)
    self.mock_now(origin)
    token = host_token.create_host_token('abcd-c4', expiration_sec=60)

    self.mock_now(origin, 59)
    self.assertEqual('abcd-c4', host_token.validate_host_token(token))

    self.mock_now(origin, 61)
    self.assertIsNone(host_token.validate_host_token(token))
Esempio n. 6
0
 def test_validate_host_token_ok(self):
   tok = host_token.create_host_token('abcd-c4')
   self.assertEqual('abcd-c4', host_token.validate_host_token(tok))
Esempio n. 7
0
 def test_create_host_token_fail(self):
   with self.assertRaises(ValueError):
     host_token.create_host_token('.')
Esempio n. 8
0
 def test_validate_host_token_ok(self):
   tok = host_token.create_host_token('abcd-c4')
   self.assertEqual('abcd-c4', host_token.validate_host_token(tok))
Esempio n. 9
0
 def test_create_host_token_fail(self):
   with self.assertRaises(ValueError):
     host_token.create_host_token('.')
Esempio n. 10
0
 def test_get_current_identity_host(self):
   """Validates caller host (from X-Host-Token) is stored in auth context."""
   tok = host_token.create_host_token('host-name.domain')
   self.call('127.0.0.1', '*****@*****.**', headers={'X-Host-Token-V1': tok})
   self.assertEqual('host-name.domain', api.get_current_identity_host())