Esempio n. 1
0
    def testBigIno(self):
        """Test that index handles big inode numbers as found on Windows"""

        s = MagicMock()
        s.st_mode = 33188
        s.st_ino = -5345198597064824875
        s.st_dev = 65027
        s.st_nlink = 1
        s.st_uid = 1000
        s.st_gid = 1000
        s.st_size = 3
        s.st_atime = 1452798827
        s.st_mtime = 1452798827
        s.st_ctime = 1452798827
        mock_lstat = MagicMock()
        mock_lstat.return_value = s

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "ghost"), 'wb') as f:
                    f.write(b'abc')

                with patch('os.lstat', mock_lstat):
                    hashDirectory(tmp, index.name)

                with open(index.name, "rb") as f:
                    assert f.read(4) == b'BOB1'
Esempio n. 2
0
    def testBigIno(self):
        """Test that index handles big inode numbers as found on Windows"""

        s = MagicMock()
        s.st_mode=33188
        s.st_ino=-5345198597064824875
        s.st_dev=65027
        s.st_nlink=1
        s.st_uid=1000
        s.st_gid=1000
        s.st_size=3
        s.st_atime=1452798827
        s.st_mtime=1452798827
        s.st_ctime=1452798827
        mock_lstat = MagicMock()
        mock_lstat.return_value = s

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "ghost"), 'wb') as f:
                    f.write(b'abc')

                with patch('os.lstat', mock_lstat):
                    hashDirectory(tmp, index.name)

                with open(index.name, "rb") as f:
                    assert f.read(4) == b'BOB1'
Esempio n. 3
0
    def testRenameFile(self):
        """Test that renaming files has an influence on the checksum"""

        with TemporaryDirectory() as tmp:
            with open(os.path.join(tmp, "foo"), 'wb') as f:
                f.write(b'abc')

            sum1 = hashDirectory(tmp)
            os.rename(os.path.join(tmp, "foo"), os.path.join(tmp, "bar"))
            sum2 = hashDirectory(tmp)
            assert sum1 != sum2
Esempio n. 4
0
    def testRenameFile(self):
        """Test that renaming files has an influence on the checksum"""

        with TemporaryDirectory() as tmp:
            with open(os.path.join(tmp, "foo"), 'wb') as f:
                f.write(b'abc')

            sum1 = hashDirectory(tmp)
            os.rename(os.path.join(tmp, "foo"), os.path.join(tmp, "bar"))
            sum2 = hashDirectory(tmp)
            assert sum1 != sum2
Esempio n. 5
0
    def testBlockDev(self):
        """Test that index handles block devices"""

        s = MagicMock()
        s.st_mode = 25008
        s.st_ino = 8325
        s.st_dev = 6
        s.st_nlink = 1
        s.st_uid = 0
        s.st_gid = 6
        s.st_rdev = 2048
        s.st_size = 0
        s.st_atime = 1453317243
        s.st_mtime = 1451854748
        s.st_ctime = 1451854748
        mock_lstat = MagicMock()
        mock_lstat.return_value = s

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "sda"), 'wb') as f:
                    pass

                with patch('os.lstat', mock_lstat):
                    h = hashDirectory(tmp, index.name)

        assert h == b'\xe8\x8e\xad\x9bv\xcbt\xc4\xcd\xa7x\xdb\xde\x96\xab@\x18\xb1\xdcX'
Esempio n. 6
0
    def testBlockDev(self):
        """Test that index handles block devices"""

        s = MagicMock()
        s.st_mode = 25008
        s.st_ino = 8325
        s.st_dev = 6
        s.st_nlink = 1
        s.st_uid = 0
        s.st_gid = 6
        s.st_rdev = 2048
        s.st_size = 0
        s.st_atime_ns = 1453317243
        s.st_mtime_ns = 1451854748
        s.st_ctime_ns = 1451854748
        mock_lstat = MagicMock()
        mock_lstat.return_value = s
        entry = MagicMock()
        entry.is_dir = MagicMock(return_value=False)
        entry.name = b'sda'
        entry.stat = mock_lstat
        entries = MagicMock()
        entries.return_value = [entry]

        with NamedTemporaryFile() as index:
            with patch('os.scandir', entries):
                h = hashDirectory("whatever", index.name)

        self.assertEqual(
            h,
            b'\xe8\x8e\xad\x9bv\xcbt\xc4\xcd\xa7x\xdb\xde\x96\xab@\x18\xb1\xdcX'
        )
