472
475
self.assertEquals(self.config.script_users,
473
476
"root, nobody, landscape")
478
def test_query_script_users_defined_on_command_line_with_unknown_user(self):
480
If several users are provided on the command line, we verify the users
481
and raise a ConfigurationError if any are unknown on this system.
483
pwnam_mock = self.mocker.replace("pwd.getpwnam")
485
self.mocker.result(None)
487
self.mocker.result(None)
488
pwnam_mock("landscape")
489
self.mocker.result(None)
490
pwnam_mock("unknown")
491
self.mocker.throw(KeyError())
494
self.config.load_command_line(
495
["--script-users", "root, nobody, landscape, unknown",
496
"--include-manager-plugins", "ScriptPlugin"])
497
self.assertRaises(ConfigurationError, self.script.query_script_plugin)
499
def test_query_script_users_defined_on_command_line_with_all_user(self):
501
We shouldn't accept all as a synonym for ALL
503
self.config.load_command_line(
504
["--script-users", "all",
505
"--include-manager-plugins", "ScriptPlugin"])
506
self.assertRaises(ConfigurationError, self.script.query_script_plugin)
508
def test_query_script_users_defined_on_command_line_with_ALL_user(self):
510
ALL is the special marker for all users.
512
self.config.load_command_line(
513
["--script-users", "ALL",
514
"--include-manager-plugins", "ScriptPlugin"])
515
self.script.query_script_plugin()
516
self.assertEquals(self.config.script_users,
519
def test_query_script_users_defined_on_command_line_with_ALL_and_extra_user(self):
521
If ALL and additional users are provided as the users on the command
522
line, this should raise an appropriate ConfigurationError.
524
self.config.load_command_line(
525
["--script-users", "ALL, kevin",
526
"--include-manager-plugins", "ScriptPlugin"])
527
self.assertRaises(ConfigurationError, self.script.query_script_plugin)
529
def test_invalid_user_entered_by_user(self):
531
If an invalid user is entered on the command line the user should be
532
informed and prompted again.
534
help_snippet = "Landscape has a feature which enables administrators"
536
script_mock = self.mocker.patch(self.script)
537
script_mock.show_help(self.get_matcher(help_snippet))
538
script_mock.prompt_yes_no("Enable script execution?", default=False)
539
self.mocker.result(True)
540
script_mock.show_help(
541
self.get_matcher("By default, scripts are restricted"))
542
script_mock.prompt_get_input("Script users: ", False)
543
self.mocker.result(u"nonexistent")
544
script_mock.show_help("Unknown system users: nonexistent")
545
script_mock.prompt_get_input("Script users: ", False)
546
self.mocker.result(u"root")
548
self.script.query_script_plugin()
549
self.assertEquals(self.config.script_users,
552
def test_tags_not_defined_on_command_line(self):
554
If tags are not provided, the user should be prompted for them.
557
script_mock = self.mocker.patch(self.script)
558
script_mock.show_help("You may provide tags for this computer e.g. "
560
script_mock.prompt("tags", "Tags", False)
562
self.script.query_tags()
564
def test_invalid_tags_entered_by_user(self):
566
If tags are not provided, the user should be prompted for them, and
567
they should be valid tags, if not the user should be prompted for them
570
script_mock = self.mocker.patch(self.script)
571
script_mock.show_help("You may provide tags for this computer e.g. "
573
script_mock.prompt_get_input("Tags: ", False)
574
self.mocker.result(u"<script>alert();</script>")
575
script_mock.show_help("Tag names may only contain alphanumeric "
577
script_mock.prompt_get_input("Tags: ", False)
578
self.mocker.result(u"london")
580
self.script.query_tags()
582
def test_tags_defined_on_command_line(self):
584
Tags defined on the command line can be verified by the user.
586
raw_input_mock = self.mocker.replace(raw_input, passthrough=False)
587
self.expect(raw_input_mock(ANY)).count(0)
589
self.config.load_command_line(["--tags", u"server,london"])
590
self.script.query_tags()
591
self.assertEquals(self.config.tags, u"server,london")
593
def test_invalid_tags_defined_on_command_line_raises_error(self):
594
raw_input_mock = self.mocker.replace(raw_input, passthrough=False)
595
self.expect(raw_input_mock(ANY)).count(0)
597
self.config.load_command_line(["--tags", u"<script>alert();</script>"])
598
self.assertRaises(ConfigurationError, self.script.query_tags)
475
600
def test_show_header(self):
476
601
help_snippet = "This script will"
477
602
script_mock = self.mocker.patch(self.script)