示例#1
0
 def test_summary_report_output_directory(self):
     """Testing fail because output directory."""
     with self.assertRaises(SystemExit):
         sys.argv = [
             '/bin/qpc', 'report', 'summary', '--json', '--output-file', '/'
         ]
         CLI().main()
示例#2
0
 def test_add_req_args_err(self):
     """Testing the add credential command required flags."""
     with self.assertRaises(SystemExit):
         sys.argv = [
             '/bin/qpc', 'credential', 'add', '--name', 'credential1'
         ]
         CLI().main()
示例#3
0
 def test_download_output_directory_not_exist(self):
     """Testing fail because output directory does not exist."""
     with self.assertRaises(SystemExit):
         sys.argv = [
             '/bin/qpc', 'report', 'download', '--output-file', '/foo/bar/'
         ]
         CLI().main()
示例#4
0
 def test_detail_report_output_file_empty(self):
     """Testing fail because output file empty."""
     with self.assertRaises(SystemExit):
         sys.argv = [
             '/bin/qpc', 'report', 'detail', '--json', '--output-file', ''
         ]
         CLI().main()
示例#5
0
 def test_add_no_type(self):
     """Testing the add credential without type flag."""
     with self.assertRaises(SystemExit):
         sys.argv = ['/bin/qpc', 'credential',
                     'add', '--name', 'credential1',
                     '--username', 'foo', '--password']
         CLI().main()
 def test_config_server_default_port(self):
     """Testing the configure server default port."""
     sys.argv = ['/bin/qpc', 'server', 'config', '--host', '127.0.0.1']
     CLI().main()
     config = read_server_config()
     self.assertEqual(config['host'], '127.0.0.1')
     self.assertEqual(config['port'], 8000)
示例#7
0
 def test_insights_publish_returning_error(  # pylint: disable=too-many-arguments
     self,
     payload_file,
     patched_insights_config,
     patched_insights_credentials,
     caplog,
     requests_mock,
     status_code,
     log_message,
 ):
     """Testing insights publish with several errors."""
     caplog.set_level("ERROR")
     requests_mock.post(
         f"https://insights.test:1111{INGRESS_REPORT_URI}",
         status_code=status_code,
     )
     sys.argv = [
         "/bin/qpc",
         "insights",
         "publish",
         "--input-file",
         str(payload_file),
     ]
     with pytest.raises(SystemExit):
         CLI().main()
     assert caplog.messages[-1] == log_message
    def test_run_command_no_config(self):
        """Test running command without config."""
        write_server_config({})

        with self.assertRaises(SystemExit):
            sys.argv = ['/bin/qpc', 'cred']
            CLI().main()
示例#9
0
 def test_write_status_output_directory_not_exist(self):
     """Testing fail because output directory does not exist."""
     with self.assertRaises(SystemExit):
         sys.argv = [
             '/bin/qpc', 'server', 'status', '--output-file', '/foo/bar/'
         ]
         CLI().main()
示例#10
0
 def test_add_process_file(self):
     """Testing the add source command process file."""
     with self.assertRaises(SystemExit):
         sys.argv = ['/bin/qpc', 'source', 'add', '--name', 'source1',
                     '--type', 'network',
                     '--hosts', TMP_HOSTFILE, '--cred', 'cred1']
         CLI().main()
示例#11
0
 def test_version(self):
     """Testing the verion argument."""
     version_out = StringIO()
     with self.assertRaises(SystemExit):
         with redirect_stdout(version_out):
             sys.argv = ['/bin/qpc', '--version']
             CLI().main()
             self.assertEqual(version_out.getvalue(), '0.0.41')
示例#12
0
 def test_insights_config_default_host(self):
     """Testing insights configure default host."""
     sys.argv = ["/bin/qpc", "insights", "config", "--port", "200"]
     CLI().main()
     config = read_insights_config()
     self.assertEqual(config["host"], DEFAULT_HOST_INSIGHTS_CONFIG)
     self.assertEqual(config["port"], 200)
     self.assertEqual(config["use_http"], DEFAULT_USE_HTTP_INSIGHTS_CONFIG)
示例#13
0
 def test_download_report_empty(self):
     """Testing fail because output file empty."""
     with self.assertRaises(SystemExit):
         sys.argv = [
             '/bin/qpc', 'report', 'download', '--report', '',
             '--output-file', 'test.json'
         ]
         CLI().main()
