def upload_source_files(db, arun_dirpath, source_files): file_collection = db['source_files'] build_results_conf = confreader.read_conf_into_dict( osp.join(arun_dirpath, 'build.conf')) build_results_archive = osp.join(arun_dirpath, build_results_conf['build-archive']) utillib.unpack_archive(build_results_archive, arun_dirpath) build_dir = osp.join( arun_dirpath, osp.join(build_results_conf.get('build-root-dir', 'build'), 'pkg1')) for srcfile in source_files: if osp.isfile(osp.join(build_dir, srcfile)): try: with open(osp.join(build_dir, srcfile), 'rb') as fobj: _bytes = fobj.read() sha1 = hashlib.sha1() sha1.update(_bytes) sha1_digest = sha1.hexdigest() file_collection.insert_one({ 'sha1_digest': sha1_digest, 'file_content': _bytes.decode('utf-8') }) file_mapping[srcfile.replace(".", "_dot_")] = sha1_digest except UnicodeDecodeError as err: print(err) print(traceback.print_exc(limit=5))
def upload_source_files(db, arun_dirpath, source_files): file_collection = db['source_files'] build_results_conf = confreader.read_conf_into_dict(osp.join(arun_dirpath, 'build.conf')) build_results_archive = osp.join(arun_dirpath, build_results_conf['build-archive']) utillib.unpack_archive(build_results_archive, arun_dirpath) build_dir = osp.join(arun_dirpath, osp.join(build_results_conf.get('build-root-dir', 'build'), 'pkg1')) for srcfile in source_files: if osp.isfile(osp.join(build_dir, srcfile)): try: with open(osp.join(build_dir, srcfile), 'rb') as fobj: _bytes = fobj.read() sha1 = hashlib.sha1() sha1.update(_bytes) sha1_digest = sha1.hexdigest(); file_collection.insert_one({'sha1_digest' : sha1_digest, 'file_content' : _bytes.decode('utf-8')}) file_mapping[srcfile.replace(".", "_dot_")] = sha1_digest except UnicodeDecodeError as err: print(err) print(traceback.print_exc(limit=5))
def test_get_run_assess9(self): pkg_conf = osp.join(osp.dirname(__file__), 'resources/test_packages/railsgoat-9052b4fcf0/package.conf') pkg_archive = osp.join(osp.dirname(__file__), 'resources/test_packages/railsgoat-9052b4fcf0/railsgoat-9052b4fcf0.zip') pkg_deps = osp.join(osp.dirname(__file__), 'resources/test_packages/railsgoat-9052b4fcf0/pkg-os-dependencies.conf') pkg_deps_dict = {k.partition('dependencies-')[2]: v for k,v in read_conf_into_dict(pkg_deps).items() if k.startswith('dependencies-')} pkg_uuid = TestAssess.API_WRAPPER.uploadPackage(pkg_conf, pkg_archive, TestSwampApiWrapper.PROJECT, pkg_deps_dict, True) self.assertIsNotNone(pkg_uuid) TestAssess.PKG_LIST.append(pkg_uuid) tool = TestAssess.API_WRAPPER.getToolFromName('Brakeman', TestSwampApiWrapper.PROJECT) arun_uuid = TestAssess.API_WRAPPER.runAssessment(pkg_uuid, [tool.getIdentifierString()], TestSwampApiWrapper.PROJECT, None) self.assertIsNotNone(arun_uuid)
def get_pkg_name_version(arun_dirpath): basename = osp.basename(arun_dirpath) pkg_name = osp.basename(osp.normpath(arun_dirpath)).split('---')[0] pkgs_base_dir = os.environ['PACKAGES_DIR'] if osp.join(pkgs_base_dir, pkg_name): pkg_conf_file = osp.join(osp.join(pkgs_base_dir, pkg_name), 'package.conf') pkg_conf = confreader.read_conf_into_dict(pkg_conf_file) return (pkg_conf['package-short-name'], pkg_conf['package-version'])
def setUpClass(cls): try: config_file = osp.join(osp.dirname(__file__), 'resources/development.properties') user_conf = read_conf_into_dict(config_file) except IOError as err: print('''Please create "%s" with USERNAME=<swamp-username> PASSWORD=<swamp-password> PROJECT=<test-project-uuid> ''' % config_file) raise err TestSwampApiWrapper.USERNAME = user_conf['USERNAME'] TestSwampApiWrapper.PASSWORD = user_conf['PASSWORD'] # Please enter your default project TestSwampApiWrapper.PROJECT = user_conf.get('PROJECT', '5bf4d93c-2945-42d0-9311-6507518219f3') TestSwampApiWrapper.HOST = 'https://dt.cosalab.org'
def __init__(self, config_file): try: if config_file and osp.isfile(config_file): self.config_file = config_file else: self.config_file = osp.join(osp.dirname(__file__), 'resources/userinfo.properties') self.user_conf = read_conf_into_dict(self.config_file) except IOError as err: print('''Please create "%s" with username=<swamp-username> password=<swamp-password> project=<test-project-uuid> hostname=<swamp-hostname> ''' % config_file) raise err self.api_wrapper = SwampApiWrapper()
def test_upload_new_pkg9(self): pkg_conf = osp.join(osp.dirname(__file__), 'resources/test_packages/railsgoat-9052b4fcf0/package.conf') pkg_archive = osp.join(osp.dirname(__file__), 'resources/test_packages/railsgoat-9052b4fcf0/railsgoat-9052b4fcf0.zip') pkg_deps = osp.join(osp.dirname(__file__), 'resources/test_packages/railsgoat-9052b4fcf0/pkg-os-dependencies.conf') pkg_deps_dict = {k.partition('dependencies-')[2]: v for k,v in read_conf_into_dict(pkg_deps).items() if k.startswith('dependencies-')} pkg_uuid = TestUpload.api_wrapper.uploadPackage(pkg_conf, pkg_archive, TestSwampApiWrapper.PROJECT, pkg_deps_dict, True) self.assertIsNotNone(pkg_uuid) TestUpload.PKG_LIST.append(pkg_uuid)
def setUpClass(cls): try: config_file = osp.join(osp.dirname(__file__), 'resources/userinfo.properties') user_conf = read_conf_into_dict(config_file) except IOError as err: print('''Please create "%s" with username=<swamp-username> password=<swamp-password> project=<test-project-uuid> hostname=<swamp-hostname> ''' % config_file) raise err TestSwampApiWrapper.USERNAME = user_conf['username'] TestSwampApiWrapper.PASSWORD = user_conf['password'] # Please enter your default project TestSwampApiWrapper.PROJECT = user_conf['project'] #TestSwampApiWrapper.HOST = 'https://dt.cosalab.org' TestSwampApiWrapper.HOST = user_conf.get('hostname', 'https://www.mir-swamp.org')