Example #1
0
    def testClosingOneNotificationLeavesAnotherIntact(self):
        with self.ACLChecksDisabled():
            with aff4.FACTORY.Create(
                    aff4.GlobalNotificationStorage.DEFAULT_PATH,
                    aff4_type="GlobalNotificationStorage",
                    mode="rw",
                    token=self.token) as storage:
                storage.AddNotification(
                    aff4_users.GlobalNotification(
                        type=aff4_users.GlobalNotification.Type.ERROR,
                        header="Oh no, we're doomed!",
                        content="Houston, Houston, we have a prob...",
                        link="http://www.google.com"))
                storage.AddNotification(
                    aff4_users.GlobalNotification(
                        type=aff4_users.GlobalNotification.Type.INFO,
                        header="Nothing to worry about!",
                        link="http://www.google.com"))

        self.Open("/")
        self.WaitUntil(self.IsTextPresent,
                       "Houston, Houston, we have a prob...")

        self.Click("css=#global-notification .alert-error button.close")
        self.WaitUntilNot(self.IsTextPresent,
                          "Houston, Houston, we have a prob...")
        self.WaitUntil(self.IsTextPresent, "Nothing to worry about!")

        self.Open("/")
        self.WaitUntil(self.IsTextPresent, "Nothing to worry about!")
        self.assertFalse(
            self.IsTextPresent("Houston, Houston, we have a prob..."))
Example #2
0
    def testNewNotificationReplacesPreviousNotificationOfTheSameType(self):
        with self.ACLChecksDisabled():
            with aff4.FACTORY.Create(
                    aff4.GlobalNotificationStorage.DEFAULT_PATH,
                    aff4_type="GlobalNotificationStorage",
                    mode="rw",
                    token=self.token) as storage:
                storage.AddNotification(
                    aff4_users.GlobalNotification(
                        type=aff4_users.GlobalNotification.Type.ERROR,
                        header="Oh no, we're doomed!",
                        content="Houston, Houston, we have a prob...",
                        link="http://www.google.com"))

        self.Open("/")
        self.WaitUntil(self.IsTextPresent,
                       "Houston, Houston, we have a prob...")

        with self.ACLChecksDisabled():
            with aff4.FACTORY.Create(
                    aff4.GlobalNotificationStorage.DEFAULT_PATH,
                    aff4_type="GlobalNotificationStorage",
                    mode="rw",
                    token=self.token) as storage:
                storage.AddNotification(
                    aff4_users.GlobalNotification(
                        type=aff4_users.GlobalNotification.Type.ERROR,
                        content="Too late to do anything!",
                        link="http://www.google.com"))

        self.Open("/")
        self.WaitUntil(self.IsTextPresent, "Too late to do anything!")
        self.assertFalse(
            self.IsTextPresent("Houston, Houston, we have a prob..."))
Example #3
0
  def Run(self):
    with aff4.FACTORY.Create(aff4_users.GlobalNotificationStorage.DEFAULT_PATH,
                             aff4_type=aff4_users.GlobalNotificationStorage,
                             mode="rw",
                             token=self.token) as storage:
      storage.AddNotification(aff4_users.GlobalNotification(
          type=aff4_users.GlobalNotification.Type.ERROR,
          header="Oh no, we're doomed!",
          content="Houston, Houston, we have a prob...",
          link="http://www.google.com",
          show_from=self.TIME_0))

      storage.AddNotification(aff4_users.GlobalNotification(
          type=aff4_users.GlobalNotification.Type.INFO,
          header="Nothing to worry about!",
          link="http://www.google.com",
          show_from=self.TIME_1))

      storage.AddNotification(aff4_users.GlobalNotification(
          type=aff4_users.GlobalNotification.Type.WARNING,
          header="Nothing to worry, we won't see this!",
          link="http://www.google.com",
          show_from=self.TIME_TOO_EARLY))

    replace = {("%d" % self.TIME_0.AsMicroSecondsFromEpoch()): "0",
               ("%d" % self.TIME_1.AsMicroSecondsFromEpoch()): "0"}

    self.Check("GET",
               "/api/users/me/notifications/pending/global",
               replace=replace)
Example #4
0
    def testGlobalNotificationDisappearsAfterClosing(self):
        with self.ACLChecksDisabled():
            with aff4.FACTORY.Create(
                    aff4.GlobalNotificationStorage.DEFAULT_PATH,
                    aff4_type="GlobalNotificationStorage",
                    mode="rw",
                    token=self.token) as storage:
                storage.AddNotification(
                    aff4_users.GlobalNotification(
                        type=aff4_users.GlobalNotification.Type.ERROR,
                        header="Oh no, we're doomed!",
                        content="Houston, Houston, we have a prob...",
                        link="http://www.google.com"))

        self.Open("/")
        self.WaitUntil(self.IsTextPresent,
                       "Houston, Houston, we have a prob...")

        self.Click("css=#global-notification button.close")
        self.WaitUntilNot(self.IsTextPresent,
                          "Houston, Houston, we have a prob...")

        self.Open("/")
        self.WaitUntil(self.IsElementPresent, "client_query")
        self.WaitUntilNot(self.IsTextPresent,
                          "Houston, Houston, we have a prob...")
