Example #1
0
    def testRunningLocally(self):

        os.environ['SERVER_SOFTWARE'] = 'Google App Engine/whatever'
        self.assertFalse(env_utils.RunningLocally())

        os.environ['SERVER_SOFTWARE'] = 'Development/whatever'
        self.assertTrue(env_utils.RunningLocally())
Example #2
0
def CreateTestEntities(email_addr):
  """Create some test Datastore data if specified, but only if running locally.

  Note that this code doesn't (and shouldn't) delete any existing entities.
  The risk of such code being accidentally triggered in prod is too great, so
  if local entities need to be deleted, use the local Datastore viewer (e.g.
  http://127.0.0.1:8000/datastore).

  Args:
    email_addr: Email address of the local users for whom test data should
        be created.

  Raises:
    NotRunningLocally: if called anywhere other than a local deployment.
  """
  if not env_utils.RunningLocally():
    raise NotRunningLocally

  # Create a user entity with all available roles.
  user = user_models.User.GetOrInsert(email_addr=email_addr)
  user_models.User.SetRoles(email_addr, constants.USER_ROLE.SET_ALL)

  username = user_map.EmailToUsername(email_addr)

  # Create associated SantaHosts for the user.
  santa_hosts = CreateSantaHosts(2, primary_user=username)

  # For each SantaHost, create some SantaEvents.
  for santa_host in santa_hosts:
    for santa_blockable in CreateSantaBlockables(5):

      parent_key = model_utils.ConcatenateKeys(
          user.key, santa_host.key, santa_blockable.key)
      CreateSantaEvent(
          santa_blockable,
          executing_user=username,
          event_type=constants.EVENT_TYPE.BLOCK_BINARY,
          host_id=santa_host.key.id(),
          parent=parent_key)

  # Create associated Bit9Hosts for the user.
  bit9_hosts = CreateBit9Hosts(2, users=[username])

  # For each Bit9Host, create some Bit9Events.
  for bit9_host in bit9_hosts:
    for bit9_binary in CreateBit9Binaries(5):

      parent_key = model_utils.ConcatenateKeys(
          user.key, bit9_host.key, bit9_binary.key)
      CreateBit9Event(
          bit9_binary,
          executing_user=username,
          event_type=constants.EVENT_TYPE.BLOCK_BINARY,
          host_id=bit9_host.key.id(),
          parent=parent_key)
Example #3
0
  def initialize(self, request, response):
    """Initalizes the handler.

    Overriden to set the XSRF cookie.
    Args:
      request: The requst to handle.
      response: The response of the handler.
    """
    super(BaseHandler, self).initialize(request, response)
    # Ensure there is an User associated with the AppEngine user making
    # this request.
    self.user = user_models.User.GetOrInsert()

    # Set the XSRF cookie.
    if self.request and self.response:
      running_locally = env_utils.RunningLocally()
      domain = self.request.host
      if ':' in domain:
        domain = domain.split(':')[0]
      self.response.set_cookie(
          xsrf_utils.ANGULAR_XSRF_COOKIE_NAME, value=xsrf_utils.GenerateToken(),
          domain=domain, secure=(not running_locally))
Example #4
0
 def testLocal(self):
     os.environ['SERVER_SOFTWARE'] = 'Development/whatever'
     self.assertTrue(env_utils.RunningLocally())
Example #5
0
 def testNotLocal(self):
     os.environ['SERVER_SOFTWARE'] = 'Google App Engine/whatever'
     self.assertFalse(env_utils.RunningLocally())