Exemple #1
0
 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 = []
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
 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 = []
Exemple #5
0
 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)
Exemple #6
0
 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)
Exemple #7
0
 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)
Exemple #8
0
 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)