def test_unauthorized_session(self): p2_session = get_session(self) self.assertRaisesDBusError( "org.freedesktop.DBus.Error.Failed: Cannot generate token: " "Session is not authorized", p2_session.GenerateToken, 0) p2_session.RevokeAuthorization()
def test_foreign_user(self): root_p2_session_path = self.root_p2.GetSession() root_p2_session = get_session(self, self.root_bus, root_p2_session_path) token = root_p2_session.GenerateToken(0) uname = self.root_bus.get_unique_name() self.assertRaisesDBusError( "org.freedesktop.DBus.Error.Failed: Failed to authorize Session: " "No peer session for bus '%s'" % (uname), self.another_p2_session.Authorize, {'problems2.peer-bus': uname, 'problems2.peer-token': token}) self.assertFalse( self.another_p2_session.getproperty("IsAuthorized"), "Foreign session authorized foreign session")
def test_auto_cancel_authorize_request(self): for pkagent_reply in [True, False]: self.logger.debug("Test with reply: %s " % (pkagent_reply)) # Random bus connection which will be closed bus = dbus.SystemBus(private=True) bus.set_exit_on_disconnect(False) with start_polkit_agent(self.root_bus, bus.get_unique_name()) as pk_agent: def close_bus(retval, bus, exp_message, message): self.logger.debug("Killing bus: %s" % (bus.get_unique_name())) bus.close() self.logger.debug("Let abrt-dbus to process " "disconnected client") time.sleep(1) # The loop_counter is incremented before we start waiting # for signal several lines below. The increment is there # because we must be waiting for the signal and also for # Polkit authorization. This call will interrupt the # waiting for signal. self.interrupt_waiting() return retval pk_agent.set_replies([partial(close_bus, pkagent_reply, bus, None)]) p2s = get_session(self, bus) p2s.getobject().connect_to_signal( "AuthorizationChanged", self.handle_authorization_changed) self.logger.debug("Authorizing own session") r = p2s.Authorize(dict()) self.assertEquals(r, 1, "Session is being authorized") self.ac_signal_occurrences = list() # Polkit agent will interrupt waiting. self.loop_counter += 1 # Waiting for signals runs a main loop and the polkit agent # can handle requests only from a main loop. Therefore, this # waiting has two purposes - running main loop and # synchronization with abrt-dbus. self.wait_for_signals(["AuthorizationChanged"]) self.assertEqual(len(self.ac_signal_occurrences), 1, "Session emitted a signal") self.assertEqual(self.ac_signal_occurrences[0], 1, "Authorization request was accepted") self.logger.debug("Going to check Session object") # Give abrt-dbus some time to deal with a disappeared session. time.sleep(1) self.logger.debug("Opening a temporary DBus connection") bus = dbus.SystemBus(private=True) bus.set_exit_on_disconnect(False) p2s = Problems2Session(bus, p2s.getobject().object_path) exception_msg = "org.freedesktop.DBus.Error.UnknownMethod: " \ "No such interface " \ "'org.freedesktop.DBus.Properties' on object " \ "at path {0}".format(p2s.getobject().object_path) self.assertRaisesDBusError(exception_msg, p2s.getproperty, "IsAuthorized") self.logger.debug("Closing the temporary DBus connection") bus.close()