Skip to content

Commit 2e526ca

Browse files
committed
Merge pull request zendframework#66 from mbaynton/reconnect
Support for automatic reconnection attempts after server goes away
2 parents 79f055b + f25f183 commit 2e526ca

File tree

13 files changed

+754
-54
lines changed

13 files changed

+754
-54
lines changed

.ci/OpenLDAP/slapd.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Global Directives
33
##
44

5+
idletimeout 30
6+
57
# Schema and objectClass definitions
68
include /etc/ldap/schema/core.schema
79
include /etc/ldap/schema/cosine.schema

.ci/OpenLDAP_run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ echo "Launching OpenLDAP ..."
1616
# Start slapd with non root privileges
1717
slapd -h "ldap://0.0.0.0:3890/ ldaps://0.0.0.0:6360" -f ${DIR}/OpenLDAP/slapd.conf
1818

19+
echo "Launching a PHP built-in webserver on port 3891..."
20+
nohup php -S 0.0.0.0:3891 --docroot ${DIR}/php_scripts 2>&1 > /dev/null &
21+
1922
# Wait for LDAP to start
2023
sleep 2

.ci/config_iptables.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# This sets iptables rules that facilitate targeted dropping of connections for
4+
# the reconnect tests.
5+
6+
iptables-restore <<RULES
7+
# Generated by iptables-save v1.4.21 on Fri Sep 29 15:37:54 2017
8+
*filter
9+
:INPUT ACCEPT [0:0]
10+
:FORWARD ACCEPT [0:0]
11+
:OUTPUT ACCEPT [0:0]
12+
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
13+
-A INPUT -p tcp -m tcp --dport 3891 -j ACCEPT
14+
-A INPUT -p tcp -m tcp --dport 3890 --tcp-flags FIN,SYN,RST,ACK SYN -j ACCEPT
15+
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
16+
-A INPUT -p tcp -j REJECT --reject-with tcp-reset
17+
-A OUTPUT -p tcp -m tcp --sport 22 -j ACCEPT
18+
-A OUTPUT -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK SYN -j ACCEPT
19+
-A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
20+
-A OUTPUT -p tcp -j REJECT --reject-with tcp-reset
21+
COMMIT
22+
# Completed on Fri Sep 29 15:37:54 2017
23+
RULES

.ci/php_scripts/drop_3890.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
/*
3+
* Removes all entries from the kernel TCP state table that are established
4+
* flows to port 3890, the slapd instance. In conjunction with our iptables
5+
* rules, this causes those connections to be dropped.
6+
*
7+
* This is used in reconnect tests.
8+
*/
9+
system('/usr/bin/sudo /usr/sbin/conntrack -D -p tcp --state ESTABLISHED --dport 3890 2>&1');

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
sudo: false
1+
sudo: required
2+
dist: trusty
23

34
language: php
45

@@ -11,6 +12,7 @@ addons:
1112
packages:
1213
- slapd
1314
- ldap-utils
15+
- conntrack
1416

1517
env:
1618
global:
@@ -63,6 +65,7 @@ matrix:
6365

6466
before_install:
6567
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
68+
- sudo .ci/config_iptables.sh
6669

6770
install:
6871
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs

Vagrantfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
$install_ldap = <<SCRIPT
55
export DEBIAN_FRONTEND=noninteractive
66
apt-get -yq update
7-
apt-get -yq --no-install-suggests --no-install-recommends --force-yes install slapd ldap-utils apparmor-utils
7+
apt-get -yq --no-install-suggests --no-install-recommends --force-yes install slapd ldap-utils apparmor-utils conntrack php5-cli
88
sudo aa-complain /usr/sbin/slapd
99
SCRIPT
1010

@@ -21,6 +21,10 @@ Vagrant.configure(2) do |config|
2121
config.vm.network 'forwarded_port', guest: 3890, host: 3890
2222
config.vm.network 'forwarded_port', guest: 6360, host: 6360
2323

24+
# PHP embedded webserver port, running in .ci/php_scripts
25+
config.vm.network 'forwarded_port', guest: 3891, host: 3891
26+
27+
config.vm.provision 'shell', privileged: true, inline: '/vagrant/.ci/config_iptables.sh', :run => 'always'
2428
config.vm.provision 'shell', inline: $install_ldap
2529
config.vm.provision 'shell', privileged: false, inline: '/vagrant/.ci/OpenLDAP_run.sh', :run => 'always'
2630
config.vm.provision 'shell', privileged: false, inline: '/vagrant/.ci/load_fixtures.sh', :run => 'always'

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<env name="TESTS_ZEND_LDAP_ONLINE_ENABLED" value="false" />
5252
<env name="TESTS_ZEND_LDAP_HOST" value="localhost" />
5353
<env name="TESTS_ZEND_LDAP_PORT" value="3890" />
54+
<env name="TESTS_ZEND_LDAP_SCRIPTS_PORT" value="3891" />
5455
<env name="TESTS_ZEND_LDAP_USE_START_TLS" value="false" />
5556
<env name="TESTS_ZEND_LDAP_USE_SSL" value="false" />
5657
<env name="TESTS_ZEND_LDAP_USERNAME" value="cn=Manager,dc=example,dc=com" />

0 commit comments

Comments
 (0)