예제 #1
0
def get_proxy(request):
    """ Fixture to return either the proxy string.
      It also 'de-import' DIRAC before and after
  """
    # Clean before

    # Oh what a dirty hack....
    # When you do the delegation, you call both Request and Proxy generation fixtures.
    # So if you do the cleaning twice, you end up in a terrible mess.
    # So, do not do the cleaning if you are in the test_delegation method
    if request.function.__name__ != 'test_delegation':
        deimportDIRAC()
    x509Class = request.param

    if x509Class == 'M2_X509Chain':
        from DIRAC.Core.Security.m2crypto.X509Chain import X509Chain
    else:
        raise NotImplementedError()

    def _generateProxy(certFile, lifetime=3600, **kwargs):
        """ Generate the proxyString and return it as an X509Chain object

        :param certFile: path to the certificate
        :param lifetime: lifetime of the proxy in seconds

        :returns:  X509Chain object
    """
        # Load the certificate and the key
        x509Chain = X509Chain()
        x509Chain.loadChainFromFile(certFile)
        x509Chain.loadKeyFromFile(getCertOption(certFile, 'keyFile'))

        # Generate the proxy string
        res = x509Chain.generateProxyToString(lifetime, rfc=True, **kwargs)

        proxyString = res['Value']
        # Load the proxy string as an X509Chain object
        proxyChain = X509Chain()
        proxyChain.loadProxyFromString(proxyString)

        return proxyChain

    yield _generateProxy

    # Clean after
    deimportDIRAC()
예제 #2
0
def get_X509Certificate_class(request):
    """Fixture to return the X509Certificate class.
    It also 'de-import' DIRAC before and after
    """
    # Clean before
    deimportDIRAC()

    x509Class = request.param

    if x509Class == "M2_X509Certificate":
        from DIRAC.Core.Security.m2crypto.X509Certificate import X509Certificate
    else:
        raise NotImplementedError()

    yield X509Certificate

    # Clean after
    deimportDIRAC()