def _testUIDGIDSwitch(self, startUID, startGID, wantUID, wantGID, expectedUIDSwitches, expectedGIDSwitches): """ Helper method checking the calls to C{os.seteuid} and C{os.setegid} made by L{util.runAsEffectiveUser}, when switching from startUID to wantUID and from startGID to wantGID. """ self.mockos.euid = startUID self.mockos.egid = startGID util.runAsEffectiveUser(wantUID, wantGID, self._securedFunction, startUID, startGID, wantUID, wantGID) self.assertEquals(self.mockos.seteuidCalls, expectedUIDSwitches) self.assertEquals(self.mockos.setegidCalls, expectedGIDSwitches) self.mockos.seteuidCalls = [] self.mockos.setegidCalls = []
def test_takeParameters(self): """ L{util.runAsEffectiveUser} pass the given parameters to the given function. """ result = util.runAsEffectiveUser(0, 0, lambda x: 2 * x, 3) self.assertEquals(result, 6)
def test_forwardResult(self): """ L{util.runAsEffectiveUser} forwards the result obtained by calling the given function """ result = util.runAsEffectiveUser(0, 0, lambda: 1) self.assertEquals(result, 1)
def _testUIDGIDSwitch(self, startUID, startGID, wantUID, wantGID, expectedUIDSwitches, expectedGIDSwitches): """ Helper method checking the calls to C{os.seteuid} and C{os.setegid} made by L{util.runAsEffectiveUser}, when switching from startUID to wantUID and from startGID to wantGID. """ self.mockos.euid = startUID self.mockos.egid = startGID util.runAsEffectiveUser( wantUID, wantGID, self._securedFunction, startUID, startGID, wantUID, wantGID) self.assertEquals(self.mockos.seteuidCalls, expectedUIDSwitches) self.assertEquals(self.mockos.setegidCalls, expectedGIDSwitches) self.mockos.seteuidCalls = [] self.mockos.setegidCalls = []
def test_takesKeyworkArguments(self): """ L{util.runAsEffectiveUser} pass the keyword parameters to the given function. """ result = util.runAsEffectiveUser(0, 0, lambda x, y=1, z=1: x*y*z, 2, z=3) self.assertEquals(result, 6)
def test_takeParameters(self): """ L{util.runAsEffectiveUser} pass the given parameters to the given function. """ result = util.runAsEffectiveUser(0, 0, lambda x: 2*x, 3) self.assertEquals(result, 6)
def test_takesKeyworkArguments(self): """ L{util.runAsEffectiveUser} pass the keyword parameters to the given function. """ result = util.runAsEffectiveUser(0, 0, lambda x, y=1, z=1: x * y * z, 2, z=3) self.assertEquals(result, 6)