Exemplo n.º 1
0
 def test_ip_whitelist_bot(self):
     """Requests from client in bots IP whitelist are authenticated as bot."""
     model.bootstrap_ip_whitelist(model.bots_ip_whitelist(),
                                  ['192.168.1.100/32'])
     self.assertEqual('bot:whitelisted-ip',
                      self.call('192.168.1.100', None))
     self.assertEqual('anonymous:anonymous', self.call('127.0.0.1', None))
Exemplo n.º 2
0
    def test_ip_whitelisted_bot(self):
        model.bootstrap_ip_whitelist(model.bots_ip_whitelist(),
                                     ['192.168.1.100/32'])

        state, _ = self.call('ipv4:192.168.1.100', None)
        self.assertEqual(
            state,
            CapturedState(
                current_identity='bot:whitelisted-ip',
                is_superuser=False,
                peer_identity='bot:whitelisted-ip',
                peer_ip=ipaddr.ip_from_string('192.168.1.100'),
                delegation_token=None,
            ))

        state, _ = self.call('ipv4:127.0.0.1', None)
        self.assertEqual(
            state,
            CapturedState(
                current_identity='anonymous:anonymous',
                is_superuser=False,
                peer_identity='anonymous:anonymous',
                peer_ip=ipaddr.ip_from_string('127.0.0.1'),
                delegation_token=None,
            ))
Exemplo n.º 3
0
  def test_ip_whitelist_bot_disabled(self):
    """Same as test_ip_whitelist_bot, but IP whitelist auth is disabled."""
    model.bootstrap_ip_whitelist(
        model.bots_ip_whitelist(), ['192.168.1.100/32'])

    class Handler(handler.AuthenticatingHandler):
      use_bots_ip_whitelist = False
      @api.public
      def get(self):
        self.response.write(api.get_current_identity().to_bytes())

    app = self.make_test_app('/request', Handler)
    def call(ip):
      api.reset_local_state()
      return app.get('/request', extra_environ={'REMOTE_ADDR': ip}).body

    self.assertEqual('anonymous:anonymous', call('192.168.1.100'))
Exemplo n.º 4
0
  def test_ip_whitelist_bot(self):
    """Requests from client in bots IP whitelist are authenticated as bot."""
    model.bootstrap_ip_whitelist(
        model.bots_ip_whitelist(), ['192.168.1.100/32'])

    class Handler(handler.AuthenticatingHandler):
      @api.public
      def get(self):
        self.response.write(api.get_current_identity().to_bytes())

    app = self.make_test_app('/request', Handler)
    def call(ip):
      api.reset_local_state()
      return app.get('/request', extra_environ={'REMOTE_ADDR': ip}).body

    self.assertEqual('bot:whitelisted-ip', call('192.168.1.100'))
    self.assertEqual('anonymous:anonymous', call('127.0.0.1'))