tests: allocate slapd TCP port using bind and SO_REUSEADDR (fixes #31339)
This commit is contained in:
parent
a278da5251
commit
9ff75d0a86
|
@ -63,7 +63,8 @@ def slapd():
|
|||
|
||||
@pytest.fixture
|
||||
def tls_slapd():
|
||||
with Slapd(ldap_url='ldap://localhost.entrouvert.org:4389', tls=(key_file, cert_file)) as s:
|
||||
tcp_port = utils.find_free_tcp_port()
|
||||
with Slapd(ldap_url='ldap://localhost.entrouvert.org:%s' % tcp_port, tls=(key_file, cert_file)) as s:
|
||||
yield create_slapd(s)
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import re
|
||||
import base64
|
||||
from contextlib import contextmanager
|
||||
import socket
|
||||
from contextlib import contextmanager, closing
|
||||
|
||||
from lxml import etree
|
||||
import pytest
|
||||
|
@ -189,3 +190,10 @@ def saml_sp_metadata(base_url):
|
|||
Location="{base_url}/mellon/artifactResponse" />
|
||||
</SPSSODescriptor>
|
||||
</EntityDescriptor>'''.format(base_url=base_url)
|
||||
|
||||
|
||||
def find_free_tcp_port():
|
||||
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
|
||||
s.bind(('', 0))
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
return s.getsockname()[1]
|
||||
|
|
Loading…
Reference in New Issue