#4076 Fix warnings with python3.8
Closed 4 years ago by pbrezina. Opened 4 years ago by lslebodn.
SSSD/ lslebodn/sssd python3_8  into  master

file modified
+6
@@ -346,12 +346,14 @@ 

  if BUILD_PYTHON2_BINDINGS

  PYTHON_TESTS += src/config/SSSDConfigTest.py2.sh \

                  src/tests/pyhbac-test.py2.sh \

+                 src/tests/pysss-test.py2.sh \

                  src/tests/pysss_murmur-test.py2.sh \

                  $(NULL)

  endif

  if BUILD_PYTHON3_BINDINGS

  PYTHON_TESTS += src/config/SSSDConfigTest.py3.sh \

                  src/tests/pyhbac-test.py3.sh \

+                 src/tests/pysss-test.py3.sh \

                  src/tests/pysss_murmur-test.py3.sh \

                  $(NULL)

  endif
@@ -456,6 +458,9 @@ 

      src/tests/pyhbac-test.py \

      src/tests/pyhbac-test.py2.sh \

      src/tests/pyhbac-test.py3.sh \

+     src/tests/pysss-test.py \

+     src/tests/pysss-test.py2.sh \

+     src/tests/pysss-test.py3.sh \

      src/tests/pysss_murmur-test.py \

      src/tests/pysss_murmur-test.py2.sh \

      src/tests/pysss_murmur-test.py3.sh \
@@ -473,6 +478,7 @@ 

      src/config/testconfigs/sssd-invalid.conf \

      src/config/testconfigs/sssd-invalid-badbool.conf \

      src/config/testconfigs/sssd-nonexisting-services-domains.conf \

+     src/config/testconfigs/sssd-test-parse.conf \

      src/config/etc/sssd.api.d/crash_test_dummy \

      contrib/ci/README.md \

      contrib/ci/configure.sh \

@@ -396,7 +396,7 @@ 

              curopts.append(self.parseLine(line))

  

          #Add last section if any

-         if len(sectopts) is not 0:

+         if sectopts:

              opts.append({'name':section, 'type':'section', 'value':sectopts})

  

          return opts

@@ -2089,6 +2089,33 @@ 

          self.assertRaises(SSSDConfig.NoDomainError,

                            sssdconfig.activate_domain, self)

  

+     def testParse(self):

+         sssdconfig = SSSDConfig.SSSDConfig(srcdir + "/etc/sssd.api.conf",

+                                            srcdir + "/etc/sssd.api.d")

+ 

+         with open(srcdir + "/testconfigs/sssd-test-parse.conf", "r") as f:

+             data = sssdconfig.parse(f)

+ 

+         self.assertEqual(len(data), 4)

+         self.assertEqual(data[-1], {'type': "section",

+                                     'name': "nss",

+                                     'value': [{'type': 'option',

+                                                'name': 'debug_level',

+                                                'value': '1'},

+                                               {'type': 'empty',

+                                                'name': 'empty'}]})

+ 

+         with open(srcdir + "/testconfigs/sssd-valid.conf", "r") as f:

+             data = sssdconfig.parse(f)

+ 

+         self.assertEqual(len(data), 10)

+         self.assertEqual(data[-1], {'name': "sudo",

+                                     'type': "section",

+                                     'value': [{'type': 'option',

+                                                'name': 'debug_level',

+                                                'value': '0xfC10'}]})

+ 

+ 

  if __name__ == "__main__":

      error = 0

  

@@ -0,0 +1,12 @@ 

+ [domain/active]

+ 

+ [domain/inactive]

+ 

+ [sssd]

+ domains = active

+ services = nss

+ 

+ [nss]

+ debug_level = 1

+ 

+ [pam]

file modified
+1 -2
@@ -1944,8 +1944,7 @@ 

  

      /* The HBAC module exception */

      PyExc_HbacError = sss_exception_with_doc(

-                         discard_const_p(char, "hbac.HbacError"),

-                         HbacError__doc__,

+                         "hbac.HbacError", HbacError__doc__,

                          PyExc_EnvironmentError, NULL);

      Py_INCREF(PyExc_HbacError);

      ret = PyModule_AddObject(m, sss_py_const_p(char, "HbacError"), PyExc_HbacError);

file modified
+3 -2
@@ -20,6 +20,7 @@ 

  

  #include "config.h"

  

+ #define PY_SSIZE_T_CLEAN 1

  #include <Python.h>

  #include <structmember.h>

  #include <talloc.h>
@@ -68,7 +69,7 @@ 

                                  PyObject *args)

  {

      char *password = NULL;

-     int plen; /* may contain NULL bytes */

+     Py_ssize_t plen; /* may contain NULL bytes */

      char *obfpwd = NULL;

      TALLOC_CTX *tctx = NULL;

      int ret;
@@ -87,7 +88,7 @@ 

          return NULL;

      }

  

