/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-03 16:54:45 UTC
  • mto: (237.7.594 trunk)
  • mto: This revision was merged to the branch mainline in revision 382.
  • Revision ID: teddy@recompile.se-20190303165445-vw9ch8k4o4x1syc8
mandos-ctl: Add test for DumpJSONCmd class

* mandos-ctl (TestDumpJSONCmd): New.

Show diffs side-by-side

added added

removed removed

Lines of Context:
868
868
"""[1:-1]
869
869
        self.assertEqual(output, expected_output)
870
870
 
 
871
class TestDumpJSONCmd(TestCmd):
 
872
    def setUp(self):
 
873
        self.expected_json = {
 
874
            "foo": {
 
875
                "Name": "foo",
 
876
                "KeyID": ("92ed150794387c03ce684574b1139a65"
 
877
                          "94a34f895daaaf09fd8ea90a27cddb12"),
 
878
                "Host": "foo.example.org",
 
879
                "Enabled": True,
 
880
                "Timeout": 300000,
 
881
                "LastCheckedOK": "2019-02-03T00:00:00",
 
882
                "Created": "2019-01-02T00:00:00",
 
883
                "Interval": 120000,
 
884
                "Fingerprint": ("778827225BA7DE539C5A"
 
885
                                "7CFA59CFF7CDBD9A5920"),
 
886
                "CheckerRunning": False,
 
887
                "LastEnabled": "2019-01-03T00:00:00",
 
888
                "ApprovalPending": False,
 
889
                "ApprovedByDefault": True,
 
890
                "LastApprovalRequest": "",
 
891
                "ApprovalDelay": 0,
 
892
                "ApprovalDuration": 1000,
 
893
                "Checker": "fping -q -- %(host)s",
 
894
                "ExtendedTimeout": 900000,
 
895
                "Expires": "2019-02-04T00:00:00",
 
896
                "LastCheckerStatus": 0,
 
897
            },
 
898
            "barbar": {
 
899
                "Name": "barbar",
 
900
                "KeyID": ("0558568eedd67d622f5c83b35a115f79"
 
901
                          "6ab612cff5ad227247e46c2b020f441c"),
 
902
                "Host": "192.0.2.3",
 
903
                "Enabled": True,
 
904
                "Timeout": 300000,
 
905
                "LastCheckedOK": "2019-02-04T00:00:00",
 
906
                "Created": "2019-01-03T00:00:00",
 
907
                "Interval": 120000,
 
908
                "Fingerprint": ("3E393AEAEFB84C7E89E2"
 
909
                                "F547B3A107558FCA3A27"),
 
910
                "CheckerRunning": True,
 
911
                "LastEnabled": "2019-01-04T00:00:00",
 
912
                "ApprovalPending": False,
 
913
                "ApprovedByDefault": False,
 
914
                "LastApprovalRequest": "2019-01-03T00:00:00",
 
915
                "ApprovalDelay": 30000,
 
916
                "ApprovalDuration": 1000,
 
917
                "Checker": ":",
 
918
                "ExtendedTimeout": 900000,
 
919
                "Expires": "2019-02-05T00:00:00",
 
920
                "LastCheckerStatus": -2,
 
921
            },
 
922
        }
 
923
        return super(TestDumpJSONCmd, self).setUp()
 
924
    def test_normal(self):
 
925
        json_data = json.loads(DumpJSONCmd().output(self.clients))
 
926
        self.assertDictEqual(json_data, self.expected_json)
 
927
    def test_one_client(self):
 
928
        clients = {"foo": self.clients["foo"]}
 
929
        json_data = json.loads(DumpJSONCmd().output(clients))
 
930
        expected_json = {"foo": self.expected_json["foo"]}
 
931
        self.assertDictEqual(json_data, expected_json)
871
932
 
872
933
 
873
934
def should_only_run_tests():