Esempio n. 7
0
    def testChrDev(self):
        """Test that index handles character devices"""

        s = MagicMock()
        s.st_mode=8630
        s.st_ino=8325
        s.st_dev=6
        s.st_nlink=1
        s.st_uid=0
        s.st_gid=6
        s.st_rdev=1280
        s.st_size=0
        s.st_atime=1453317243
        s.st_mtime=1451854748
        s.st_ctime=1451854748
        mock_lstat = MagicMock()
        mock_lstat.return_value = s

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "tty"), 'wb') as f:
                    pass

                with patch('os.lstat', mock_lstat):
                    h = hashDirectory(tmp, index.name)

        assert h == b"\x9b\x98~\xa5\xd5\xc4\x1e\xe29'\x8d\x1e\xe1\x12\xdd\xf4\xa51\xf5d"
Esempio n. 8
0
    def testBlockDev(self):
        """Test that index handles block devices"""

        s = MagicMock()
        s.st_mode=25008
        s.st_ino=8325
        s.st_dev=6
        s.st_nlink=1
        s.st_uid=0
        s.st_gid=6
        s.st_rdev=2048
        s.st_size=0
        s.st_atime=1453317243
        s.st_mtime=1451854748
        s.st_ctime=1451854748
        mock_lstat = MagicMock()
        mock_lstat.return_value = s

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "sda"), 'wb') as f:
                    pass

                with patch('os.lstat', mock_lstat):
                    h = hashDirectory(tmp, index.name)

        assert h == b'\xe8\x8e\xad\x9bv\xcbt\xc4\xcd\xa7x\xdb\xde\x96\xab@\x18\xb1\xdcX'
Esempio n. 9
0
    def testChrDev(self):
        """Test that index handles character devices"""

        s = MagicMock()
        s.st_mode = 8630
        s.st_ino = 8325
        s.st_dev = 6
        s.st_nlink = 1
        s.st_uid = 0
        s.st_gid = 6
        s.st_rdev = 1280
        s.st_size = 0
        s.st_atime_ns = 1453317243
        s.st_mtime_ns = 1451854748
        s.st_ctime_ns = 1451854748
        mock_lstat = MagicMock()
        mock_lstat.return_value = s
        entry = MagicMock()
        entry.is_dir = MagicMock(return_value=False)
        entry.name = b'tty'
        entry.stat = mock_lstat
        entries = MagicMock()
        entries.return_value = [entry]

        with NamedTemporaryFile() as index:
            with patch('os.scandir', entries):
                h = hashDirectory("whatever", index.name)

        self.assertEqual(
            h,
            b"\x9b\x98~\xa5\xd5\xc4\x1e\xe29'\x8d\x1e\xe1\x12\xdd\xf4\xa51\xf5d"
        )
Esempio n. 10
0
    def testChrDev(self):
        """Test that index handles character devices"""

        s = MagicMock()
        s.st_mode = 8630
        s.st_ino = 8325
        s.st_dev = 6
        s.st_nlink = 1
        s.st_uid = 0
        s.st_gid = 6
        s.st_rdev = 1280
        s.st_size = 0
        s.st_atime = 1453317243
        s.st_mtime = 1451854748
        s.st_ctime = 1451854748
        mock_lstat = MagicMock()
        mock_lstat.return_value = s

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "tty"), 'wb') as f:
                    pass

                with patch('os.lstat', mock_lstat):
                    h = hashDirectory(tmp, index.name)

        assert h == b"\x9b\x98~\xa5\xd5\xc4\x1e\xe29'\x8d\x1e\xe1\x12\xdd\xf4\xa51\xf5d"
Esempio n. 11
0
    def testOldFile(self):
        """Test negative time fields for files from the past"""

        s = MagicMock()
        s.st_mode = 33188
        s.st_ino = 270794
        s.st_dev = 65026
        s.st_nlink = 1
        s.st_uid = 1000
        s.st_gid = 1000
        s.st_size = 4
        s.st_atime_ns = 1601623698
        s.st_mtime_ns = -3600
        s.st_ctime_ns = 1601623698
        mock_lstat = MagicMock()
        mock_lstat.return_value = s

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "McFly"), 'wb') as f:
                    pass

                with patch('os.lstat', mock_lstat):
                    h = hashDirectory(tmp, index.name)
                with patch('os.stat', mock_lstat):
                    b = binStat("whatever")

        self.assertEqual(
            h,
            b'\xdc\xe1\xf4\x02\x01\xc3\xa1\xf7j\xac\xbc\xbf=1ey\x11\x1a\xc8\xda'
        )
        self.assertEqual(type(b), bytes)
