1-
21import os
3- import shlex
42import shutil
5- import subprocess
63import sys
74import unittest
85from unittest .mock import patch
96
10- try :
11- from Pilot . proxyTools import getVO , parseASN1
12- except ModuleNotFoundError :
13- from proxyTools import getVO , parseASN1
7+ sys . path . insert ( 0 , os . getcwd () + "/Pilot" )
8+
9+ from proxyTools import getVO , parseASN1
10+
1411
1512class TestProxyTools (unittest .TestCase ):
1613 def test_getVO (self ):
@@ -23,7 +20,7 @@ def test_getVO(self):
2320 os .remove (cert )
2421 self .assertEqual (vo , "fakevo" )
2522
26- @patch ("Pilot. proxyTools.Popen" )
23+ @patch ("proxyTools.Popen" )
2724 def test_getVOPopenFails (self , popenMock ):
2825 """
2926 Check if an exception is raised when Popen return code is not 0.
@@ -51,7 +48,7 @@ def test_getVOPopenFails(self, popenMock):
5148 getVO (data )
5249 self .assertEqual (str (exc .exception ), msg )
5350
54- @patch ("Pilot. proxyTools.Popen" )
51+ @patch ("proxyTools.Popen" )
5552 def test_parseASN1Fails (self , popenMock ):
5653 """Should raise an exception when Popen return code is !=0"""
5754
@@ -84,46 +81,7 @@ def __createFakeProxy(self, proxyFile):
8481 """
8582 Create a fake proxy locally.
8683 """
87-
8884 basedir = os .path .dirname (__file__ )
89- shutil .copy (basedir + "/certs/user/userkey.pem" , basedir + "/certs/user/userkey400.pem" )
90- os .chmod (basedir + "/certs/user/userkey400.pem" , 0o400 )
91- ret = self .createFakeProxy (
92- basedir + "/certs/user/usercert.pem" ,
93- basedir + "/certs/user/userkey400.pem" ,
94- "fakeserver.cern.ch:15000" ,
95- "fakevo" ,
96- basedir + "/certs//host/hostcert.pem" ,
97- basedir + "/certs/host/hostkey.pem" ,
98- basedir + "/certs/ca" ,
99- proxyFile ,
100- )
101- os .remove (basedir + "/certs/user/userkey400.pem" )
102- return ret
103-
104- def createFakeProxy (self , usercert , userkey , serverURI , vo , hostcert , hostkey , CACertDir , proxyfile ):
105- """
106- voms-proxy-fake --cert usercert.pem
107- --key userkey.pem
108- -rfc
109- -fqan "/fakevo/Role=user/Capability=NULL"
110- -uri fakeserver.cern.ch:15000
111- -voms fakevo
112- -hostcert hostcert.pem
113- -hostkey hostkey.pem
114- -certdir ca
115- """
116- opt = (
117- '--cert %s --key %s -rfc -fqan "/fakevo/Role=user/Capability=NULL" -uri %s -voms %s -hostcert %s'
118- " -hostkey %s -certdir %s -out %s"
119- % (usercert , userkey , serverURI , vo , hostcert , hostkey , CACertDir , proxyfile )
120- )
121- proc = subprocess .Popen (
122- shlex .split ("voms-proxy-fake " + opt ),
123- bufsize = 1 ,
124- stdout = sys .stdout ,
125- stderr = sys .stderr ,
126- universal_newlines = True ,
127- )
128- proc .communicate ()
129- return proc .returncode
85+ shutil .copy (basedir + "/certs/voms/proxy.pem" , proxyFile )
86+ return 0
87+
0 commit comments