Skip to content

Commit 07f6218

Browse files
committed
Added/Updated tests\bugs\core_5229_test.py: Added check for ability to use IPv6. See notes.
1 parent 393143d commit 07f6218

File tree

1 file changed

+81
-36
lines changed

1 file changed

+81
-36
lines changed

tests/bugs/core_5229_test.py

Lines changed: 81 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,93 @@
22

33
"""
44
ID: issue-5508
5-
ISSUE: 5508
5+
ISSUE: https://github.com/FirebirdSQL/firebird/issues/5508
66
TITLE: Allow to enforce IPv4 or IPv6 in URL-like connection strings
77
DESCRIPTION:
8-
NOTES:
9-
[04.02.2022] pcisar
10-
Test may fail with IPv6.
11-
For example it fails on my Linux OpenSuSE Tumbleweed with regular setup (IPv6 should not be disabled).
12-
Test should IMHO check IPv4/IPv6 availability on test host before runs inet6:// check.
138
JIRA: CORE-5229
149
FBTEST: bugs.core_5229
15-
"""
10+
NOTES:
11+
[04.02.2022] pcisar
12+
Test may fail with IPv6.
13+
For example it fails on my Linux OpenSuSE Tumbleweed with regular setup (IPv6 should not be disabled).
14+
Test should IMHO check IPv4/IPv6 availability on test host before runs inet6:// check.
15+
[13.06.2024] pzotov
16+
1. Added check for ability to use IPv6.
17+
2. Attempt to specify explicitly IPv6 address "[::1]" in ES/EDS causes error:
18+
========
19+
Statement failed, SQLSTATE = 42000
20+
External Data Source provider 'inet6://[' not found
21+
========
22+
Sent report to Vlad et al, waiting for fix.
23+
Currently no concrete address is specified in ES/EDS.
1624
25+
Checked on 3.0.12.33744, 4.0.5.3103, 5.0.1.1411, 6.0.0.368
26+
"""
1727
import pytest
1828
from firebird.qa import *
1929

2030
db = db_factory()
2131

2232
act = python_act('db')
2333

24-
expected_stdout = """
25-
PROCOTOL_WHEN_CONNECT_FROM_OS TCPv4
26-
PROCOTOL_WHEN_CONNECT_FROM_ISQL TCPv4
27-
PROTOCOL_WHEN_CONNECT_BY_ES_EDS TCPv4
28-
PROCOTOL_WHEN_CONNECT_FROM_ISQL TCPv6
29-
PROTOCOL_WHEN_CONNECT_BY_ES_EDS TCPv6
30-
"""
34+
#------------------------------------------
35+
# https://stackoverflow.com/questions/66246308/detect-if-ipv6-is-supported-os-agnostic-no-external-program/66249915#66249915
36+
# https://stackoverflow.com/a/66249915
37+
38+
def check_ipv6_avail():
39+
import socket
40+
import errno
41+
42+
# On Windows, the E* constants will use the WSAE* values
43+
# So no need to hardcode an opaque integer in the sets.
44+
_ADDR_NOT_AVAIL = {errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT}
45+
_ADDR_IN_USE = {errno.EADDRINUSE}
46+
47+
res = -1
48+
if not socket.has_ipv6:
49+
# If the socket library has no support for IPv6, then the
50+
# question is moot as we can't use IPv6 anyways.
51+
return res
52+
53+
sock = None
54+
try:
55+
#with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as sock:
56+
# sock.bind(("::1", 0))
57+
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
58+
sock.bind(("::1", 0))
59+
#sock.shutdown(socket.SHUT_RDWR) # [Errno 107] Transport endpoint is not connected
60+
sock.close()
61+
res = 0
62+
except socket.error as x:
63+
# sysctl net.ipv6.conf.all.disable_ipv6=1
64+
# sysctl net.ipv6.conf.default.disable_ipv6=1
65+
# sock.bind(("::1", 0)) --> socket.error: [Errno 99] Cannot assign requested address
66+
#print(x)
67+
res = -2
68+
except OSError as e:
69+
if e.errno in _ADDR_NOT_AVAIL:
70+
res = -3
71+
elif e.errno in _ADDR_IN_USE:
72+
# This point shouldn't ever be reached. But just in case...
73+
res = -4
74+
else:
75+
# Other errors should be inspected
76+
res = -5
77+
78+
return res
79+
#------------------------------------------
3180

32-
@pytest.mark.skip("FIXME: see notes")
3381
@pytest.mark.es_eds
3482
@pytest.mark.version('>=3.0.1')
3583
def test_1(act: Action):
84+
85+
if (res := check_ipv6_avail()) < 0:
86+
pytest.skip(f"IPv6 not avail, retcode: {res}")
87+
3688
sql_chk = f"""
3789
set list on;
38-
select mon$remote_protocol as procotol_when_connect_from_os
39-
from mon$attachments where mon$attachment_id = current_connection;
40-
4190
commit;
42-
connect 'inet4://{act.db.db_path}';
91+
connect 'inet4://127.0.0.1/{act.db.db_path}';
4392
4493
select mon$remote_protocol as procotol_when_connect_from_isql
4594
from mon$attachments where mon$attachment_id = current_connection;
@@ -50,7 +99,7 @@ def test_1(act: Action):
5099
begin
51100
for
52101
execute statement (stt)
53-
on external 'inet4://{act.db.db_path}'
102+
on external 'inet4://127.0.0.1/{act.db.db_path}'
54103
as user '{act.db.user}' password '{act.db.password}'
55104
into protocol_when_connect_by_es_eds
56105
do
@@ -61,6 +110,8 @@ def test_1(act: Action):
61110
commit;
62111
63112
-- since 27.10.2019:
113+
-- inet6://[::1]/employee
114+
-- connect 'inet6://[::1]/{act.db.db_path}';
64115
connect 'inet6://{act.db.db_path}';
65116
66117
select mon$remote_protocol as procotol_when_connect_from_isql
@@ -72,6 +123,7 @@ def test_1(act: Action):
72123
begin
73124
for
74125
execute statement (stt)
126+
--on external 'inet6://[::1]/{act.db.db_path}' -- currently fails with
75127
on external 'inet6://{act.db.db_path}'
76128
as user '{act.db.user}' password '{act.db.password}'
77129
into protocol_when_connect_by_es_eds
@@ -81,23 +133,16 @@ def test_1(act: Action):
81133
^
82134
set term ;^
83135
commit;
136+
"""
137+
138+
expected_stdout = """
139+
PROCOTOL_WHEN_CONNECT_FROM_ISQL TCPv4
140+
PROTOCOL_WHEN_CONNECT_BY_ES_EDS TCPv4
141+
PROCOTOL_WHEN_CONNECT_FROM_ISQL TCPv6
142+
PROTOCOL_WHEN_CONNECT_BY_ES_EDS TCPv6
143+
"""
84144

85-
-- ||||||||||||||||||||||||||||
86-
-- ###################################||| FB 4.0+, SS and SC |||##############################
87-
-- ||||||||||||||||||||||||||||
88-
-- If we check SS or SC and ExtConnPoolLifeTime > 0 (config parameter FB 4.0+) then current
89-
-- DB (bugs.core_NNNN.fdb) will be 'captured' by firebird.exe process and fbt_run utility
90-
-- will not able to drop this database at the final point of test.
91-
-- Moreover, DB file will be hold until all activity in firebird.exe completed and AFTER this
92-
-- we have to wait for <ExtConnPoolLifeTime> seconds after it (discussion and small test see
93-
-- in the letter to hvlad and dimitr 13.10.2019 11:10).
94-
-- This means that one need to kill all connections to prevent from exception on cleanup phase:
95-
-- SQLCODE: -901 / lock time-out on wait transaction / object <this_test_DB> is in use
96-
-- #############################################################################################
97-
delete from mon$attachments where mon$attachment_id != current_connection;
98-
commit;
99-
"""
100145
act.expected_stdout = expected_stdout
101-
act.isql(switches=['-q', f'inet4://{act.db.db_path}'], input=sql_chk, connect_db=False)
146+
act.isql(switches=['-q', f'inet://{act.db.db_path}'], input=sql_chk, connect_db=False)
102147
assert act.clean_stdout == act.clean_expected_stdout
103148

0 commit comments

Comments
 (0)