def mode(self): # Respect umask instead of the file mode stored in the archive. # The only bit used from the embedded mode is the executable bit for files. umask = utils.get_umask() if self.isdir() or bool(self.__permission & 0o100): return 0o777 & ~umask else: return 0o666 & ~umask
def __init__(self, cache): self.root = os.path.abspath(cache) os.makedirs(cache, exist_ok=True) # Use the same sources every time self.sources = os.path.join(self.root, "sources") # Create a temp directory for the duration of the test for # the artifacts directory try: self.cachedir = tempfile.mkdtemp(dir=self.root, prefix="cache-") # Apply mode allowed by umask os.chmod(self.cachedir, 0o777 & ~utils.get_umask()) except OSError as e: raise AssertionError("Unable to create test directory !") from e
def test_simple_file_build(cli, tmpdir, datafiles): project = str(datafiles) generate_project(project, {"aliases": { "tmpdir": "file:///" + str(tmpdir) }}) checkoutdir = os.path.join(str(tmpdir), "checkout") # Try to fetch it result = cli.run(project=project, args=["source", "fetch", "target.bst"]) result.assert_success() result = cli.run(project=project, args=["build", "target.bst"]) result.assert_success() result = cli.run(project=project, args=[ "artifact", "checkout", "target.bst", "--directory", checkoutdir ]) result.assert_success() # Note that the url of the file in target.bst is actually /dir/file # but this tests confirms we take the basename checkout_file = os.path.join(checkoutdir, "file") assert os.path.exists(checkout_file) mode = os.stat(checkout_file).st_mode # Assert not executable by anyone assert not mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH) # Assert not writeable by anyone other than me (unless umask allows it) if utils.get_umask() & stat.S_IWGRP: assert not mode & stat.S_IWGRP if utils.get_umask() & stat.S_IWOTH: assert not mode & stat.S_IWOTH
def test_pull_access_rights(cli, tmpdir, datafiles): project = str(datafiles) checkout = os.path.join(str(tmpdir), "checkout") umask = utils.get_umask() # Work-around datafiles not preserving mode os.chmod(os.path.join(project, "files/bin-files/usr/bin/hello"), 0o0755) # We need a big file that does not go into a batch to test a different # code path os.makedirs(os.path.join(project, "files/dev-files/usr/share"), exist_ok=True) with open(os.path.join(project, "files/dev-files/usr/share/big-file"), "w", encoding="utf-8") as f: buf = " " * 4096 for _ in range(1024): f.write(buf) with create_artifact_share(os.path.join(str(tmpdir), "artifactshare")) as share: cli.configure( {"artifacts": { "servers": [{ "url": share.repo, "push": True }] }}) result = cli.run(project=project, args=["build", "compose-all.bst"]) result.assert_success() result = cli.run( project=project, args=[ "artifact", "checkout", "--no-integrate", "compose-all.bst", "--directory", checkout ], ) result.assert_success() st = os.lstat(os.path.join(checkout, "usr/include/pony.h")) assert stat.S_ISREG(st.st_mode) assert stat.S_IMODE(st.st_mode) == 0o0666 & ~umask st = os.lstat(os.path.join(checkout, "usr/bin/hello")) assert stat.S_ISREG(st.st_mode) assert stat.S_IMODE(st.st_mode) == 0o0777 & ~umask st = os.lstat(os.path.join(checkout, "usr/share/big-file")) assert stat.S_ISREG(st.st_mode) assert stat.S_IMODE(st.st_mode) == 0o0666 & ~umask shutil.rmtree(checkout) casdir = os.path.join(cli.directory, "cas") shutil.rmtree(casdir) result = cli.run(project=project, args=["artifact", "pull", "compose-all.bst"]) result.assert_success() result = cli.run( project=project, args=[ "artifact", "checkout", "--no-integrate", "compose-all.bst", "--directory", checkout ], ) result.assert_success() st = os.lstat(os.path.join(checkout, "usr/include/pony.h")) assert stat.S_ISREG(st.st_mode) assert stat.S_IMODE(st.st_mode) == 0o0666 & ~umask st = os.lstat(os.path.join(checkout, "usr/bin/hello")) assert stat.S_ISREG(st.st_mode) assert stat.S_IMODE(st.st_mode) == 0o0777 & ~umask st = os.lstat(os.path.join(checkout, "usr/share/big-file")) assert stat.S_ISREG(st.st_mode) assert stat.S_IMODE(st.st_mode) == 0o0666 & ~umask