Skip to content

Commit

Permalink
Merge pull request #302 from GoSecure/file-logging-changes
Browse files Browse the repository at this point in the history
File-related logging changes
  • Loading branch information
xshill authored Mar 13, 2021
2 parents cc39d50 + a49d0e8 commit 219cc58
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pyrdp/mitm/FileMapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def write(self, data: bytes):
self.file.write(data)
self.written = True

def getHash(self):
def getSha1Hash(self):
with open(self.dataPath, "rb") as f:
sha1 = hashlib.sha1()

Expand All @@ -57,7 +57,7 @@ def finalize(self):
self.log.debug("Closing file %(path)s", {"path": self.dataPath})
self.file.close()

fileHash = self.getHash()
fileHash = self.getSha1Hash()

# Go up one directory because files are saved to outDir / tmp while we're downloading them
hashPath = (self.dataPath.parents[1] / fileHash)
Expand All @@ -78,8 +78,8 @@ def finalize(self):
# Make the symlink relative so you can move the output folder around and it will still work.
self.filesystemPath.symlink_to(Path(os.path.relpath(hashPath, self.filesystemPath.parent)))

self.log.info("SHA1 '%(path)s' = '%(hash)s'", {
"path": self.filesystemPath.relative_to(self.filesystemDir), "hash": fileHash
self.log.info("SHA1 '%(path)s' = '%(shasum)s'", {
"path": str(self.filesystemPath.relative_to(self.filesystemDir)), "shasum": fileHash
})

@staticmethod
Expand All @@ -94,7 +94,7 @@ def generate(remotePath: str, outDir: Path, filesystemDir: Path, log: LoggerAdap
file = open(handle, "wb")

log.info("Saving file '%(remotePath)s' to '%(localPath)s'", {
"localPath": tmpPath, "remotePath": remotePath
"localPath": str(tmpPath), "remotePath": str(remotePath)
})

return FileMapping(file, Path(tmpPath), filesystemPath, filesystemDir, log)
2 changes: 1 addition & 1 deletion test/test_FileMapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):
def createMapping(self, mkdir: MagicMock, mkstemp: MagicMock, mock_open_object):
mkstemp.return_value = (1, str(self.outDir / "tmp" / "tmp_test"))
mapping = FileMapping.generate("/test", self.outDir, Path("filesystems"), self.log)
mapping.getHash = Mock(return_value = self.hash)
mapping.getSha1Hash = Mock(return_value = self.hash)
return mapping, mkdir, mkstemp, mock_open_object

def test_generate_createsTempFile(self):
Expand Down

0 comments on commit 219cc58

Please sign in to comment.