-     ret = sss_password_encrypt(tctx, password, plen+1,

+     ret = sss_password_encrypt(tctx, password, (int)(plen + 1),

                                 mode, &obfpwd);

      if (ret != EOK) {

          PyErr_SetSssError(ret);

file modified
+2 -1
@@ -20,6 +20,7 @@ 

  

  #include "config.h"

  

+ #define PY_SSIZE_T_CLEAN 1

  #include <Python.h>

  

  #include "util/sss_python.h"
@@ -38,7 +39,7 @@ 

      long key_len;

      long long seed;

      uint32_t hash;

-     int input_len;

+     Py_ssize_t input_len;

  

      if (!PyArg_ParseTuple(args, sss_py_const_p(char, "z#lL"),

                            &key, &input_len, &key_len, &seed)) {

@@ -168,7 +168,7 @@ 

  

          [domain/auth_only]

          use_fully_qualified_names = True

-         full_name_format = %2$s\%1$s

+         full_name_format = %2$s\\%1$s

          debug_level = 10

          id_provider = files

  
@@ -644,5 +644,5 @@ 

      if sssctl.wait() != 0:

          raise Exception("sssctl failed")

  

-     assert err.find("pam_authenticate for user [auth_only\user1]: " +

+     assert err.find(r"pam_authenticate for user [auth_only\user1]: " +

                      "Success") != -1

@@ -0,0 +1,99 @@ 

+ #!/usr/bin/env python

+ #  SSSD

+ #

+ #  SSSD python SSS API tests

+ #

+ #  Copyright (C) Red Hat

+ #

+ #  This program is free software; you can redistribute it and/or modify

+ #  it under the terms of the GNU General Public License as published by

+ #  the Free Software Foundation; either version 3 of the License, or

+ #  (at your option) any later version.

+ #

+ #  This program is distributed in the hope that it will be useful,

+ #  but WITHOUT ANY WARRANTY; without even the implied warranty of

+ #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

+ #  GNU General Public License for more details.

+ #

+ #  You should have received a copy of the GNU General Public License

+ #  along with this program.  If not, see <http://www.gnu.org/licenses/>.

+ 

+ from __future__ import print_function

+ 

+ import unittest

+ import sys

+ import os

+ import tempfile

+ 

+ BUILD_DIR = os.getenv('builddir') or "."

+ TEST_DIR = os.getenv('SSS_TEST_DIR') or "."

+ MODPATH = tempfile.mkdtemp(prefix="tp_pysss_", dir=TEST_DIR)

+ 

+ 

+ class PysssImport(unittest.TestCase):

+     def setUp(self):

+         " Make sure we load the in-tree module "

+         self.system_path = sys.path[:]

+         sys.path = [MODPATH]

+ 

+     def tearDown(self):

+         " Restore the system path "

+         sys.path = self.system_path

+ 

+     def test_import(self):

+         " Import the module and assert it comes from tree "

+         try:

+             dest_module_path = MODPATH + "/pysss.so"

+ 

+             if sys.version_info[0] > 2:

+                 src_module_path = BUILD_DIR + "/.libs/_py3sss.so"

+             else:

+                 src_module_path = BUILD_DIR + "/.libs/_py2sss.so"

+ 

+             src_module_path = os.path.abspath(src_module_path)

+             os.symlink(src_module_path, dest_module_path)

+ 

+             import pysss

+         except ImportError as ex:

+             print("Could not load the pysss module. Please check if it is "

+                   "compiled", file=sys.stderr)

+             raise ex

+         self.assertEqual(pysss.__file__, MODPATH + "/pysss.so")

+ 

+ 

+ class PysssEncryptTest(unittest.TestCase):

+     def test_encrypt(self):

+         obfuscator = pysss.password()

+ 

+         val1 = obfuscator.encrypt("123", obfuscator.AES_256)

+         self.assertEqual(len(val1), 96)

+ 

+         val2 = obfuscator.encrypt("123", obfuscator.AES_256)

+         self.assertEqual(len(val2), 96)

+ 

+         self.assertNotEqual(val1, val2)

+ 

+ 

+ if __name__ == "__main__":

+     error = 0

+ 

+     suite = unittest.TestLoader().loadTestsFromTestCase(PysssImport)

+     res = unittest.TextTestRunner().run(suite)

+     if not res.wasSuccessful():

+         error |= 0x1

+         # need to bail out here because pysss could not be imported

+         sys.exit(error)

+ 

+     # import the pysss module into the global namespace, but make sure it's

+     # the one in tree

+     sys.path.insert(0, MODPATH)

+     import pysss

+ 

+     loadTestsFromTestCase = unittest.TestLoader().loadTestsFromTestCase

+ 

+     suite = loadTestsFromTestCase(PysssEncryptTest)

+     res = unittest.TextTestRunner().run(suite)

+     if not res.wasSuccessful():

+         error |= 0x2

+ 

+     sys.exit(error)

@@ -0,0 +1,5 @@ 

+ #!/bin/sh

+ 

+ SCRIPT=$(readlink -f "$0")

+ SCRIPT_PATH=$(dirname "$SCRIPT")

+ exec python2 $SCRIPT_PATH/pysss-test.py

@@ -0,0 +1,5 @@ 

+ #!/bin/sh

+ 

+ SCRIPT=$(readlink -f "$0")

+ SCRIPT_PATH=$(dirname "$SCRIPT")

+ exec python3 $SCRIPT_PATH/pysss-test.py

@@ -169,13 +169,13 @@ 

          if service is None:

              service = 'host'

  

-         if p_type is 'user':

+         if p_type == 'user':

              add_principal = "add_principal -clearpolicy"\

                              " -pw %s %s@%s" % (password, principal,

                                                 self.krb_realm)

              kadmin_local_cmd = ['kadmin.local', '-r',

                                  self.krb_realm, '-q', add_principal]

-         elif p_type is 'admin':

+         elif p_type == 'admin':

              add_principal = "add_principal -clearpolicy"\

                              " -pw %s %s/%s" % (password, service, 'admin')

              kadmin_local_cmd = ['kadmin.local', '-r', self.krb_realm,

file modified
+7 -3
@@ -21,10 +21,14 @@ 

  #include "src/util/sss_python.h"

  

  PyObject *

- sss_exception_with_doc(char *name, char *doc, PyObject *base, PyObject *dict)

+ sss_exception_with_doc(const char *name, const char *doc, PyObject *base,

+                        PyObject *dict)

  {

- #if PY_VERSION_HEX >= 0x02070000

+ #if PY_VERSION_HEX >= 0x03080000

      return PyErr_NewExceptionWithDoc(name, doc, base, dict);

+ #elif PY_VERSION_HEX >= 0x02070000

+     return PyErr_NewExceptionWithDoc(discard_const_p(char, name),

+                                      discard_const_p(char, doc), base, dict);

  #else

      int result;

      PyObject *ret = NULL;
@@ -48,7 +52,7 @@ 

              goto failure;

      }

  

-     ret = PyErr_NewException(name, base, dict);

+     ret = PyErr_NewException(discard_const_p(char, name), base, dict);

    failure:

      Py_XDECREF(mydict);

      return ret;

file modified
+2 -1
@@ -30,7 +30,8 @@ 

  

  /* Exceptions compatibility */

  PyObject *

- sss_exception_with_doc(char *name, char *doc, PyObject *base, PyObject *dict);

+ sss_exception_with_doc(const char *name, const char *doc, PyObject *base,

+                        PyObject *dict);

  

  /* Convenience macros */

  #define TYPE_READY(module, type, name) do {         \

8 new commits added

  • test_pam_responder: Fix DeprecationWarning invalid escape sequence
  • pysss_murmur: Fix DeprecationWarning PY_SSIZE_T_CLEAN
  • pysss: Fix DeprecationWarning PY_SSIZE_T_CLEAN
  • TESTS: Add minimal test for pysss encrypt
  • SSSDConfig: Fix SyntaxWarning "is not" with a literal
  • SSSDConfig: Add minimal test for parse method
  • test_pam_responder: Fix unicore error
  • pyhbac: Fix warning Wdiscarded-qualifiers
4 years ago

1 new commit added

  • testlib: Fix SyntaxWarning "is" with a literal
4 years ago

9 new commits added

  • testlib: Fix SyntaxWarning "is" with a literal
  • test_pam_responder: Fix DeprecationWarning invalid escape sequence
  • pysss_murmur: Fix DeprecationWarning PY_SSIZE_T_CLEAN
  • pysss: Fix DeprecationWarning PY_SSIZE_T_CLEAN
  • TESTS: Add minimal test for pysss encrypt
  • SSSDConfig: Fix SyntaxWarning "is not" with a literal
  • SSSDConfig: Add minimal test for parse method
  • test_pam_responder: Fix unicore error
  • pyhbac: Fix warning Wdiscarded-qualifiers
4 years ago

Metadata Update from @pbrezina:
- Request assigned

4 years ago

CI passed on all machines.

Commit f3529be fixes this pull-request

Pull-Request has been merged by pbrezina

4 years ago
  • master
    • faed8a508bb029d1ee8a3a4d769d651f3f874d17 - testlib: Fix SyntaxWarning "is" with a literal
    • 4f5ffbd55363b2a36dee0c84346215dfe53ff35d - test_pam_responder: Fix DeprecationWarning invalid escape sequence
    • 8423d6cfc73619f372925d159e58f50138c18aca - pysss_murmur: Fix DeprecationWarning PY_SSIZE_T_CLEAN
    • 375018bfa0ae7e14c50323b5296a6a5bbb50a226 - pysss: Fix DeprecationWarning PY_SSIZE_T_CLEAN
    • 97a6d1e844ea07b68d00dc9564fa1fba83423c14 - TESTS: Add minimal test for pysss encrypt
    • 640a0ad43fbd014deb2059a4b2114202317b5eb2 - SSSDConfig: Fix SyntaxWarning "is not" with a literal
    • 38eedb79e48650681b034f5e4a556bb4dd249544 - SSSDConfig: Add minimal test for parse method
    • 2fcd4b3cb085cff34bf7f110131ddf24b59d05b4 - test_pam_responder: Fix unicore error
    • 9007d17cec320a435df1cb8315d563979c7ed161 - pyhbac: Fix warning Wdiscarded-qualifiers

Pull-Request has been closed by pbrezina

4 years ago