Merge lp:~cjwatson/txpkgupload/sftp-interface-oopses into lp:txpkgupload

Proposed by Colin Watson on 2015-01-23
Status: Merged
Merged at revision: 23
Proposed branch: lp:~cjwatson/txpkgupload/sftp-interface-oopses
Merge into: lp:txpkgupload
Diff against target: 98 lines (+56/-3)
2 files modified
src/txpkgupload/tests/test_plugin.py (+41/-0)
src/txpkgupload/twistedsftp.py (+15/-3)
To merge this branch: bzr merge lp:~cjwatson/txpkgupload/sftp-interface-oopses
Reviewer Review Type Date Requested Status
William Grant code 2015-01-23 Approve on 2015-02-03
Review via email: mp+247459@code.launchpad.net

Commit Message

Stub out openDirectory and getAttrs properly to avoid OOPSes with certain clients.

Description of the Change

Stub out openDirectory and getAttrs properly to avoid OOPSes with certain clients.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/txpkgupload/tests/test_plugin.py'
2--- src/txpkgupload/tests/test_plugin.py 2015-01-21 13:07:32 +0000
3+++ src/txpkgupload/tests/test_plugin.py 2015-01-23 17:46:57 +0000
4@@ -43,6 +43,7 @@
5 FileTransferClient,
6 FXF_CREAT,
7 FXF_EXCL,
8+ FXF_READ,
9 FXF_TRUNC,
10 FXF_WRITE,
11 )
12@@ -678,3 +679,43 @@
13 """
14
15 server_factory = SFTPServer
16+
17+ @defer.inlineCallbacks
18+ def test_stat(self):
19+ """Check that attribute retrieval doesn't give anything away."""
20+ client = yield self.server.getClient()
21+ yield self.server.createFile(client, "foo/bar/baz", "fake contents")
22+ attrs = yield client.getAttrs("foo/bar/baz")
23+ self.assertEqual({}, attrs)
24+
25+ yield self.server.disconnect(client)
26+ yield self.server.waitForClose()
27+
28+ @defer.inlineCallbacks
29+ def test_fstat(self):
30+ """Check that file attribute retrieval doesn't give anything away."""
31+ client = yield self.server.getClient()
32+ yield self.server.createFile(client, "foo/bar/baz", "fake contents")
33+ remote_file = yield client.openFile("foo/bar/baz", FXF_READ, {})
34+ attrs = yield remote_file.getAttrs()
35+ self.assertEqual({}, attrs)
36+ yield remote_file.close()
37+
38+ yield self.server.disconnect(client)
39+ yield self.server.waitForClose()
40+
41+ @defer.inlineCallbacks
42+ def test_openDirectory(self):
43+ """Check that opening a directory doesn't give anything away."""
44+ client = yield self.server.getClient()
45+ yield self.server.createFile(client, "foo/bar/baz", "fake contents")
46+ directory = yield client.openDirectory(".")
47+ try:
48+ entry = yield directory.next()
49+ raise AssertionError("Directory not empty")
50+ except EOFError:
51+ pass
52+ yield directory.close()
53+
54+ yield self.server.disconnect(client)
55+ yield self.server.waitForClose()
56
57=== modified file 'src/txpkgupload/twistedsftp.py'
58--- src/txpkgupload/twistedsftp.py 2015-01-22 11:29:37 +0000
59+++ src/txpkgupload/twistedsftp.py 2015-01-23 17:46:57 +0000
60@@ -64,10 +64,10 @@
61 self.uploadfilesystem.rmdir(path)
62
63 def openDirectory(self, path):
64- pass
65+ return SFTPDirectory()
66
67 def getAttrs(self, path, follow_links):
68- pass
69+ return {}
70
71 def setAttrs(self, path, attrs):
72 pass
73@@ -123,12 +123,24 @@
74 os.close(chunk_file)
75
76 def getAttrs(self):
77- pass
78+ return {}
79
80 def setAttrs(self, attr):
81 pass
82
83
84+class SFTPDirectory:
85+
86+ def __iter__(self):
87+ return self
88+
89+ def next(self):
90+ raise StopIteration
91+
92+ def close(self):
93+ pass
94+
95+
96 class PkgUploadFileTransferServer(FileTransferServer):
97
98 def __init__(self, data=None, avatar=None):

Subscribers

People subscribed via source and target branches

to all changes: