/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-06 22:07:48 UTC
  • Revision ID: teddy@recompile.se-20190306220748-wfxlbmehw0mny8mn
mandos-ctl: Fix bugs

* mandos-ctl (SetSecretCommand): Argument is file object, not string.
  (commands_from_options): Fix "command" to "commands" throughout. Add
                           option argument to SetCheckerCmd().
  (TestSetSecretCmd): Set file objects, not byte strings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
import json
43
43
import unittest
44
44
import logging
 
45
import io
45
46
 
46
47
import dbus
47
48
 
475
476
    property = "Host"
476
477
 
477
478
class SetSecretCmd(PropertyCmd, ValueArgumentMixIn):
 
479
    @property
 
480
    def value_to_set(self):
 
481
        return self._vts
 
482
    @value_to_set.setter
 
483
    def value_to_set(self, value):
 
484
        """When setting, read data from supplied file object"""
 
485
        self._vts = value.read()
 
486
        value.close()
478
487
    property = "Secret"
479
488
 
480
489
class SetTimeoutCmd(PropertyCmd, MillisecondsValueArgumentMixIn):
609
618
        commands.append(RemoveCmd())
610
619
 
611
620
    if options.checker is not None:
612
 
        commands.append(SetCheckerCmd())
 
621
        commands.append(SetCheckerCmd(options.checker))
613
622
 
614
623
    if options.timeout is not None:
615
624
        commands.append(SetTimeoutCmd(options.timeout))
619
628
            SetExtendedTimeoutCmd(options.extended_timeout))
620
629
 
621
630
    if options.interval is not None:
622
 
        command.append(SetIntervalCmd(options.interval))
 
631
        commands.append(SetIntervalCmd(options.interval))
623
632
 
624
633
    if options.approved_by_default is not None:
625
634
        if options.approved_by_default:
626
 
            command.append(ApproveByDefaultCmd())
 
635
            commands.append(ApproveByDefaultCmd())
627
636
        else:
628
 
            command.append(DenyByDefaultCmd())
 
637
            commands.append(DenyByDefaultCmd())
629
638
 
630
639
    if options.approval_delay is not None:
631
 
        command.append(SetApprovalDelayCmd(options.approval_delay))
 
640
        commands.append(SetApprovalDelayCmd(options.approval_delay))
632
641
 
633
642
    if options.approval_duration is not None:
634
 
        command.append(
 
643
        commands.append(
635
644
            SetApprovalDurationCmd(options.approval_duration))
636
645
 
637
646
    if options.host is not None:
638
 
        command.append(SetHostCmd(options.host))
 
647
        commands.append(SetHostCmd(options.host))
639
648
 
640
649
    if options.secret is not None:
641
 
        command.append(SetSecretCmd(options.secret))
 
650
        commands.append(SetSecretCmd(options.secret))
642
651
 
643
652
    if options.approve:
644
653
        commands.append(ApproveCmd())
1083
1092
class TestSetSecretCmd(TestValueArgumentPropertyCmd):
1084
1093
    command = SetSecretCmd
1085
1094
    property = "Secret"
1086
 
    values_to_set = [b"", b"secret"]
 
1095
    values_to_set = [open("/dev/null", "rb"),
 
1096
                     io.BytesIO(b"secret\0xyzzy\nbar")]
 
1097
    values_to_get = [b"", b"secret\0xyzzy\nbar"]
1087
1098
 
1088
1099
class TestSetTimeoutCmd(TestValueArgumentPropertyCmd):
1089
1100
    command = SetTimeoutCmd