示例#14
0
 def test_insights_config_default_port(self):
     """Testing insights configure default port."""
     sys.argv = ["/bin/qpc", "insights", "config", "--host", "console.insights.test"]
     CLI().main()
     config = read_insights_config()
     self.assertEqual(config["host"], "console.insights.test")
     self.assertEqual(config["port"], DEFAULT_PORT_INSIGHTS_CONFIG)
     self.assertEqual(config["use_http"], DEFAULT_USE_HTTP_INSIGHTS_CONFIG)
示例#15
0
 def test_config_host_alpha_port_err(self):
     """Testing the configure server requires bad port."""
     with self.assertRaises(SystemExit):
         sys.argv = [
             '/bin/qpc', 'server', 'config', '--host', '127.0.0.1',
             '--port', 'abc'
         ]
         CLI().main()
示例#16
0
 def test_success_config_server(self):
     """Testing the configure server green path."""
     sys.argv = ['/bin/qpc', 'server', 'config',
                 '--host', '127.0.0.1', '--port', '8005']
     CLI().main()
     config = read_server_config()
     self.assertEqual(config['host'], '127.0.0.1')
     self.assertEqual(config['port'], 8005)
示例#17
0
 def test_edit_req_args_err(self):
     """Testing the credential edit command required flags."""
     cred_out = StringIO()
     with self.assertRaises(SystemExit):
         with redirect_stdout(cred_out):
             sys.argv = [
                 '/bin/qpc', 'credential', 'edit', '--name', 'credential1'
             ]
             CLI().main()
示例#18
0
    def test_invalid_configuration(self):
        """Test reading bad JSON on cli start."""
        write_server_config({})

        sys.argv = ['/bin/qpc', 'server', 'config', '--host', '127.0.0.1']
        CLI().main()
        config = read_server_config()
        self.assertEqual(config['host'], '127.0.0.1')
        self.assertEqual(config['port'], 8000)
示例#19
0
 def test_edit_req_args_err(self):
     """Testing the edit command required flags."""
     source_out = StringIO()
     with self.assertRaises(SystemExit):
         with redirect_stdout(source_out):
             sys.argv = ['/bin/qpc', 'scan', 'edit', '--name', 'scan1']
             CLI().main()
             self.assertEqual(source_out.getvalue(),
                              'No arguments provided to edit '
                              'scan scan1')
示例#20
0
    def test_add_bad_key(self):
        """Testing the add credential command.

        When providing an invalid path for the sshkeyfile.
        """
        cred_out = StringIO()
        with self.assertRaises(SystemExit):
            with redirect_stdout(cred_out):
                sys.argv = ['/bin/qpc', 'credential', 'add',
                            '--name', 'credential1',
                            '--username', 'root', '--sshkeyfile', 'bad_path']
                CLI().main()
示例#21
0
    def tearDown(self):
        """Remove test case setup."""
        # Reset server config to default ip/port
        sys.argv = ['/bin/qpc', 'server', 'config',
                    '--host', '127.0.0.1', '--port', '443']

        CLI().main()
        config = read_server_config()
        self.assertEqual(config['host'], '127.0.0.1')
        self.assertEqual(config['port'], 443)

        # Restore stderr
        sys.stderr = self.orig_stderr
示例#22
0
 def test_invalid_payload_file(self, payload, caplog, log_message):
     """Test invalid tar.gz payloads."""
     caplog.set_level("INFO")
     sys.argv = [
         "/bin/qpc",
         "insights",
         "publish",
         "--input-file",
         str(payload),
     ]
     with pytest.raises(SystemExit):
         CLI().main()
     assert caplog.messages[-1] == log_message
示例#23
0
 def test_success_config_server(self):
     """Testing the configure server green path."""
     config_out = StringIO()
     sys.argv = ['/bin/qpc', 'server', 'config',
                 '--host', '127.0.0.1', '--port', '8005']
     with redirect_stdout(config_out):
         CLI().main()
         config = read_server_config()
         self.assertEqual(config['host'], '127.0.0.1')
         self.assertEqual(config['port'], 8005)
         self.assertEqual(config_out.getvalue(),
                          messages.SERVER_CONFIG_SUCCESS % ('https',
                                                            '127.0.0.1',
                                                            '8005') + '\n')