Esempio n. 12
0
    def testDirAndFile(self):
        """Test hashing a directory with one file.

        The hash sum should stay stable in the long run as this might be used
        for binary artifact matching in the future.
        """

        with TemporaryDirectory() as tmp:
            os.mkdir(os.path.join(tmp, "dir"))
            with open(os.path.join(tmp, "dir", "file"), 'wb') as f:
                f.write(b'abc')

            sum1 = hashDirectory(tmp)
            assert len(sum1) == 20
            assert sum1 == binascii.unhexlify(
                "640f516de78fba0b6d2ddde4451000f142d06b0d")
            sum2 = hashDirectory(tmp)
            assert sum1 == sum2
Esempio n. 13
0
 def testPrune(self):
     """Test that pruning destination works if requested"""
     s = self.createImportScm({"prune": True})
     with tempfile.TemporaryDirectory() as workspace:
         canary = os.path.join(workspace, "test.txt")
         with open(canary, "w") as f:
             f.write("Changed")
         self.invokeScm(workspace, s)
         self.assertEqual(self.digest, hashDirectory(workspace))
Esempio n. 14
0
    def testDirAndFile(self):
        """Test hashing a directory with one file.

        The hash sum should stay stable in the long run as this might be used
        for binary artifact matching in the future.
        """

        with TemporaryDirectory() as tmp:
            os.mkdir(os.path.join(tmp, "dir"))
            with open(os.path.join(tmp, "dir", "file"), 'wb') as f:
                f.write(b'abc')

            sum1 = hashDirectory(tmp)
            assert len(sum1) == 20
            assert sum1 == binascii.unhexlify(
                "640f516de78fba0b6d2ddde4451000f142d06b0d")
            sum2 = hashDirectory(tmp)
            assert sum1 == sum2
Esempio n. 15
0
    def testRewriteFile(self):
        """Changing the file content should change the hash sum"""

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "foo"), 'wb') as f:
                    f.write(b'abc')
                sum1 = hashDirectory(tmp, index.name)

                with open(index.name, "rb") as f:
                    assert f.read(4) == b'BOB1'

                with open(os.path.join(tmp, "foo"), 'wb') as f:
                    f.write(b'qwer')
                sum2 = hashDirectory(tmp, index.name)

                with open(index.name, "rb") as f:
                    assert f.read(4) == b'BOB1'

                assert sum1 != sum2
Esempio n. 16
0
    def testRewriteFile(self):
        """Changing the file content should change the hash sum"""

        with NamedTemporaryFile() as index:
            with TemporaryDirectory() as tmp:
                with open(os.path.join(tmp, "foo"), 'wb') as f:
                    f.write(b'abc')
                sum1 = hashDirectory(tmp, index.name)

                with open(index.name, "rb") as f:
                    assert f.read(4) == b'BOB1'

                with open(os.path.join(tmp, "foo"), 'wb') as f:
                    f.write(b'qwer')
                sum2 = hashDirectory(tmp, index.name)

                with open(index.name, "rb") as f:
                    assert f.read(4) == b'BOB1'

                assert sum1 != sum2
Esempio n. 17
0
    def setUpClass(cls):
        cls.__repodir = tempfile.TemporaryDirectory()
        cls.url = os.path.abspath(cls.__repodir.name)

        cls.fn = os.path.join(cls.url, "test.txt")
        with open(cls.fn, "w") as f:
            f.write("Hello world!")
        os.symlink("test.txt", os.path.join(cls.url, "link.txt"))

        os.mkdir(os.path.join(cls.url, "sub"))
        with open(os.path.join(cls.url, "sub", "sub.txt"), "w") as f:
            f.write("Nested")

        cls.digest = hashDirectory(cls.url)
Esempio n. 18
0
 def testCopyViaProperties(self):
     """Test Jenkins-like 'checkout' via properties"""
     s = ImportScm(self.createImportScm().getProperties())
     with tempfile.TemporaryDirectory() as workspace:
         self.invokeScm(workspace, s)
         self.assertEqual(self.digest, hashDirectory(workspace))
Esempio n. 19
0
 def testCopy(self):
     """Test straigt forward 'checkout'"""
     s = self.createImportScm()
     with tempfile.TemporaryDirectory() as workspace:
         self.invokeScm(workspace, s)
         self.assertEqual(self.digest, hashDirectory(workspace))