def test_two_tokens(self):
        with authorize_session(self) as p2_session:
            token1 = p2_session.GenerateToken(20)
            token2 = p2_session.GenerateToken(0)
            self.assertNotEqual(token1, token2)

            self.another_p2_session.getobject().connect_to_signal(
                    "AuthorizationChanged", self.handle_authorization_changed)

            ret = self.another_p2_session.Authorize(
                    {'problems2.peer-bus': self.bus.get_unique_name(),
                     'problems2.peer-token': token2})

            self.assertEqual(0, ret, "Authorization passed")
            self.wait_for_signals(["AuthorizationChanged"])
            logging.debug("Authorization via the second token finished")

            self.assertTrue(
                    self.another_p2_session.getproperty("IsAuthorized"),
                    "Token Authorization made Session authorized")

            self.another_p2_session.RevokeAuthorization()
            self.wait_for_signals(["AuthorizationChanged"])

            ret = self.another_p2_session.Authorize(
                    {'problems2.peer-bus': self.bus.get_unique_name(),
                     'problems2.peer-token': token1})

            self.assertEqual(0, ret, "Authorization passed")
            self.wait_for_signals(["AuthorizationChanged"])
            logging.debug("Authorization via the first token finished")
    def test_random_token(self):
        with authorize_session(self) as p2_session:
            self.assertRaisesDBusError(
                "org.freedesktop.DBus.Error.AccessDenied: Failed to authorize Session: "
                "No such token",
                self.another_p2_session.Authorize,
                {'problems2.peer-bus': self.bus.get_unique_name(),
                 'problems2.peer-token': "fooblah"})

            self.assertFalse(
                    self.another_p2_session.getproperty("IsAuthorized"),
                    "Token Authorization made Session authorized")
    def test_random_bus(self):
        with authorize_session(self) as p2_session:
            token = p2_session.GenerateToken(0)

            self.assertRaisesDBusError(
                "org.freedesktop.DBus.Error.Failed: Failed to authorize Session: "
                "No peer session for bus 'fooblah'",
                self.another_p2_session.Authorize,
                {'problems2.peer-bus': "fooblah",
                 'problems2.peer-token': token})

            self.assertFalse(
                    self.another_p2_session.getproperty("IsAuthorized"),
                    "Token Authorization made Session authorized")
    def test_expired_token(self):
        with authorize_session(self) as p2_session:
            token = p2_session.GenerateToken(0)
            time.sleep(6)

            self.assertRaisesDBusError(
                "org.freedesktop.DBus.Error.AccessDenied: Failed to authorize Session: "
                "Token has already expired",
                self.another_p2_session.Authorize,
                {'problems2.peer-bus': self.bus.get_unique_name(),
                 'problems2.peer-token': token})

            self.assertFalse(
                    self.another_p2_session.getproperty("IsAuthorized"),
                    "Token Authorization made Session authorized")
    def test_revoked_authorization_session(self):
        token = None
        with authorize_session(self) as p2_session:
            token = p2_session.GenerateToken(0)

        self.assertRaisesDBusError(
                "org.freedesktop.DBus.Error.AccessDenied: Failed to authorize Session: "
                "Not authorized session cannot pass authorization",
                self.another_p2_session.Authorize,
                {'problems2.peer-bus': self.bus.get_unique_name(),
                 'problems2.peer-token': token})

        self.assertFalse(
                self.another_p2_session.getproperty("IsAuthorized"),
                "Token Authorization with De-authorized Session"
                " made Session authorized")
Exemplo n.º 6
0
    def test_get_foreign_problem(self):
        with authorize_session(self):
            p = self.p2.GetProblems(0, dict())

            self.assertNotEqual(0, len(p), "no problems")
            self.assertIn(self.p2_entry_path, p, "missing our problem")
            self.assertIn(self.p2_entry_root_path, p,
                          "missing private problem")

            p = self.p2.GetProblemData(self.p2_entry_root_path)

            self.assertEqual("0", p["uid"][2], "invalid UID")

            p2_entry = Problems2Entry(self.bus, self.p2_entry_root_path)
            self.assertEqual("Application has been killed",
                             p2_entry.getproperty("Reason"),
                             "Properties are accessible")