示例#24
0
 def test_validate_report_name_if_not_file(self, tmp_path, caplog):
     """Testing if insights publish --input-file will accept dir as file."""
     caplog.set_level("INFO")
     sys.argv = [
         "/bin/qpc",
         "insights",
         "publish",
         "--input-file",
         tmp_path.name,
     ]
     with pytest.raises(SystemExit):
         CLI().main()
     assert caplog.messages[
         -1] == messages.INSIGHTS_LOCAL_REPORT_NOT % tmp_path.name
示例#25
0
 def test_success_add_insights_login_config(self):
     """Testing insights login config green path."""
     sys.argv = [
         "/bin/qpc",
         "insights",
         "add_login",
         "--username",
         "insights-test-user",
         "--password",
         "insights-test-password",
     ]
     CLI().main()
     config = read_insights_login_config()
     self.assertEqual(config["username"], "insights-test-user")
     self.assertEqual(config["password"], "insights-test-password")
示例#26
0
    def test_edit_bad_key(self):
        """Testing the credential edit command.

        When providing an invalid path for the sshkeyfile.
        """
        cred_out = StringIO()
        with self.assertRaises(SystemExit):
            with redirect_stdout(cred_out):
                sys.argv = ['/bin/qpc', 'credential', 'edit',
                            '--name', 'cred1',
                            '--sshkeyfile', 'bad_path']
                CLI().main()
                self.assertTrue('Please provide a valid location for the '
                                '"--sshkeyfile" argument.'
                                in cred_out.getvalue())
示例#27
0
 def test_success_config_insights(self):
     """Testing insights configure green path."""
     sys.argv = [
         "/bin/qpc",
         "insights",
         "config",
         "--host",
         "console.insights.test",
         "--port",
         "200",
         "--use-http",
     ]
     CLI().main()
     config = read_insights_config()
     self.assertEqual(config["host"], "console.insights.test")
     self.assertEqual(config["port"], 200)
     self.assertEqual(config["use_http"], True)
示例#28
0
    def tearDown(self):
        """Remove test case setup."""
        # Reset server config to default ip/port
        config_out = StringIO()
        sys.argv = ['/bin/qpc', 'server', 'config',
                    '--host', '127.0.0.1', '--port', str(DEFAULT_PORT)]

        with redirect_stdout(config_out):
            CLI().main()
            config = read_server_config()
            self.assertEqual(config['host'], '127.0.0.1')
            self.assertEqual(config['port'], DEFAULT_PORT)
            self.assertEqual(config_out.getvalue(),
                             messages.SERVER_CONFIG_SUCCESS % ('https',
                                                               '127.0.0.1',
                                                               str(DEFAULT_PORT)) + '\n')
        # Restore stderr
        sys.stderr = self.orig_stderr
示例#29
0
 def test_validate_report_name_if_invalid_name(
     self,
     inapropriate_payload_file: tempfile.NamedTemporaryFile,
     caplog,
 ):
     """Testing if--input-file will accept files with inappropriate extensions."""
     caplog.set_level("INFO")
     sys.argv = [
         "/bin/qpc",
         "insights",
         "publish",
         "--input-file",
         inapropriate_payload_file.name,
     ]
     with pytest.raises(SystemExit):
         CLI().main()
     assert (
         caplog.messages[-1] == messages.INSIGHTS_LOCAL_REPORT_NOT_TAR_GZ %
         inapropriate_payload_file.name)
示例#30
0
 def test_insights_publish_successful(  # pylint: disable=too-many-arguments
     self,
     payload_file,
     patched_insights_config,
     patched_insights_credentials,
     caplog,
     requests_mock,
 ):
     """Testing insights publish --input-file green path."""
     caplog.set_level("INFO")
     requests_mock.post(
         f"https://insights.test:1111{INGRESS_REPORT_URI}",
         status_code=202,
     )
     sys.argv = [
         "/bin/qpc",
         "insights",
         "publish",
         "--input-file",
         str(payload_file),
     ]
     CLI().main()
     assert caplog.messages[-1] == messages.INSIGHTS_PUBLISH_SUCCESSFUL