Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-pysmbc for openSUSE:Factory checked in at 2021-01-15 19:43:02 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-pysmbc (Old) and /work/SRC/openSUSE:Factory/.python-pysmbc.new.28504 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pysmbc" Fri Jan 15 19:43:02 2021 rev:6 rq:863124 version:1.0.23 Changes: -------- --- /work/SRC/openSUSE:Factory/python-pysmbc/python-pysmbc.changes 2020-08-13 10:12:03.046562082 +0200 +++ /work/SRC/openSUSE:Factory/.python-pysmbc.new.28504/python-pysmbc.changes 2021-01-15 19:43:03.701724478 +0100 @@ -1,0 +2,12 @@ +Thu Jan 14 12:05:43 UTC 2021 - Benjamin Greiner <c...@bnavigator.de> + +- Update to 1.0.23 + No changelog provided. From the git log: + * Python 3 API changes + * Rework Context.getxattr() To Only Allocate Needed Buffer Space +- Remove evil ifpython3. Let the macros figure out the correct + provides/obsoletes tags. gh#openSUSE/python-rpm-macros#66 +- Upstream is moving to pytest, but the tests still need a running + samba server. + +------------------------------------------------------------------- Old: ---- pysmbc-1.0.22.tar.gz New: ---- pysmbc-1.0.23.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pysmbc.spec ++++++ --- /var/tmp/diff_new_pack.OLnKhg/_old 2021-01-15 19:43:04.201725298 +0100 +++ /var/tmp/diff_new_pack.OLnKhg/_new 2021-01-15 19:43:04.205725304 +0100 @@ -1,7 +1,7 @@ # # spec file for package python-pysmbc # -# Copyright (c) 2020 SUSE LLC +# Copyright (c) 2021 SUSE LLC # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -18,15 +18,15 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} %define oldpython python -# Tests don't work in rpmbuild sandbox +# Tests need a running samba server %bcond_with test Name: python-pysmbc -Version: 1.0.22 +Version: 1.0.23 Release: 0 Summary: Python bindings for samba clients (libsmbclient) License: GPL-2.0-or-later Group: Development/Languages/Python -URL: http://cyberelk.net/tim/software/pysmbc/ +URL: https://github.com/hamano/pysmbc Source: https://files.pythonhosted.org/packages/source/p/pysmbc/pysmbc-%{version}.tar.gz BuildRequires: %{python_module devel} BuildRequires: %{python_module setuptools} @@ -35,16 +35,14 @@ BuildRequires: pkgconfig BuildRequires: python-rpm-macros %if %{with test} -BuildRequires: %{python_module nose} +BuildRequires: %{python_module pytest} %endif %ifpython2 Obsoletes: %{oldpython}-smbc < %{version} Provides: %{oldpython}-smbc = %{version} %endif -%ifpython3 -Obsoletes: python3-smbc < %{version} -Provides: python3-smbc = %{version} -%endif +Obsoletes: python-smbc < %{version}-%{release} +Provides: python-smbc = %{version}-%{release} %python_subpackages %description @@ -53,6 +51,7 @@ %prep %setup -q -n pysmbc-%{version} +sed -i '1{/^#!.*/ d}' smbc/xattr.py %build export CFLAGS="%{optflags}" @@ -60,25 +59,18 @@ %install %python_install - -%{python_expand chmod a+x %{buildroot}%{$python_sitearch}/smbc/xattr.py -sed -i "s|^#!%{_bindir}/python$|#!%__$python|" %{buildroot}%{$python_sitearch}/smbc/xattr.py -$python -m compileall -d %{$python_sitearch} %{buildroot}%{$python_sitearch}/smbc/ -$python -O -m compileall -d %{$python_sitelib} %{buildroot}%{$python_sitearch}/smbc/ -%fdupes %{buildroot}%{$python_sitearch} -} +%python_expand %fdupes %{buildroot}%{$python_sitearch} %if %{with test} %check -pushd tests -%{python_expand export PYTHONPATH=%{buildroot}%{$python_sitearch} -$python -B -m nose . -} +%pytest_arch %endif %files %{python_files} %license COPYING %doc NEWS -%{python_sitearch}/* +%{python_sitearch}/smbc +%{python_sitearch}/_smbc* +%{python_sitearch}/pysmbc-%{version}*-info %changelog ++++++ pysmbc-1.0.22.tar.gz -> pysmbc-1.0.23.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/Makefile new/pysmbc-1.0.23/Makefile --- old/pysmbc-1.0.22/Makefile 2020-05-19 18:17:24.000000000 +0200 +++ new/pysmbc-1.0.23/Makefile 2020-05-19 18:17:55.000000000 +0200 @@ -1,7 +1,6 @@ PYTHON=python NAME=pysmbc VERSION:=$(shell $(PYTHON) setup.py --version) -#SDIST_ARGS=--formats=bztar -d. _smbc.so: force $(PYTHON) setup.py build diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/PKG-INFO new/pysmbc-1.0.23/PKG-INFO --- old/pysmbc-1.0.22/PKG-INFO 2020-05-19 18:17:40.000000000 +0200 +++ new/pysmbc-1.0.23/PKG-INFO 2020-10-26 03:36:16.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pysmbc -Version: 1.0.22 +Version: 1.0.23 Summary: Python bindings for libsmbclient Home-page: https://github.com/hamano/pysmbc Author: ['Tim Waugh <twa...@redhat.com>', 'Tsukasa Hamano <ham...@osstech.co.jp>', 'Roberto Polli <rpo...@babel.it>'] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/pysmbc.egg-info/PKG-INFO new/pysmbc-1.0.23/pysmbc.egg-info/PKG-INFO --- old/pysmbc-1.0.22/pysmbc.egg-info/PKG-INFO 2020-05-19 18:17:40.000000000 +0200 +++ new/pysmbc-1.0.23/pysmbc.egg-info/PKG-INFO 2020-10-26 03:36:16.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pysmbc -Version: 1.0.22 +Version: 1.0.23 Summary: Python bindings for libsmbclient Home-page: https://github.com/hamano/pysmbc Author: ['Tim Waugh <twa...@redhat.com>', 'Tsukasa Hamano <ham...@osstech.co.jp>', 'Roberto Polli <rpo...@babel.it>'] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/pysmbc.egg-info/SOURCES.txt new/pysmbc-1.0.23/pysmbc.egg-info/SOURCES.txt --- old/pysmbc-1.0.22/pysmbc.egg-info/SOURCES.txt 2020-05-19 18:17:40.000000000 +0200 +++ new/pysmbc-1.0.23/pysmbc.egg-info/SOURCES.txt 2020-10-26 03:36:16.000000000 +0100 @@ -4,6 +4,7 @@ NEWS README.md setup.py +test.py pysmbc.egg-info/PKG-INFO pysmbc.egg-info/SOURCES.txt pysmbc.egg-info/dependency_links.txt @@ -20,9 +21,6 @@ smbc/smbcmodule.c smbc/smbcmodule.h smbc/xattr.py -tests/settings.py -tests/test_acl.py -tests/test_auth.py -tests/test_context.py -tests/test_dir.py -tests/test_file.py \ No newline at end of file +tests/__init__.py +tests/conftest.py +tests/test_auth.py \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/setup.py new/pysmbc-1.0.23/setup.py --- old/pysmbc-1.0.22/setup.py 2020-05-19 13:38:32.000000000 +0200 +++ new/pysmbc-1.0.23/setup.py 2020-10-26 03:35:07.000000000 +0100 @@ -79,12 +79,15 @@ stdout=subprocess.PIPE) (stdout, stderr) = c.communicate() vers = stdout.decode('ascii').rstrip().split('.') - ver = str(int(vers[0]) * 10000 + int(vers[1]) * 100 + int(vers[2])) + if len(vers) == 3: + ver = str(int(vers[0]) * 10000 + int(vers[1]) * 100 + int(vers[2])) + else: + ver = str(int(vers[0])) return [(prefix + 'VERSION', ver)] setup( name="pysmbc", - version="1.0.22", + version="1.0.23", description="Python bindings for libsmbclient", long_description=__doc__, author=[ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/smbc/context.c new/pysmbc-1.0.23/smbc/context.c --- old/pysmbc-1.0.22/smbc/context.c 2020-05-19 13:33:50.000000000 +0200 +++ new/pysmbc-1.0.23/smbc/context.c 2020-10-22 17:19:20.000000000 +0200 @@ -25,8 +25,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <Python.h> -#include <string.h> #include "smbcmodule.h" #include "context.h" #include "dir.h" @@ -143,16 +141,6 @@ self->auth_fn = auth; } -#if SMBCLIENT_VERSION < 500 /* Older than 0.5.0 */ - if(proto) - { - debugprintf ("-> Setting client max protocol to %s\n", proto); - lp_set_cmdline("client max protocol", proto); - debugprintf ("-> Setting client min protocol to %s\n", proto); - lp_set_cmdline("client min protocol", proto); - } -#endif - debugprintf ("-> Context_init ()\n"); errno = 0; @@ -170,13 +158,17 @@ smbc_setOptionUserData (ctx, self); if (auth) smbc_setFunctionAuthDataWithContext (ctx, auth_fn); -#if SMBCLIENT_VERSION >= 500 /* 0.5.0 or newer */ if(proto) { - debugprintf ("-> Setting client min/max protocol to %s\n", proto); - smbc_setOptionProtocols (ctx, proto, proto); - } +#if SMBCLIENT_VERSION >= 500 /* 0.5.0 or newer */ + debugprintf("-> Setting client min/max protocol to %s by smbc_setOptionProtocols\n", proto); + smbc_setOptionProtocols(ctx, proto, proto); +#else + debugprintf("-> Setting client min/max protocol to %s by smbc_option_set\n", proto); + smbc_option_set(ctx, "client max protocol", proto); + smbc_option_set(ctx, "client min protocol", proto); #endif + } if (smbc_init_context (ctx) == NULL) { @@ -586,64 +578,43 @@ */ static PyObject * Context_getxattr (Context *self, PyObject *args) -{ - int ret; - char *uri = NULL; - char *name = NULL; - char *buffer = NULL; - static smbc_getxattr_fn fn; - - // smbc_getxattr takes two string parameters - if (!PyArg_ParseTuple (args, "ss", &uri, &name)) - { - return NULL; - } - - /* The security descriptor string returned by this call will vary depending on the requested attribute - * A call with system.nt_sec_desc.* will return the longest string which would be in the following format: - * - * REVISION:<revision number>,OWNER:<sid>,GROUP:<sid>,ACL:<sid>:<type>/<flags>/<mask> - * - * There could be multiple ACL entries up to a reasonable maximum of 1820. - * - * <revision number> : 3 chars - * <sid> : 184 chars - * <type>: 1 char - * <flags>: 3 chars - * <mask>: 10 chars - * - * The maximum size of the security descriptor string returned can be - * derived as follows (includes space for terminating null): - * Sec Desc = 13 + 2 x (7 + <sid>) + 1820 * (5 + <acl>) = 375315 - * - * References: https://msdn.microsoft.com/en-us/library/cc246018.aspx - * https://technet.microsoft.com/en-us/library/cc961995.aspx - * https://technet.microsoft.com/en-us/library/cc961986.aspx - */ - - size_t size = 375315; - buffer = (char *)malloc (size); - if(!buffer) - return PyErr_NoMemory (); - - bzero(buffer, size); - - errno = 0; - fn = smbc_getFunctionGetxattr(self->context); - ret = (*fn)(self->context, uri, name, buffer, size); - - if (ret < 0) - { - pysmbc_SetFromErrno (); - free(buffer); - return NULL; - } - - PyObject *value = PyUnicode_FromString(buffer); - free(buffer); - - return value; -} + { + PyObject * result = NULL; + char *uri = NULL; + char *name = NULL; + char *buffer = NULL; + int ret; + do /*once*/ + { + if (!PyArg_ParseTuple(args, "ss", &uri, &name)) + break; + const smbc_getxattr_fn fn = smbc_getFunctionGetxattr(self->context); + errno = 0; + ret = fn(self->context, uri, name, NULL, 0); + if (ret < 0) + { + pysmbc_SetFromErrno(); + break; + } + const int bufsize = ret + 1; + buffer = (char *)malloc(bufsize); + if (buffer == NULL) + { + PyErr_NoMemory(); + break; + } /*if*/ + ret = fn(self->context, uri, name, buffer, bufsize); + if (ret < 0) + { + pysmbc_SetFromErrno(); + break; + } /*if*/ + result = PyUnicode_FromString(buffer); + } + while (false); + free(buffer); + return result; + } /*Context_getxattr*/ /** @@ -805,7 +776,12 @@ return -1; } - chars = PyUnicode_GetSize (value); /* not including NUL */ +#if PY_MAJOR_VERSION > 3 + chars = PyUnicode_GET_LENGTH(value); +#else + chars = PyUnicode_GET_SIZE(value); /* not including NUL */ +#endif + w_name = malloc ((chars + 1) * sizeof (wchar_t)); if (!w_name) { @@ -874,7 +850,12 @@ return -1; } - chars = PyUnicode_GetSize (value); /* not including NUL */ +#if PY_MAJOR_VERSION > 3 + chars = PyUnicode_GET_LENGTH(value); +#else + chars = PyUnicode_GET_SIZE(value); /* not including NUL */ +#endif + w_workgroup = malloc ((chars + 1) * sizeof (wchar_t)); if (!w_workgroup) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/smbc/dir.c new/pysmbc-1.0.23/smbc/dir.c --- old/pysmbc-1.0.22/smbc/dir.c 2020-05-19 13:33:50.000000000 +0200 +++ new/pysmbc-1.0.23/smbc/dir.c 2020-10-22 17:17:16.000000000 +0200 @@ -18,7 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <Python.h> #include "smbcmodule.h" #include "context.h" #include "dir.h" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/smbc/file.c new/pysmbc-1.0.23/smbc/file.c --- old/pysmbc-1.0.22/smbc/file.c 2020-05-19 13:33:50.000000000 +0200 +++ new/pysmbc-1.0.23/smbc/file.c 2020-10-22 17:17:30.000000000 +0200 @@ -23,7 +23,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <Python.h> #include "smbcmodule.h" #include "context.h" #include "file.h" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/smbc/smbcdirent.c new/pysmbc-1.0.23/smbc/smbcdirent.c --- old/pysmbc-1.0.22/smbc/smbcdirent.c 2019-09-27 10:36:50.000000000 +0200 +++ new/pysmbc-1.0.23/smbc/smbcdirent.c 2020-10-22 17:23:16.000000000 +0200 @@ -18,7 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <Python.h> #include "smbcmodule.h" #include "smbcdirent.h" @@ -55,9 +54,9 @@ Dirent_init (Dirent *self, PyObject *args, PyObject *kwds) { const char *name; - int name_len; + Py_ssize_t name_len; const char *comment; - int comment_len; + Py_ssize_t comment_len; unsigned int smbc_type; static char *kwlist[] = { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/smbc/smbcmodule.c new/pysmbc-1.0.23/smbc/smbcmodule.c --- old/pysmbc-1.0.22/smbc/smbcmodule.c 2019-09-27 10:36:50.000000000 +0200 +++ new/pysmbc-1.0.23/smbc/smbcmodule.c 2020-10-22 17:16:37.000000000 +0200 @@ -26,7 +26,6 @@ */ #include <stdarg.h> -#include <Python.h> #include "smbcmodule.h" #include "context.h" #include "dir.h" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/smbc/smbcmodule.h new/pysmbc-1.0.23/smbc/smbcmodule.h --- old/pysmbc-1.0.22/smbc/smbcmodule.h 2020-05-19 13:33:50.000000000 +0200 +++ new/pysmbc-1.0.23/smbc/smbcmodule.h 2020-10-22 17:20:18.000000000 +0200 @@ -23,7 +23,8 @@ #ifndef HAVE_SMBCMODULE_H #define HAVE_SMBCMODULE_H - +#define PY_SSIZE_T_CLEAN +#include <Python.h> #include <stdbool.h> #include <libsmbclient.h> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/test.py new/pysmbc-1.0.23/test.py --- old/pysmbc-1.0.22/test.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pysmbc-1.0.23/test.py 2020-10-14 18:03:53.000000000 +0200 @@ -0,0 +1,15 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import sys +import smbc + +def main(): + ctx = smbc.Context() + uri = 'smb://localhost' + entries = ctx.opendir(uri).getdents() + for d in entries: + print(d) + +if __name__ == '__main__': + main() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/tests/conftest.py new/pysmbc-1.0.23/tests/conftest.py --- old/pysmbc-1.0.22/tests/conftest.py 1970-01-01 01:00:00.000000000 +0100 +++ new/pysmbc-1.0.23/tests/conftest.py 2020-10-16 03:43:28.000000000 +0200 @@ -0,0 +1,22 @@ +import pytest + +def pytest_addoption(parser): + parser.addoption('--server', action='store', default='localhost') + parser.addoption('--share', action='store', default='share') + parser.addoption('--username', action='store', default='user1') + parser.addoption('--password', action='store', default='password1') + +@pytest.fixture(autouse=True, scope='session') +def config(pytestconfig): + server = pytestconfig.getoption('server') + share = pytestconfig.getoption('share') + username = pytestconfig.getoption('username') + password = pytestconfig.getoption('password') + uri = 'smb://{}/{}/'.format(server, share) + yield { + 'server': server, + 'share': share, + 'username': username, + 'password': password, + 'uri': uri, + } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/tests/settings.py new/pysmbc-1.0.23/tests/settings.py --- old/pysmbc-1.0.22/tests/settings.py 2019-09-27 10:36:50.000000000 +0200 +++ new/pysmbc-1.0.23/tests/settings.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,13 +0,0 @@ -# This is setting template. -# You must change these parameter if you perform test. -# The following configration will create \\server\share\testdir -# directory, so user should have write permission. - -WORKGROUP = "WORKGROUP" -SERVER = "server" -SHARE = "share" -USERNAME = "username" -PASSWORD = "password" -TESTDIR = "testdir" - - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/tests/test_acl.py new/pysmbc-1.0.23/tests/test_acl.py --- old/pysmbc-1.0.22/tests/test_acl.py 2019-09-27 10:36:50.000000000 +0200 +++ new/pysmbc-1.0.23/tests/test_acl.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,68 +0,0 @@ -import os -import smbc -import settings -import nose -from nose.plugins.skip import SkipTest - - -""" Test acl parser - - -""" - -class SmbAcl(): - revision = None - owner = None - group = None - acl = [] - - def __init__(self, xattr_s=None): - """ parse an acl into a SmbAcl object """ - if xattr_s: - xattr_l = [ s[s.index(":")+1:] for s in xattr_s.split(",")] - (self.revision, self.owner, self.group) = xattr_l[0:3] - self.acl = xattr_l[3:] - - - def __str__(self): - ret = "REVISION:%s,OWNER:%s,GROUP:%s" % (self.revision,self.owner,self.group) - for a in self.acl: - ret = ret + ",ACL:%s" % a - return ret - - @staticmethod - def get_target(acl_s): - return acl_s[0:acl_s.index(":")] - - @staticmethod - def get_perm(acl_s): - return acl_s[acl_s.index(":")+1:] - - -"""SmbAcl parser To be implemented""" -def test_acl_parser(): - raise SkipTest("SmbAcl to be implemented") - - xattr_l = ["REVISION:1,OWNER:S-1-5-21-833659924-920326847-3160110649-3002,GROUP:S-1-22-2-1002,ACL:S-1-5-21-833659924-920326847-3160110649-3002:0/0/0x001e01ff,ACL:S-1-22-2-1002:0/0/0x00120089,ACL:S-1-1-0:0/0/0x00120089", - #attrs(system.nt_sec_desc.*+): - 'REVISION:1,OWNER:RPOLLI\\babel,GROUP:Unix Group\\babel,ACL:RPOLLI\\babel:0/0/0x001e01ff,ACL:Unix Group\\babel:0/0/0x00120089,ACL:\Everyone:0/0/0x00120089'] - - for xattr_s in xattr_l: - xattr = SmbAcl(xattr_s) - print("xattr: %s" % xattr) - - assert xattr.revision - assert xattr.owner - assert xattr.group - assert xattr.acl and len(xattr.acl)>1 - -def test_acl_get_target(): - acl_l = ["S-1-5-21-833659924-920326847-3160110649-3002:0/0/0x001e01ff", - "Unix Group\\babel:0/0/0x00120089"] - for acl_s in acl_l: - perm = SmbAcl.get_perm(acl_s) - target = SmbAcl.get_target(acl_s) - - assert target - assert perm - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/tests/test_auth.py new/pysmbc-1.0.23/tests/test_auth.py --- old/pysmbc-1.0.22/tests/test_auth.py 2019-09-27 10:36:50.000000000 +0200 +++ new/pysmbc-1.0.23/tests/test_auth.py 2020-10-25 15:25:07.000000000 +0100 @@ -1,72 +1,43 @@ -#!/usr/bin/env python - import smbc -import settings -import sys - -def setUp(): - pass - -def tearDown(): - pass -def test_AuthSuccess(): +def test_auth_succes(config): ctx = smbc.Context() ctx.optionNoAutoAnonymousLogin = True - cb = lambda se, sh, w, u, p: (w, settings.USERNAME, settings.PASSWORD) + cb = lambda se, sh, w, u, p: (w, config['username'], config['password']) ctx.functionAuthData = cb - uri = 'smb://' + settings.SERVER + '/' + settings.SHARE - try: - dir = ctx.opendir(uri) - print("ok: connection to ", uri) - except: - print("fail: connection to ", uri) - assert False + d = ctx.opendir(config['uri']) + assert d != None -def test_AuthFailNoauth(): +def test_auth_failed_noauth(config): ctx = smbc.Context() ctx.optionNoAutoAnonymousLogin = True - uri = 'smb://' + settings.SERVER + '/' + settings.SHARE try: - dir = ctx.opendir(uri) + ctx.opendir(config['uri']) except smbc.PermissionError: - print("ok: permission error to ", uri) - pass - except: - print("fail: error connecting to", uri) - assert False + assert True else: - print("fail: error connecting to", uri) assert False -def test_AuthFailNopass(): +def test_auth_failed_nopass(config): ctx = smbc.Context() ctx.optionNoAutoAnonymousLogin = True - cb = lambda se, sh, w, u, p: (w, settings.USERNAME, "") + cb = lambda se, sh, w, u, p: (w, config['username'], "") ctx.functionAuthData = cb - uri = 'smb://' + settings.SERVER + '/' + settings.SHARE try: - dir = ctx.opendir(uri) + ctx.opendir(config['uri']) except smbc.PermissionError: - pass - except: - assert False + assert True else: assert False -def test_AuthFailNoname(): +def test_auth_failed_nouser(config): ctx = smbc.Context() ctx.optionNoAutoAnonymousLogin = True - cb = lambda se, sh, w, u, p: (w, "", "") + cb = lambda se, sh, w, u, p: (w, "", config['password']) ctx.functionAuthData = cb - uri = 'smb://' + settings.SERVER + '/' + settings.SHARE try: - dir = ctx.opendir(uri) + ctx.opendir(config['uri']) except smbc.PermissionError: - pass - except: - assert False + assert True else: assert False - - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/tests/test_context.py new/pysmbc-1.0.23/tests/test_context.py --- old/pysmbc-1.0.22/tests/test_context.py 2019-09-27 10:36:50.000000000 +0200 +++ new/pysmbc-1.0.23/tests/test_context.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,195 +0,0 @@ -#!/usr/bin/env python -import os -import smbc -import settings -import nose -from nose.plugins.skip import SkipTest - - -baseurl = 'smb://' + settings.SERVER + "/" + settings.SHARE +"/" - - -# a nice map from/to smbc constants -smbcType = { - 'WORKGROUP' : smbc.WORKGROUP, - 'SERVER' : smbc.SERVER, - 'FILE_SHARE' : smbc.FILE_SHARE, - 'PRINTER_SHARE' : smbc.PRINTER_SHARE, - 'IPC_SHARE' : smbc.IPC_SHARE, - - smbc.WORKGROUP : 'WORKGROUP', - smbc.SERVER : 'SERVER', - smbc.FILE_SHARE : 'FILE_SHARE', - smbc.PRINTER_SHARE : 'PRINTER_SHARE', - smbc.IPC_SHARE : 'IPC_SHARE' -} - -# another map for system errors TODO can you find them in another module? -EINVAL = 22 - -def setUp(): - global ctx - ctx = smbc.Context() - cb = lambda se, sh, w, u, p: (w, settings.USERNAME, settings.PASSWORD) - ctx.functionAuthData = cb - - -def tearDown(): - global ctx - del ctx - -def touch_file(name): - """ - create a file containing "sample test file" in the test baseurl - """ - tmpfile_name = baseurl + name - dfile = ctx.open(tmpfile_name, os.O_CREAT | os.O_TRUNC | os.O_WRONLY) - dfile.write("sample test file") - dfile.close - return tmpfile_name - - -def test_xattr_constants(): - assert smbc.XATTR_ACL - assert smbc.XATTR_OWNER - assert smbc.XATTR_GROUP - - -def test_xattr_get(): - """ - system.nt_sec_desc.<attribute name> - * system.nt_sec_desc.* - * system.nt_sec_desc.*+ - * - * where <attribute name> is one of: - * - * revision - * owner - * owner+ - * group - * group+ - * acl:<name or sid> - * acl+:<name or sid - """ - print("test_xattr") - furl = touch_file("tmpfile.out") - - # create all combinations of attribute strings - plus_xattrs = ["%s%s" % (i,j) for i in ["owner", "group", "*"] for j in ["","+"]] - plus_xattrs.append("revision") - valid_xatts = ["system.nt_sec_desc." +i for i in plus_xattrs] - - # check their existence - for xattr in valid_xatts: - print("\ttesting %s with %s" % (furl, xattr)) - assert(ctx.getxattr(furl, xattr)) - ctx.open(furl) - -def test_xattr_get_error(): - """ Verify that a RuntimeError is raised when passing bad arguments to getxattr() - - Bad arguments include malformed xattrs and unexistent file - """ - print("test_xattr") - furl = touch_file("tmpfile.out") - - # create all combinations of attribute strings - plus_xattrs = ["%s%s" % (i,j) for i in ["owner", "pluto", "*"] for j in ["x","-"]] - plus_xattrs.append("revisionX") - invalid_xatts = ["system.nt_sec_desc." +i for i in plus_xattrs] - - try: - ctx.getxattr("UNEXISTENT", smbc.XATTR_OWNER) - assert False, "getxattr should fail with an unexistent file" - except ValueError as e: - (errno,strerror) = e.args - assert errno == EINVAL # TODO is it possible to trap an unexistent entity error from smbclient? - pass - - # check their existence - for xattr in invalid_xatts: - print("\ttesting %s with %s" % (furl, xattr)) - try: - ctx.getxattr(furl, xattr) - assert False, "getxattr should fail with %s" % xattr - except ValueError as e: - (errno,strerror) = e.args - assert errno == EINVAL # invalid arguments - - ctx.open(furl) - -def test_xattr_set(): - #raise SkipTest("xattr_set to be implemented") - print("test_xattr_put") - furl = touch_file("tmpfile_set.out") - attr_name = smbc.XATTR_ALL - attrs = ctx.getxattr(furl, attr_name) - print("attrs(%s): %s" % (attr_name, attrs)) - ctx.setxattr(furl, attr_name, attrs, smbc.XATTR_FLAG_REPLACE) - attrs1 = ctx.getxattr(furl, attr_name) - print("attrs1(%s): %s" % (attr_name, attrs1)) - assert attrs1 == attrs - -@SkipTest -def test_xattr_set_2(): - furl = touch_file("tmpfile_set.out") - attrs_new = u'REVISION:1,OWNER:RPOLLI\\babel" \ - + ",GROUP:Unix Group\\babel" \ - + ",ACL:RPOLLI\\babel:0/0/0x001e01ff" \ - + ",ACL:Unix Group\\babel:0/0/0x00120089" \ - + ",ACL:Unix Group\\games:0/0/0x001e01ff" \ - + ",ACL:\\Everyone:0/0/0x00120089' - attr_name = smbc.XATTR_ALL_SID - attrs_0 = ctx.getxattr(furl, attr_name) - print("original attrs(%s)" % attrs_0) - - assert attrs_0 != attrs_new, "Old and new attributes are the same:\n%s\n%s\n" % (attrs_0, attrs_new) - - ctx.setxattr(furl, attr_name, attrs_new, smbc.XATTR_FLAG_REPLACE) - attrs_1 = ctx.getxattr(furl, attr_name) - - print("attrs_1(%s): %s" % (attr_name, attrs_1)) - assert attrs_1 == attrs_new - -def test_xattr_set_error(): - #raise SkipTest("xattr_set to be implemented") - print("test_xattr_set_error") - furl = touch_file("tmpfile_set.out") - attr_name = smbc.XATTR_ALL_SID - attrs_ok = ctx.getxattr(furl, attr_name) - attrs = "BAD_VALUE" # causes segfault - for xa in ["BAD_VALUE", u'REVISION:1,OWNER:RPOLLI\\babel,GROUP:', 0, None]: - try: - ctx.setxattr(furl, attr_name, xa, smbc.XATTR_FLAG_REPLACE) - except ValueError as e: - (errno,strerror) = e.args - assert errno == EINVAL # invalid arguments - print("setxattr(%s) raises %s" % (xa, e)) - pass - except TypeError as e: - print("setxattr(%s) raises %s" % (xa, e)) - pass - - - -def test_Workgroup(): - l_entries = ctx.opendir('smb://').getdents() - assert(len(l_entries) > 0) - for entry in l_entries: - assert(entry.smbc_type == smbc.WORKGROUP), "Entry %s of type %s, expected %s" % (entry.name, smbcType[entry.smbc_type], smbcType[smbc.WORKGROUP]) - -def test_Server(): - uri = 'smb://' + settings.WORKGROUP - l_entries = ctx.opendir(uri).getdents() - assert(len(l_entries) > 0) - for entry in l_entries: - assert(entry.smbc_type == smbc.SERVER), "Entry %s of type %s, expected %s" % (entry.name, smbcType[entry.smbc_type], smbcType[smbc.SERVER]) - -def test_Share(): - uri = 'smb://' + settings.SERVER - l_entries = ctx.opendir(uri).getdents() - - allowed_shares = [smbc.FILE_SHARE, smbc.PRINTER_SHARE, smbc.IPC_SHARE, smbc.COMMS_SHARE] - assert(len(l_entries) > 0) - for entry in l_entries: - assert (entry.smbc_type in allowed_shares), "Entry was %s (%d), expected values: %s" % (smbcType[entry.smbc_type], entry.smbc_type, allowed_shares) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/tests/test_dir.py new/pysmbc-1.0.23/tests/test_dir.py --- old/pysmbc-1.0.22/tests/test_dir.py 2019-09-27 10:36:50.000000000 +0200 +++ new/pysmbc-1.0.23/tests/test_dir.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,73 +0,0 @@ -#!/usr/bin/env python - -import smbc -import settings -import stat - -basedir = 'smb://' + settings.SERVER + '/' + settings.SHARE + '/' -testdir = basedir + '/' + settings.TESTDIR - -def auth_fn(server, share, workgroup, username, password): - return (workgroup, settings.USERNAME, settings.PASSWORD) - -def setUp(): - global ctx - ctx = smbc.Context() - ctx.optionNoAutoAnonymousLogin = True - ctx.functionAuthData = auth_fn - -def tearDown(): - global ctx - del ctx - -def test_Mkdir(): - ret = ctx.mkdir(testdir, 0) - assert(ret == 0) - -def test_MkdirFail(): - try: - ret = ctx.mkdir(testdir) - except smbc.ExistsError: - pass - except: - assert False - else: - assert False - assert True - -def test_ListDir(): - list = ctx.opendir(testdir).getdents() - assert(len(list) == 2) - -def test_Stat(): - st = ctx.stat(testdir) - mode = st[stat.ST_MODE] - assert(stat.S_ISDIR(mode)) - assert(stat.S_ISREG(mode) == False) - -def test_Rename(): - src = testdir + '/dir1' - dst = testdir + '/dir2' - ret = ctx.mkdir(src) - assert(ret == 0) - ret = ctx.rename(src, dst) - assert(ret == 0) - -def test_StatFail(): - uri = testdir + '/dir1' - try: - ctx.stat(uri) - except smbc.NoEntryError: - pass - except: - assert False - -def test_Rmdir(): - uri = testdir + '/dir2' - ret = ctx.rmdir(uri) - assert(ret == 0) - -def test_Cleanup(): - ret = ctx.rmdir(testdir) - assert(ret == 0) - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pysmbc-1.0.22/tests/test_file.py new/pysmbc-1.0.23/tests/test_file.py --- old/pysmbc-1.0.22/tests/test_file.py 2019-09-27 10:36:50.000000000 +0200 +++ new/pysmbc-1.0.23/tests/test_file.py 1970-01-01 01:00:00.000000000 +0100 @@ -1,167 +0,0 @@ -#!/usr/bin/env python - -import smbc -import settings -import hashlib -import os - -basedir = 'smb://' + settings.SERVER + '/' + settings.SHARE + '/' -testdir = basedir + '/' + settings.TESTDIR - -def auth_fn(server, share, workgroup, username, password): - return (workgroup, settings.USERNAME, settings.PASSWORD) - -def creat_randfile(path, size): - rand = open('/dev/urandom', 'rb') - file = open(path, 'wb') - buf = rand.read(size) - file.write(buf) - file.close() - rand.close() - -def md(path): - m = hashlib.md5() - file = open(path, 'rb') - m.update(file.read()) - file.close() - return m.hexdigest() - -def upload_simple(spath, ctx, duri): - sfile = open(spath, 'rb') - dfile = ctx.open(duri, os.O_CREAT | os.O_TRUNC | os.O_WRONLY) - ret = dfile.write(sfile.read()) - if ret < 0: - raise IOError("smbc write error") - sfile.close() - dfile.close() - return True - -def download_simple(ctx, suri, dpath): - sfile = ctx.open(suri, os.O_RDONLY) - dfile = open(dpath, 'wb') - dfile.write(sfile.read()) - dfile.flush() - sfile.close() - dfile.close() - return True - -def upload_buffer(spath, ctx, duri): - sfile = open(spath, 'rb') - dfile = ctx.open(duri, os.O_CREAT | os.O_TRUNC | os.O_WRONLY) - while True: - buf = sfile.read(8192) - if not buf: - break - ret = dfile.write(buf) - if ret < 0: - raise IOError("smbc write error") - sfile.close() - dfile.close() - return True - -def download_buffer(ctx, suri, dpath): - sfile = ctx.open(suri, os.O_RDONLY) - dfile = open(dpath, 'wb') - while True: - buf = sfile.read(8192) - if not buf: - break - dfile.write(buf) - dfile.flush() - sfile.close() - dfile.close() - return True - -def upload_iter(spath, ctx, duri): - sfile = open(spath, 'rb') - dfile = ctx.open(duri, os.O_CREAT | os.O_TRUNC | os.O_WRONLY) - for buf in sfile: - ret = dfile.write(buf) - if ret < 0: - raise IOError("smbc write error") - sfile.close() - dfile.close() - return True - -def download_iter(ctx, suri, dpath): - sfile = ctx.open(suri, os.O_RDONLY) - dfile = open(dpath, 'wb') - for buf in sfile: - dfile.write(buf) - dfile.flush() - sfile.close() - dfile.close() - return True - -def setUp(): - global ctx - ctx = smbc.Context() - ctx.optionNoAutoAnonymousLogin = True - ctx.functionAuthData = auth_fn - -def tearDown(): - global ctx - del ctx - -def test_copy_simple_1k(): - creat_randfile('test1.dat', 1000) - testfile = basedir + '/' + 'test1.dat' - upload_simple('test1.dat', ctx, testfile) - download_simple(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat')) - -def test_copy_simple_100k(): - creat_randfile('test1.dat', 10000) - testfile = basedir + '/' + 'test1.dat' - upload_simple('test1.dat', ctx, testfile) - download_simple(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat')) - -def test_copy_simple_1M(): - creat_randfile('test1.dat', 1000000) - testfile = basedir + '/' + 'test1.dat' - upload_simple('test1.dat', ctx, testfile) - download_simple(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat')) - -def test_copy_buffer_1k(): - creat_randfile('test1.dat', 1000) - testfile = basedir + '/' + 'test1.dat' - upload_buffer('test1.dat', ctx, testfile) - download_buffer(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat')) - -def test_copy_buffer_100k(): - creat_randfile('test1.dat', 10000) - testfile = basedir + '/' + 'test1.dat' - upload_buffer('test1.dat', ctx, testfile) - download_buffer(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat')) - -def test_copy_buffer_1M(): - creat_randfile('test1.dat', 1000000) - testfile = basedir + '/' + 'test1.dat' - upload_buffer('test1.dat', ctx, testfile) - download_buffer(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat')) - -def test_copy_iter_1k(): - creat_randfile('test1.dat', 1000) - testfile = basedir + '/' + 'test1.dat' - upload_iter('test1.dat', ctx, testfile) - download_iter(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat')) - -def test_copy_iter_100k(): - creat_randfile('test1.dat', 10000) - testfile = basedir + '/' + 'test1.dat' - upload_iter('test1.dat', ctx, testfile) - download_iter(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat')) - -def test_copy_iter_1M(): - creat_randfile('test1.dat', 1000000) - testfile = basedir + '/' + 'test1.dat' - upload_iter('test1.dat', ctx, testfile) - download_iter(ctx, testfile, 'test2.dat') - assert(md('test1.dat') == md('test2.dat'))