Exemplo n.º 7
0
    def test_get_foreign_problem(self):
        with authorize_session(self):
            p = self.p2.GetProblems(0, dict())

            self.assertNotEqual(0, len(p), "no problems")
            self.assertIn(self.p2_entry_path, p, "missing our problem")
            self.assertIn(self.p2_entry_root_path,
                          p,
                          "missing private problem")

            p = self.p2.GetProblemData(self.p2_entry_root_path)

            self.assertEqual("0", p["uid"][2], "invalid UID")

            p2_entry = Problems2Entry(self.bus, self.p2_entry_root_path)
            self.assertEqual("Application has been killed",
                             p2_entry.getproperty("Reason"),
                             "Properties are accessible")
    def test_successful_authorization(self):
        with authorize_session(self) as p2_session:
            token = p2_session.GenerateToken(0)

            self.another_p2_session.getobject().connect_to_signal(
                    "AuthorizationChanged", self.handle_authorization_changed)

            ret = self.another_p2_session.Authorize(
                    {'problems2.peer-bus': self.bus.get_unique_name(),
                     'problems2.peer-token': token})

            self.assertEqual(0, ret,"Authorization passed")
            self.wait_for_signals(["AuthorizationChanged"])

            logging.debug("Signal processing done")

            self.assertTrue(
                    self.another_p2_session.getproperty("IsAuthorized"),
                    "Token Authorization made Session authorized")
Exemplo n.º 9
0
    def test_foreign_crash_signal(self):
        with authorize_session(self) as session:
            uuid, duphash = create_problem(self,
                                           self.root_p2,
                                           bus=self.root_bus,
                                           wait=False)

            self.loop_counter += 1
            self.wait_for_signals(["Crash"])

            self.assertEqual(len(self.crash_signal_occurrences), 2,
                             "Crash signal for root's problem wasn't emitted")

            self.assertEqual(0, self.crash_signal_occurrences[0][1],
                             "Crash signal was emitted with wrong UID")

            self.p2_entry_root_path = self.crash_signal_occurrences[0][0]
            p2e_root = Problems2Entry(self.root_bus, self.p2_entry_root_path)
            self.assertEqual(uuid, p2e_root.getproperty("UUID"))
            self.assertEqual(duphash, p2e_root.getproperty("Duphash"))
Exemplo n.º 10
0
    def test_reused_token(self):
        with authorize_session(self) as p2_session:
            token = p2_session.GenerateToken(0)

            ret = self.another_p2_session.Authorize(
                    {'problems2.peer-bus': self.bus.get_unique_name(),
                     'problems2.peer-token': token})

            self.assertEqual(0, ret, "Authorization succeeded")

            self.assertTrue(
                    self.another_p2_session.getproperty("IsAuthorized"),
                    "Token Authorization made Session authorized")

            self.another_p2_session.RevokeAuthorization()
            self.assertRaisesDBusError(
                "org.freedesktop.DBus.Error.AccessDenied: Failed to authorize Session: "
                "No such token",
                self.another_p2_session.Authorize,
                {'problems2.peer-bus': self.bus.get_unique_name(),
                 'problems2.peer-token': token})
Exemplo n.º 11
0
    def test_foreign_crash_signal(self):
        with authorize_session(self) as session:
            uuid, duphash = create_problem(self,
                                           self.root_p2,
                                           bus=self.root_bus,
                                           wait=False)

            self.loop_counter += 1
            self.wait_for_signals(["Crash"])

            self.assertEqual(len(self.crash_signal_occurrences),
                             2,
                             "Crash signal for root's problem wasn't emitted")

            self.assertEqual(0,
                             self.crash_signal_occurrences[0][1],
                             "Crash signal was emitted with wrong UID")

            self.p2_entry_root_path = self.crash_signal_occurrences[0][0]
            p2e_root = Problems2Entry(self.root_bus, self.p2_entry_root_path)
            self.assertEqual(uuid, p2e_root.getproperty("UUID"))
            self.assertEqual(duphash, p2e_root.getproperty("Duphash"))