summaryrefslogtreecommitdiff
path: root/python/samba/tests/blackbox/misc_dfs_widelink.py
blob: 7948590d71063e62de1467b069924bffddada478 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Blackbox tests for DFS (widelink)
#
# Copyright (C) Noel Power noel.power@suse.com
#
# 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 samba.tests import BlackboxTestCase, BlackboxProcessError
from samba.samba3 import param as s3param

from samba.credentials import Credentials

import os

class DfsWidelinkBlockboxTestBase(BlackboxTestCase):

    def setUp(self):
        super().setUp()
        self.lp = s3param.get_context()
        self.server = os.environ["SERVER"]
        self.user = os.environ["USER"]
        self.passwd = os.environ["PASSWORD"]
        self.creds = Credentials()
        self.creds.guess(self.lp)
        self.creds.set_username(self.user)
        self.creds.set_password(self.passwd)
        self.testdir = os.getenv("TESTDIR", "msdfs-share-wl")
        self.share = os.getenv("SHARE", "msdfs-share-wl")
        self.dirpath = os.path.join(os.environ["LOCAL_PATH"],self.testdir)
        # allow a custom teardown function to be defined
        self.cleanup = None
        self.cleanup_args = []

    def tearDown(self):
        try:
            if (self.cleanup):
                self.cleanup(self.cleanup_args)
        except Exception as e:
            print("remote remove failed: %s" % str(e))

    def build_test_cmd(self, cmd, args):
        cmd = [cmd, "-U%s%%%s" % (self.user, self.passwd)]
        cmd.extend(args)
        return cmd

    def test_ci_chdir(self):
        parent_dir = "msdfs-src1"
        dirs = [parent_dir, parent_dir.upper()]
        # try as named dir first then try upper-cased version
        for adir in dirs:
            smbclient_args = self.build_test_cmd("smbclient", ["//%s/%s" % (self.server, self.share), "-c", "cd %s" % (adir)])
            try:
                out_str = self.check_output(smbclient_args)
            except BlackboxProcessError as e:
                print(str(e))
                self.fail(str(e))

    def test_nested_chdir(self):
        parent_dir = "dfshop1"
        child_dir = "dfshop2"
        smbclient_args = self.build_test_cmd("smbclient", ["//%s/%s" % (self.server, self.share), "-c", "cd %s/%s" % (parent_dir,child_dir)])
        try:
            out_str = self.check_output(smbclient_args)
        except BlackboxProcessError as e:
            print(str(e))
            self.fail(str(e))

    def test_enumerate_dfs_link(self):
        smbclient_args = self.build_test_cmd("smbclient", ["//%s/%s" % (self.server, self.share), "-c", "dir"])
        try:
            out_str = self.check_output(smbclient_args)
        except BlackboxProcessError as e:
            print(str(e))
            self.fail(str(e))
        out_str = out_str.decode()
        self.assertIn("msdfs-src1", out_str)