def test_ec2reporter_cycle(live_server, tmpdir, fm_user, monkeypatch): """Test EC2Reporter cycle""" monkeypatch.setattr( os.path, 'expanduser', lambda path: tmpdir.strpath) # ensure fuzzmanager config is not used monkeypatch.setattr(time, 'sleep', lambda t: None) config = utils.create_config('testconfig') pool = utils.create_pool(config, last_cycled=timezone.now()) # create a reporter url = urlsplit(live_server.url) reporter = EC2Reporter(sigCacheDir=tmpdir.mkdir('sigcache').strpath, serverHost=url.hostname, serverPort=url.port, serverProtocol=url.scheme, serverAuthToken=fm_user.token, clientId='host1') with pytest.raises( RuntimeError, message= "Server unexpectedly responded with status code 405: Not acceptable" ): reporter.cycle(pool.pk) pool.isEnabled = True pool.save() reporter.cycle(pool.pk) pool = InstancePool.objects.get(pk=pool.pk) # re-read assert pool.isEnabled assert pool.last_cycled is None
def test_ec2reporter_cycle(mock_expanduser, live_server, tmp_path, fm_user): """Test EC2Reporter cycle""" mock_expanduser.side_effect = lambda path: str( tmp_path) # ensure fuzzmanager config is not used config = create_config('testconfig') pool = create_pool(config, last_cycled=timezone.now()) # create a reporter url = urlsplit(live_server.url) sigcache_path = tmp_path / 'sigcache' sigcache_path.mkdir() reporter = EC2Reporter(sigCacheDir=str(sigcache_path), serverHost=url.hostname, serverPort=url.port, serverProtocol=url.scheme, serverAuthToken=fm_user.token, clientId='host1') with pytest.raises( RuntimeError, message= "Server unexpectedly responded with status code 405: Not acceptable" ): reporter.cycle(pool.pk) pool.isEnabled = True pool.save() reporter.cycle(pool.pk) pool = InstancePool.objects.get(pk=pool.pk) # re-read assert pool.isEnabled assert pool.last_cycled is None
def main(): # pylint: disable=missing-docstring print_machine_info() options = parseOpts() collector = create_collector.make_collector() try: collector.refresh() except RuntimeError: print() print( "Unable to find required entries in FuzzManager. Duplicate detection via sigcache will not work..." ) options.tempDir = tempfile.mkdtemp("fuzzbot") print(options.tempDir) build_info = ensureBuild(options) assert build_info.buildDir.is_dir() number_of_processes = multiprocessing.cpu_count() if "-asan" in str(build_info.buildDir): # This should really be based on the amount of RAM available, but I don't know how to compute that in Python. # I could guess 1 GB RAM per core, but that wanders into sketchyville. number_of_processes = max(number_of_processes // 2, 1) try: EC2Reporter().report( f"About to start fuzzing {number_of_processes} \n" f" {options.build_options.build_options_str} \n" f" with target time {options.targetTime} \n" f" and jsfunfuzz timeout of {options.timeout} ...") except RuntimeError: # Ignore errors if the server is temporarily unavailable print("Failed to contact server") fork_join.forkJoin(options.tempDir, number_of_processes, loopFuzzingAndReduction, options, build_info, collector) try: EC2Reporter().report("Fuzzing has finished...") except RuntimeError: # Ignore errors if the server is temporarily unavailable print("Failed to contact server") shutil.rmtree(options.tempDir)
def test_ec2reporter_report(live_server, tmpdir, fm_user, monkeypatch): '''Test report submission''' monkeypatch.setattr( os.path, 'expanduser', lambda path: tmpdir.strpath) # ensure fuzzmanager config is not used monkeypatch.setattr(time, 'sleep', lambda t: None) # create an instance host = utils.create_instance('host1') # create a reporter url = urlsplit(live_server.url) reporter = EC2Reporter(sigCacheDir=tmpdir.mkdir('sigcache').strpath, serverHost=url.hostname, serverPort=url.port, serverProtocol=url.scheme, serverAuthToken=fm_user.token, clientId='host1') reporter.report('data') host = Instance.objects.get(pk=host.pk) # re-read assert host.status_data == 'data' reporter.report(None) host = Instance.objects.get(pk=host.pk) # re-read assert host.status_data is None reporter = EC2Reporter(sigCacheDir=tmpdir.join('sigcache').strpath, serverHost=url.hostname, serverPort=url.port, serverProtocol=url.scheme, serverAuthToken=fm_user.token, clientId='host2') with pytest.raises( RuntimeError, message= "Server unexpectedly responded with status code 404: Not found"): reporter.report('data')
def test_ec2reporter_report(mock_expanduser, live_server, tmp_path, fm_user): '''Test report submission''' mock_expanduser.side_effect = lambda path: str( tmp_path) # ensure fuzzmanager config is not used # create an instance host = create_instance('host1') # create a reporter url = urlsplit(live_server.url) sigcache_path = tmp_path / 'sigcache' sigcache_path.mkdir() reporter = EC2Reporter(sigCacheDir=str(sigcache_path), serverHost=url.hostname, serverPort=url.port, serverProtocol=url.scheme, serverAuthToken=fm_user.token, clientId='host1') reporter.report('data') host = Instance.objects.get(pk=host.pk) # re-read assert host.status_data == 'data' reporter.report(None) host = Instance.objects.get(pk=host.pk) # re-read assert host.status_data is None reporter = EC2Reporter(sigCacheDir=str(sigcache_path), serverHost=url.hostname, serverPort=url.port, serverProtocol=url.scheme, serverAuthToken=fm_user.token, clientId='host2') with pytest.raises( RuntimeError, message= "Server unexpectedly responded with status code 404: Not found"): reporter.report('data')