URL: https://github.com/freeipa/freeipa/pull/1301
Author: tiran
 Title: #1301: Require UTF-8 fs encoding
Action: opened

PR body:
"""
https://pagure.io/freeipa/issue/5887

Signed-off-by: Christian Heimes <chei...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/1301/head:pr1301
git checkout pr1301
From dcb498fa1e9110b59fa40c12c232e4573ffabb69 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Fri, 17 Nov 2017 11:42:33 +0100
Subject: [PATCH] Require UTF-8 fs encoding

https://pagure.io/freeipa/issue/5887

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipalib/errors.py                  | 12 ++++++++++++
 ipalib/plugable.py                |  5 +++++
 ipatests/test_cmdline/test_cli.py | 21 ++++++++++++++++++++-
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/ipalib/errors.py b/ipalib/errors.py
index fb7fb4e2a9..3a40fa28dc 100644
--- a/ipalib/errors.py
+++ b/ipalib/errors.py
@@ -452,6 +452,18 @@ class EnvironmentError(PublicError):
 
     errno = 912
 
+
+class SystemEncodingError(PublicError):
+    """
+    **913** Raised when system encoding is not UTF-8
+    """
+
+    errno = 913
+    format = _(
+        "System encoding must be UTF-8, '%(encoding)s' is not supported. "
+        "Set LC_ALL=\"C.UTF-8\", or LC_ALL=\"\" and LC_CTYPE=\"C.UTF-8\"."
+    )
+
 ##############################################################################
 # 1000 - 1999: Authentication errors
 class AuthenticationError(PublicError):
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index 66a200ea34..b1fba368db 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -485,6 +485,11 @@ def bootstrap(self, parser=None, **overrides):
         handler.setFormatter(ipa_log_manager.Formatter(LOGGING_FORMAT_STDERR))
         root_logger.addHandler(handler)
 
+        # check after logging is set up but before we create files.
+        fse = sys.getfilesystemencoding()
+        if fse.lower() not in {'utf-8', 'utf8'}:
+            raise errors.SystemEncodingError(encoding=fse)
+
         # Add file handler:
         if self.env.mode in ('dummy', 'unit_test'):
             return  # But not if in unit-test mode
diff --git a/ipatests/test_cmdline/test_cli.py b/ipatests/test_cmdline/test_cli.py
index 4585126d9c..697263b94c 100644
--- a/ipatests/test_cmdline/test_cli.py
+++ b/ipatests/test_cmdline/test_cli.py
@@ -1,6 +1,8 @@
+import contextlib
+import os
 import shlex
+import subprocess
 import sys
-import contextlib
 
 import nose
 import six
@@ -305,3 +307,20 @@ def test_without_options():
 
         if not adtrust_is_enabled:
             mockldap.del_entry(adtrust_dn)
+
+
+def test_cli_fsencoding():
+    # https://pagure.io/freeipa/issue/5887
+    env = {
+        key: value for key, value in os.environ.items()
+        if not key.startswith('LC_')
+    }
+    env['LC_ALL'] = 'C'
+    p = subprocess.Popen(
+        [sys.executable, '-m', 'ipaclient', 'help'],
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE
+    )
+    out, err = p.communicate()
+    assert p.returncode > 0
+    assert 'System encoding must be UTF-8' in err
_______________________________________________
FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org
To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org

Reply via email to