Example #5
0
  def setUp(self):
    super(ApiDeletePendingGlobalNotificationHandlerTest, self).setUp()
    self.handler = user_plugin.ApiDeletePendingGlobalNotificationHandler()

    with aff4.FACTORY.Create(aff4_users.GlobalNotificationStorage.DEFAULT_PATH,
                             aff4_type=aff4_users.GlobalNotificationStorage,
                             mode="rw",
                             token=self.token) as storage:
      storage.AddNotification(aff4_users.GlobalNotification(
          type=aff4_users.GlobalNotification.Type.ERROR,
          header="Oh no, we're doomed!",
          content="Houston, Houston, we have a prob...",
          link="http://www.google.com"))
      storage.AddNotification(aff4_users.GlobalNotification(
          type=aff4_users.GlobalNotification.Type.INFO,
          header="Nothing to worry about!",
          link="http://www.google.com"))
  def testNotificationsOfDifferentTypesAreShownTogether(self):
    with aff4.FACTORY.Create(
        aff4_users.GlobalNotificationStorage.DEFAULT_PATH,
        aff4_type=aff4_users.GlobalNotificationStorage,
        mode="rw",
        token=self.token) as storage:
      storage.AddNotification(
          aff4_users.GlobalNotification(
              type=aff4_users.GlobalNotification.Type.ERROR,
              header="Oh no, we're doomed!",
              content="Houston, Houston, we have a prob...",
              link="http://www.google.com"))
      storage.AddNotification(
          aff4_users.GlobalNotification(
              type=aff4_users.GlobalNotification.Type.INFO,
              header="Nothing to worry about!",
              link="http://www.google.com"))

    self.Open("/")
    self.WaitUntil(self.IsTextPresent, "Houston, Houston, we have a prob...")
    self.WaitUntil(self.IsTextPresent, "Nothing to worry about!")
  def testGlobalNotificationIsShownWhenSet(self):
    with aff4.FACTORY.Create(
        aff4_users.GlobalNotificationStorage.DEFAULT_PATH,
        aff4_type=aff4_users.GlobalNotificationStorage,
        mode="rw",
        token=self.token) as storage:
      storage.AddNotification(
          aff4_users.GlobalNotification(
              type=aff4_users.GlobalNotification.Type.ERROR,
              header="Oh no, we're doomed!",
              content="Houston, Houston, we have a prob...",
              link="http://www.google.com"))

    self.Open("/")
    self.WaitUntil(self.IsTextPresent, "Houston, Houston, we have a prob...")
Example #8
0
    def testNotificationIsReturnedWhenItIsSet(self):
        with aff4.FACTORY.Create(users.GlobalNotificationStorage.DEFAULT_PATH,
                                 aff4_type=users.GlobalNotificationStorage,
                                 mode="rw",
                                 token=self.token) as storage:
            storage.AddNotification(
                users.GlobalNotification(
                    type=users.GlobalNotification.Type.ERROR,
                    header="foo",
                    content="bar",
                    link="http://www.google.com"))

        notifications = self.user.GetPendingGlobalNotifications()
        self.assertTrue(notifications)
        self.assertEqual(len(notifications), 1)
        self.assertEqual(notifications[0].header, "foo")
        self.assertEqual(notifications[0].content, "bar")
Example #9
0
    def testNotificationIsNotReturnedWhenItExpires(self):
        with test_lib.FakeTime(100):
            with aff4.FACTORY.Create(
                    users.GlobalNotificationStorage.DEFAULT_PATH,
                    aff4_type=users.GlobalNotificationStorage,
                    mode="rw",
                    token=self.token) as storage:
                storage.AddNotification(
                    users.GlobalNotification(
                        type=users.GlobalNotification.Type.ERROR,
                        header="foo",
                        content="bar",
                        duration=rdfvalue.Duration("1h"),
                    ))

        with test_lib.FakeTime(101):
            notifications = self.user.GetPendingGlobalNotifications()
            self.assertTrue(notifications)

        with test_lib.FakeTime(100 + 3600 + 1):
            notifications = self.user.GetPendingGlobalNotifications()
            self.assertFalse(notifications)
Example #10
0
        artifact_list = flags.FLAGS.artifact
        if not artifact_list:
            raise ValueError("No artifact to delete given.")
        artifact_registry.DeleteArtifactsFromDatastore(artifact_list,
                                                       token=token)
        print "Artifacts %s deleted." % artifact_list

    elif flags.FLAGS.subparser_name == "download_missing_rekall_profiles":
        print "Downloading missing Rekall profiles."
        s = rekall_profile_server.GRRRekallProfileServer()
        s.GetMissingProfiles()

    elif flags.FLAGS.subparser_name == "set_global_notification":
        notification = aff4_users.GlobalNotification(
            type=flags.FLAGS.type,
            header=flags.FLAGS.header,
            content=flags.FLAGS.content,
            link=flags.FLAGS.link)
        if flags.FLAGS.show_from:
            notification.show_from = rdfvalue.RDFDatetime(
            ).ParseFromHumanReadable(flags.FLAGS.show_from)
        if flags.FLAGS.duration:
            notification.duration = rdfvalue.Duration().ParseFromHumanReadable(
                flags.FLAGS.duration)

        print "Setting global notification."
        print notification

        with aff4.FACTORY.Create(
                aff4_users.GlobalNotificationStorage.DEFAULT_PATH,
                aff4_type=aff4_users.GlobalNotificationStorage,