libsecurity: Simplify struct ace_condition_script
[Samba.git] / python / samba / tests / blackbox / traffic_replay.py
blob835c248f0d9f1e1954ed1ae338930568292afb22
1 # Black box tests for script/traffic_leaner
3 # Copyright (C) Catalyst IT Ltd. 2017
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Blackbox tests for traffic_replay"""
20 import os
21 import tempfile
23 from samba.tests import BlackboxTestCase
25 DATA_DIR = "python/samba/tests/blackbox/testdata"
26 SCRIPT = "script/traffic_replay"
27 FIXED = "--fixed-password=trafficreplay01%"
28 SERVER = os.environ["SERVER"]
29 PASSWORD = os.environ["PASSWORD"]
30 USER = os.environ["USERNAME"]
31 CREDS = "-U%s%%%s" % (USER, PASSWORD)
32 MODEL = os.path.join(DATA_DIR, "traffic-sample-very-short.model")
33 EXPECTED_OUTPUT = os.path.join(DATA_DIR, "traffic_replay-%s.expected")
36 class TrafficLearnerTests(BlackboxTestCase):
38 def tearDown(self):
39 options = "--clean-up"
40 command = "%s %s %s %s" % (SCRIPT, options, CREDS, SERVER)
41 self.check_run(command)
43 def test_generate_users_only(self):
44 """Ensure the generate users only option functions correctly
45 """
46 options = ("--generate-users-only --number-of-users 20 "
47 "--number-of-groups 5 --average-groups-per-user 2")
48 command = "%s %s %s %s %s" % (
49 SCRIPT, options, FIXED, CREDS, SERVER)
50 self.check_run(command)
51 command = "%s %s %s %s %s %s" % (
52 SCRIPT, MODEL, options, FIXED, CREDS, SERVER)
53 self.check_run(command)
55 def test_summary_generation(self):
56 """Ensure a summary file is generated and the contents are correct"""
58 for i, opts in enumerate((["--random-seed=3"],
59 ["--random-seed=4"],
60 ["--random-seed=3",
61 "--conversation-persistence=0.5"],
62 ["--random-seed=3",
63 "--old-scale",
64 "--conversation-persistence=0.95"],
65 )):
66 with self.mktemp() as output:
67 command = ([SCRIPT, MODEL,
68 "--traffic-summary", output,
69 "-D1", "-S0.1"] +
70 opts +
71 [FIXED, CREDS, SERVER])
72 self.check_run(command)
73 expected = open(EXPECTED_OUTPUT % i).read()
74 actual = open(output).read()
75 self.assertStringsEqual(expected, actual)
77 def test_summary_replay_no_fixed(self):
78 """Ensure a summary file with no fixed password fails
79 """
80 command = [SCRIPT, MODEL, CREDS, SERVER]
81 self.check_exit_code(command, 1)
83 def test_model_replay(self):
84 """Ensure a model can be replayed against a DC
85 """
86 command = [SCRIPT, MODEL,
87 FIXED,
88 '-D2', '-S0.1',
89 CREDS, SERVER]
90 self.check_run(command)
92 def test_generate_users_only_no_password(self):
93 """Ensure the generate users only fails if no fixed_password supplied"
94 """
95 options = ("--generate-users-only --number-of-users 20 "
96 "--number-of-groups 5 --average-groups-per-user 2")
97 command = "%s %s %s %s" % (SCRIPT, options, CREDS, SERVER)
98 self.check_exit_code(command, 1)
99 command = "%s %s %s %s %s" % (SCRIPT, MODEL, options, CREDS, SERVER)
100 self.check_exit_code(command, 1)