コード例 #1
0
    def test_missing_host_parameter(self):
        result = run_check('ssh-fingerprint', {
            'PORT': 3223,
            'EXPECTED_FINGERPRINT': 'SOME FINGERPRINT THAT DOES NOT MATCH SERVER FINGERPRINT'
        }, {})

        self.assertIn('You need to provide a HOST', result.output.strip())
        self.assertFalse(result.exit_status)
コード例 #2
0
    def test_reports_stderr_messages(self):
        result = run_check('ssh-fingerprint', {
            'HOST': 'non-existing-host',
            'PORT': 3223,
            'EXPECTED_FINGERPRINT': 'BAKUNIN'
        }, {})

        self.assertIn('getaddrinfo non-existing-host', result.output.strip())
        self.assertFalse(result.exit_status)
コード例 #3
0
    def test_invalid_fingerprint(self):
        result = run_check('ssh-fingerprint', {
            'HOST': '127.0.0.1',
            'PORT': 3223,
            'EXPECTED_FINGERPRINT': 'SOME FINGERPRINT THAT DOES NOT MATCH SERVER FINGERPRINT'
        }, {})

        self.assertIn('Fingerprint does not match', result.output.strip())
        self.assertFalse(result.exit_status)
コード例 #4
0
    def test_success_case(self):
        # we create SSH server for testing dynamically in a docker container, so each time it has a different identity
        current_expected_fingerprint = self.get_current_ssh_server_fingerprint()

        result = run_check('ssh-fingerprint', {
            'HOST': '127.0.0.1',
            'PORT': 3223,
            'EXPECTED_FINGERPRINT': current_expected_fingerprint
        }, {})

        self.assertEqual('Fingerprint is OK', result.output.strip())
        self.assertTrue(result.exit_status)
コード例 #5
0
    def test_success_case(self):
        result = run_check('ssh-files-checksum', {
            'HOST': '127.0.0.1',
            'PORT': 3223,
            'USER': '******',
            'PASSWORD': '******',
            'SSH_OPTS': '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null',
            'EXPECTS': {
                "/dev/null": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
            }
        }, {})

        self.assertEqual('All checksums are matching', result.output.strip())
        self.assertTrue(result.exit_status)
コード例 #6
0
    def test_at_least_one_checksum_not_matching(self):
        result = run_check('ssh-files-checksum', {
            'HOST': '127.0.0.1',
            'PORT': 3223,
            'USER': '******',
            'PASSWORD': '******',
            'SSH_OPTS': '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null',
            'EXPECTS': {
                "/dev/null": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
                "/bin/sh": "will-not-match-this-one"
            }
        }, {})

        self.assertIn("FAIL: '/bin/sh' checksum is not matching. Expected: 'will-not-match-this-one'", result.output.strip())
        self.assertFalse(result.exit_status)
コード例 #7
0
    def test_invalid_password(self):
        result = run_check(
            'ssh-command', {
                'HOST':
                '127.0.0.1',
                'PORT':
                3223,
                'USER':
                '******',
                'PASSWORD':
                '******',
                'SSH_OPTS':
                '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
            }, {})

        self.assertIn('Permission denied, please try again.',
                      result.output.strip())
        self.assertFalse(result.exit_status)
コード例 #8
0
    def test_fingerprint_will_be_fetched_first_time(self):
        known_hosts_file = NamedTemporaryFile(delete=False)

        result = run_check(
            'ssh-command',
            {
                'HOST': '127.0.0.1',
                'PORT': 3223,
                'USER': '******',
                'PASSWORD': '******',
                'KNOWN_HOSTS_FILE': known_hosts_file.name,
                'SSH_OPTS': '',  # there is no StrictHostKeyChecking turned off
                'COMMAND': 'ls -la'
            },
            {})

        os.unlink(known_hosts_file.name)

        self.assertEqual('OK', result.output.strip())
        self.assertTrue(result.exit_status)
コード例 #9
0
    def test_success_case(self):
        """
        Simple success case with expected keywords usage
        :return:
        """

        result = run_check(
            'ssh-command', {
                'HOST': '127.0.0.1',
                'PORT': 3223,
                'USER': '******',
                'PASSWORD': '******',
                'SSH_OPTS':
                '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null',
                'COMMAND': 'uname -a',
                'EXPECTED_KEYWORDS': 'Linux',
                'UNEXPECTED_KEYWORDS': 'Darwin'
            }, {})

        self.assertEqual('OK', result.output.strip())
        self.assertTrue(result.exit_status)
コード例 #10
0
    def test_not_passed_host_raises_human_readable_message(self):
        result = run_check('ssh-files-checksum', {}, {})

        self.assertIn('HOST is mandatory', result.output.strip())
        self.assertFalse(result.exit_status)