Skip to content

RemoteOperations::exec_command explicitly transfers LANG, LANGUAGE and LC_* envvars to the server side #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prev Previous commit
Next Next commit
TestgresRemoteTests.test_init__unk_LANG_and_LC_CTYPE is updated
Let's test bad data with '\' and '"' symbols.
  • Loading branch information
dmitry-lipetsk committed Feb 21, 2025
commit f4dc0623954582a7d5c75b028138ad08d297c6f0
71 changes: 47 additions & 24 deletions tests/test_simple_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,53 @@ def test_init__unk_LANG_and_LC_CTYPE(self):
prev_LC_COLLATE = os.environ.get("LC_COLLATE")

try:
os.environ["LANG"] = "UNKNOWN_LANG"
os.environ.pop("LANGUAGE", None)
os.environ["LC_CTYPE"] = "UNKNOWN_CTYPE"
os.environ.pop("LC_COLLATE", None)

assert os.environ.get("LANG") == "UNKNOWN_LANG"
assert not ("LANGUAGE" in os.environ.keys())
assert os.environ.get("LC_CTYPE") == "UNKNOWN_CTYPE"
assert not ("LC_COLLATE" in os.environ.keys())

while True:
try:
with get_remote_node(conn_params=conn_params):
pass
except testgres.exceptions.ExecUtilException as e:
# warning: setlocale: LC_CTYPE: cannot change locale (UNKNOWN_CTYPE): No such file or directory
# postgres (PostgreSQL) 14.12
errMsg = str(e)
assert "LC_CTYPE" in errMsg
assert "UNKNOWN_CTYPE" in errMsg
assert "warning: setlocale: LC_CTYPE: cannot change locale (UNKNOWN_CTYPE): No such file or directory" in errMsg
assert "postgres" in errMsg
break
raise Exception("We expected an error!")
# TODO: Pass unkData through test parameter.
unkDatas = [
("UNKNOWN_LANG", "UNKNOWN_CTYPE"),
("\"UNKNOWN_LANG\"", "\"UNKNOWN_CTYPE\""),
("\\UNKNOWN_LANG\\", "\\UNKNOWN_CTYPE\\"),
("\"UNKNOWN_LANG", "UNKNOWN_CTYPE\""),
("\\UNKNOWN_LANG", "UNKNOWN_CTYPE\\"),
("\\", "\\"),
("\"", "\""),
]

for unkData in unkDatas:
logging.info("----------------------")
logging.info("Unk LANG is [{0}]".format(unkData[0]))
logging.info("Unk LC_CTYPE is [{0}]".format(unkData[1]))

os.environ["LANG"] = unkData[0]
os.environ.pop("LANGUAGE", None)
os.environ["LC_CTYPE"] = unkData[1]
os.environ.pop("LC_COLLATE", None)

assert os.environ.get("LANG") == unkData[0]
assert not ("LANGUAGE" in os.environ.keys())
assert os.environ.get("LC_CTYPE") == unkData[1]
assert not ("LC_COLLATE" in os.environ.keys())

while True:
try:
with get_remote_node(conn_params=conn_params):
pass
except testgres.exceptions.ExecUtilException as e:
#
# Example of an error message:
#
# warning: setlocale: LC_CTYPE: cannot change locale (UNKNOWN_CTYPE): No such file or directory
# postgres (PostgreSQL) 14.12
#
errMsg = str(e)

logging.info("Error message is: {0}".format(errMsg))

assert "LC_CTYPE" in errMsg
assert unkData[1] in errMsg
assert "warning: setlocale: LC_CTYPE: cannot change locale (" + unkData[1] + "): No such file or directory" in errMsg
assert "postgres" in errMsg
break
raise Exception("We expected an error!")
finally:
__class__.helper__restore_envvar("LANG", prev_LANG)
__class__.helper__restore_envvar("LANGUAGE", prev_LANGUAGE)
Expand Down