Projet

Général

Profil

0001-tests-allocate-slapd-TCP-port-using-bind-and-SO_REUS.patch

Benjamin Dauvergne, 12 mars 2019 21:06

Télécharger (1,55 ko)

Voir les différences:

Subject: [PATCH] tests: allocate slapd TCP port using bind and SO_REUSEADDR
 (fixes #31339)

 tests/test_ldap.py |  3 ++-
 tests/utils.py     | 10 +++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
tests/test_ldap.py
63 63

  
64 64
@pytest.fixture
65 65
def tls_slapd():
66
    with Slapd(ldap_url='ldap://localhost.entrouvert.org:4389', tls=(key_file, cert_file)) as s:
66
    tcp_port = utils.find_free_tcp_port()
67
    with Slapd(ldap_url='ldap://localhost.entrouvert.org:%s' % tcp_port, tls=(key_file, cert_file)) as s:
67 68
        yield create_slapd(s)
68 69

  
69 70

  
tests/utils.py
1 1
import re
2 2
import base64
3
from contextlib import contextmanager
3
import socket
4
from contextlib import contextmanager, closing
4 5

  
5 6
from lxml import etree
6 7
import pytest
......
189 190
     Location="{base_url}/mellon/artifactResponse" />
190 191
 </SPSSODescriptor>
191 192
</EntityDescriptor>'''.format(base_url=base_url)
193

  
194

  
195
def find_free_tcp_port():
196
    with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
197
        s.bind(('', 0))
198
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
199
        return s.getsockname()[1]
192
-