Пример #1
0
	def test_redact_will_redact_the_password(self):
		the_password="******"
		wrapper = HubDetectWrapper(self.fake_url)
		options=["--blackduck.password={}".format(the_password)]
		redacted_options = wrapper._redact(options)

		self.assertTrue(the_password not in redacted_options)
Пример #2
0
	def test_confirm_subprocess_options_when_authenticating_with_token(self):
		wrapper = HubDetectWrapper(self.fake_url, blackduck_token="the-token")

		subprocess_options = wrapper._determine_subprocess_options()
		self.assertTrue("--blackduck.username=the-username" not in subprocess_options)		
		self.assertTrue("--blackduck.password=the-password" not in subprocess_options)		
		self.assertTrue("--blackduck.api.token=the-token" in subprocess_options)
Пример #3
0
	def test_redact_will_redact_the_auth_token(self):
		the_token="the-token"
		wrapper = HubDetectWrapper(self.fake_url)
		options=["--blackduck.api.token={}".format(the_token)]
		redacted_options = wrapper._redact(options)

		self.assertTrue(the_token not in redacted_options)
Пример #4
0
	def test_adjust_detect_options_for_backwards_compatibility(self):
		wrapper = HubDetectWrapper(self.fake_url)

		input_options = [
			Path('/tmp/hub-detect.sh'),
			'--blackduck.url={}'.format(self.fake_url), 
			'--blackduck.username=a_user', 
			'--blackduck.password=a_password', 
			'--blackduck.trust.cert=true', 
			'--blackduck.api.timeout', 
			'--detect.api.timeout', 
			'--detect.policy.check.fail.on.severities=ALL'
		]
		expected_options_old_versions = [
			Path('/tmp/hub-detect.sh'),
			'--blackduck.hub.url={}'.format(self.fake_url), 
			'--blackduck.hub.username=a_user', 
			'--blackduck.hub.password=a_password', 
			'--blackduck.hub.trust.cert=true', 
			'--blackduck.hub.api.timeout', 
			'--detect.api.timeout', 
			'--detect.policy.check.fail.on.severities=ALL'
		]
		options_and_versions = {
			'4.4.1' : {'input': input_options, 'expected': input_options},
			'4.2.0' : {'input': input_options, 'expected': input_options},
			'4.1.0' : {'input': input_options, 'expected': expected_options_old_versions},
			'3.0.1' : {'input': input_options, 'expected': expected_options_old_versions},
		}

		for version_str, inputs_and_expected in options_and_versions.items():
			resulting_options = wrapper._adjust_detect_options_for_backwards_compatibility(inputs_and_expected['input'], version_str)
			assert resulting_options == inputs_and_expected['expected']
Пример #5
0
	def test_run_detect_with_no_detect_version_specified(self):
		output_dir="/tmp/output_dir"
		detect_log_path = output_dir + "/detect.log"
		wrapper = HubDetectWrapper(self.fake_url, detect_log_path=output_dir)

		subprocess_options = ["env"] # this is a contrived set of subprocess options
		result = wrapper._run_detect(subprocess_options)

		self.assertEqual(result.returncode, 0)
		# Need to adjust this with any new version that is added to the list
		self.assertEqual(wrapper.detect_version, "4.4.1")
		self.assertEqual(wrapper.hub_detect_path, "hub-detect-4.4.1.jar")
		self.assertTrue(os.path.isfile(detect_log_path))
Пример #6
0
	def check_the_parsing(self, test_d, method_to_test):
		wrapper = HubDetectWrapper(self.fake_url)
		for detect_log_file, expected_value in test_d:
			with open(detect_log_file, 'r') as f:
				detect_output = f.read()
				method_to_call = getattr(wrapper, method_to_test)
				result_d = method_to_call(detect_output)
				# print(result_d)
				self.assertEqual(result_d, expected_value)
Пример #7
0
	def test_get_detect_path(self):
		expected_paths = {
			"4.4.1": "hub-detect-4.4.1.jar",
			"4.3.0": "hub-detect-4.3.0.jar",
			"3.1.1": "hub-detect-3.1.1.jar"
		}
		for version, path in expected_paths.items():
			wrapper = HubDetectWrapper(self.fake_url, detect_version=version)
			self.assertEqual(wrapper.detect_version, version)
			self.assertEqual(wrapper.hub_detect_path, path)
Пример #8
0
	def test_parse_detect_output_to_get_results_returns_all_keys_all_the_time(self):
		ALL_RESULT_KEYS=[
			'overall_status', 
			'policy_violation', 
			'elapsed_time_from_detect', 
			'components_in_violation', 
			'components_in_violation_overridden', 
			'components_not_in_violation',
			'total_components',
			'local_processing',
			'server_processing',
			]

		for detect_log_file in self.detect_test_log_files:
			with open(detect_log_file, 'r') as f:
				detect_output = f.read()
				wrapper = HubDetectWrapper(self.fake_url)
				results = wrapper._parse_detect_output_to_get_results(detect_output, 'dummy-path')
				# print(results)
				self.assertTrue(all([key in results for key in ALL_RESULT_KEYS]))
Пример #9
0
    def detect_worker(self, test_project_d, iterations, test_config_d):
        logging.debug(
            "starting %s iterations to analyze project %s with config %s" %
            (iterations, test_project_d, test_config_d))
        folder = test_project_d['folder']
        project_name = test_project_d['project_name']
        version = test_project_d['version']
        # relocate the output files if a base dir was specified
        if self.detect_output_base_dir:
            output_path = os.path.join(self.detect_output_base_dir, folder)
        else:
            output_path = folder
        options = [
            '--detect.project.name=%s' % project_name,
            '--detect.project.version.name=%s' % version,
            '--detect.source.path=%s' % folder,
            '--detect.output.path=%s_output' % output_path,
        ]
        options.extend(self.detect_options)
        for i in range(iterations):
            logging.debug('iteration %s for project %s' %
                          (i + 1, test_project_d))

            # using hard-coded hub detect version for now since the newest version, v3.2.0 breaks some things
            hub_detect_wrapper = HubDetectWrapper(
                self.hub_url,
                self.hub_user,
                self.hub_password,
                additional_detect_options=options,
                detect_path="./hub-detect-3.1.1.jar")
            thread_project_results = hub_detect_wrapper.run()
            thread_project_results.update(test_config_d)
            self.results.append(thread_project_results)
            logging.debug('results for project %s are %s' %
                          (test_project_d, thread_project_results))
        logging.debug(
            "thread exiting after performing %s iterations on project %s" %
            (iterations, test_project_d))
Пример #10
0
	def test_output_dir_returns_output_path_from_detect_options_if_no_log_given(self):
		wrapper = HubDetectWrapper(self.fake_url)

		output_dir = "/var/log/output_dir"
		self.assertEqual(wrapper._output_dir(["--detect.output.path={}".format(output_dir)]), output_dir)	
Пример #11
0
	def test_output_dir_returns_detect_log_path_if_one_was_given(self):
		output_dir = "/var/log/output_dir"
		wrapper = HubDetectWrapper(self.fake_url, detect_log_path=output_dir)

		self.assertEqual(wrapper._output_dir([]), output_dir)
Пример #12
0
	def test_init_requires_url(self):
		with self.assertRaises(TypeError):
			wrapper = HubDetectWrapper()

		wrapper = HubDetectWrapper(self.fake_url)