bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
1185.16.127
by Martin Pool
[patch] paramiko sftp tests (robey) |
1 |
# Copyright (C) 2005 Robey Pointer <robey@lag.net>, Canonical Ltd
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
2 |
#
|
|
1185.16.127
by Martin Pool
[patch] paramiko sftp tests (robey) |
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
7 |
#
|
|
1185.16.127
by Martin Pool
[patch] paramiko sftp tests (robey) |
8 |
# This program is distributed in the hope that it will be useful,
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
|
1887.1.1
by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines, |
12 |
#
|
|
1185.16.127
by Martin Pool
[patch] paramiko sftp tests (robey) |
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
|
15 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
16 |
||
17 |
import os |
|
18 |
import socket |
|
19 |
import threading |
|
20 |
||
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
21 |
import bzrlib.bzrdir as bzrdir |
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
22 |
import bzrlib.errors as errors |
|
1530.1.7
by Robert Collins
merge integration. |
23 |
from bzrlib.osutils import pathjoin, lexists |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
24 |
from bzrlib.tests import TestCaseWithTransport, TestCase, TestSkipped |
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
25 |
import bzrlib.transport |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
26 |
from bzrlib.workingtree import WorkingTree |
|
1185.16.127
by Martin Pool
[patch] paramiko sftp tests (robey) |
27 |
|
28 |
try: |
|
29 |
import paramiko |
|
30 |
paramiko_loaded = True |
|
31 |
except ImportError: |
|
32 |
paramiko_loaded = False |
|
33 |
||
|
1530.1.6
by Robert Collins
Trim duplicate sftp tests. |
34 |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
35 |
class TestCaseWithSFTPServer(TestCaseWithTransport): |
|
1530.1.6
by Robert Collins
Trim duplicate sftp tests. |
36 |
"""A test case base class that provides a sftp server on localhost.""" |
|
1185.16.127
by Martin Pool
[patch] paramiko sftp tests (robey) |
37 |
|
38 |
def setUp(self): |
|
|
1532
by Robert Collins
Merge in John Meinels integration branch. |
39 |
if not paramiko_loaded: |
40 |
raise TestSkipped('you must have paramiko to run this test') |
|
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
41 |
super(TestCaseWithSFTPServer, self).setUp() |
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
42 |
from bzrlib.transport.sftp import SFTPAbsoluteServer, SFTPHomeDirServer |
43 |
if getattr(self, '_get_remote_is_absolute', None) is None: |
|
44 |
self._get_remote_is_absolute = True |
|
45 |
if self._get_remote_is_absolute: |
|
46 |
self.transport_server = SFTPAbsoluteServer |
|
47 |
else: |
|
48 |
self.transport_server = SFTPHomeDirServer |
|
49 |
self.transport_readonly_server = bzrlib.transport.http.HttpServer |
|
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
50 |
|
51 |
def get_transport(self, path=None): |
|
52 |
"""Return a transport relative to self._test_root.""" |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
53 |
return bzrlib.transport.get_transport(self.get_url(path)) |
|
1530.1.6
by Robert Collins
Trim duplicate sftp tests. |
54 |
|
55 |
||
56 |
class SFTPLockTests (TestCaseWithSFTPServer): |
|
|
1185.16.127
by Martin Pool
[patch] paramiko sftp tests (robey) |
57 |
|
|
1185.49.3
by John Arbash Meinel
Added a form of locking to sftp branches. Refactored _sftp_open_exclusive to take a relative path |
58 |
def test_sftp_locks(self): |
59 |
from bzrlib.errors import LockError |
|
60 |
t = self.get_transport() |
|
61 |
||
62 |
l = t.lock_write('bogus') |
|
63 |
self.failUnlessExists('bogus.write-lock') |
|
64 |
||
65 |
# Don't wait for the lock, locking an already locked
|
|
66 |
# file should raise an assert
|
|
67 |
self.assertRaises(LockError, t.lock_write, 'bogus') |
|
68 |
||
69 |
l.unlock() |
|
|
1185.31.33
by John Arbash Meinel
A couple more path.join statements needed changing. |
70 |
self.failIf(lexists('bogus.write-lock')) |
|
1185.49.3
by John Arbash Meinel
Added a form of locking to sftp branches. Refactored _sftp_open_exclusive to take a relative path |
71 |
|
72 |
open('something.write-lock', 'wb').write('fake lock\n') |
|
73 |
self.assertRaises(LockError, t.lock_write, 'something') |
|
74 |
os.remove('something.write-lock') |
|
75 |
||
76 |
l = t.lock_write('something') |
|
77 |
||
78 |
l2 = t.lock_write('bogus') |
|
79 |
||
80 |
l.unlock() |
|
81 |
l2.unlock() |
|
82 |
||
|
1185.49.10
by John Arbash Meinel
Use a weakref dictionary to enable re-use of a connection (for sftp). |
83 |
def test_multiple_connections(self): |
84 |
t = self.get_transport() |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
85 |
self.assertTrue('sftpserver - new connection' in self.get_server().logs) |
86 |
self.get_server().logs = [] |
|
|
1185.49.10
by John Arbash Meinel
Use a weakref dictionary to enable re-use of a connection (for sftp). |
87 |
# The second request should reuse the first connection
|
88 |
# SingleListener only allows for a single connection,
|
|
89 |
# So the next line fails unless the connection is reused
|
|
90 |
t2 = self.get_transport() |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
91 |
self.assertEquals(self.get_server().logs, []) |
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
92 |
|
93 |
||
|
1530.1.6
by Robert Collins
Trim duplicate sftp tests. |
94 |
class SFTPTransportTestRelative(TestCaseWithSFTPServer): |
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
95 |
"""Test the SFTP transport with homedir based relative paths.""" |
96 |
||
97 |
def test__remote_path(self): |
|
98 |
t = self.get_transport() |
|
99 |
# try what is currently used:
|
|
100 |
# remote path = self._abspath(relpath)
|
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
101 |
self.assertEqual(self.test_dir + '/relative', t._remote_path('relative')) |
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
102 |
# we dont os.path.join because windows gives us the wrong path
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
103 |
root_segments = self.test_dir.split('/') |
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
104 |
root_parent = '/'.join(root_segments[:-1]) |
105 |
# .. should be honoured
|
|
106 |
self.assertEqual(root_parent + '/sibling', t._remote_path('../sibling')) |
|
107 |
# / should be illegal ?
|
|
108 |
### FIXME decide and then test for all transports. RBC20051208
|
|
109 |
||
|
1530.1.6
by Robert Collins
Trim duplicate sftp tests. |
110 |
|
111 |
class SFTPTransportTestRelative(TestCaseWithSFTPServer): |
|
112 |
"""Test the SFTP transport with homedir based relative paths.""" |
|
113 |
||
114 |
def setUp(self): |
|
115 |
self._get_remote_is_absolute = False |
|
116 |
super(SFTPTransportTestRelative, self).setUp() |
|
117 |
||
|
1524.1.1
by Robert Collins
Test sftp with relative, absolute-in-homedir and absolute-not-in-homedir |
118 |
def test__remote_path_relative_root(self): |
119 |
# relative paths are preserved
|
|
120 |
t = self.get_transport('') |
|
121 |
self.assertEqual('a', t._remote_path('a')) |
|
122 |
||
123 |
||
|
1185.40.4
by Robey Pointer
fix sftp urls to support the ietf draft url spec wrt relative vs absolute sftp urls (this will break existing branch urls); fix username/password parsing in sftp urls; add unit tests to make sure sftp url parsing is working |
124 |
class FakeSFTPTransport (object): |
125 |
_sftp = object() |
|
126 |
fake = FakeSFTPTransport() |
|
127 |
||
128 |
||
|
1185.49.14
by John Arbash Meinel
[merge] bzr.dev |
129 |
class SFTPNonServerTest(TestCase): |
|
1185.58.12
by John Arbash Meinel
Changing so that sftp tests are skipped rather than hidden when paramiko isn't present |
130 |
def setUp(self): |
131 |
TestCase.setUp(self) |
|
132 |
if not paramiko_loaded: |
|
133 |
raise TestSkipped('you must have paramiko to run this test') |
|
134 |
||
|
1185.40.4
by Robey Pointer
fix sftp urls to support the ietf draft url spec wrt relative vs absolute sftp urls (this will break existing branch urls); fix username/password parsing in sftp urls; add unit tests to make sure sftp url parsing is working |
135 |
def test_parse_url(self): |
136 |
from bzrlib.transport.sftp import SFTPTransport |
|
|
1534.1.8
by Robert Collins
Update SFTP Urls as per mailing list thread. |
137 |
s = SFTPTransport('sftp://simple.example.com/home/source', clone_from=fake) |
|
1185.40.4
by Robey Pointer
fix sftp urls to support the ietf draft url spec wrt relative vs absolute sftp urls (this will break existing branch urls); fix username/password parsing in sftp urls; add unit tests to make sure sftp url parsing is working |
138 |
self.assertEquals(s._host, 'simple.example.com') |
|
1185.49.23
by John Arbash Meinel
bugreport from Matthieu Moy: relpath was failing, but throwing an unhelpful exception. |
139 |
self.assertEquals(s._port, None) |
|
1185.48.5
by James Henstridge
Change SFTP url parsing back to treat the path in sftp://host/path as |
140 |
self.assertEquals(s._path, '/home/source') |
|
1185.49.19
by John Arbash Meinel
Testing that sftp.base gets properly sanitized |
141 |
self.failUnless(s._password is None) |
142 |
||
|
1534.1.8
by Robert Collins
Update SFTP Urls as per mailing list thread. |
143 |
self.assertEquals(s.base, 'sftp://simple.example.com/home/source/') |
144 |
||
145 |
s = SFTPTransport('sftp://ro%62ey:h%40t@example.com:2222/~/relative', clone_from=fake) |
|
|
1185.40.4
by Robey Pointer
fix sftp urls to support the ietf draft url spec wrt relative vs absolute sftp urls (this will break existing branch urls); fix username/password parsing in sftp urls; add unit tests to make sure sftp url parsing is working |
146 |
self.assertEquals(s._host, 'example.com') |
147 |
self.assertEquals(s._port, 2222) |
|
148 |
self.assertEquals(s._username, 'robey') |
|
149 |
self.assertEquals(s._password, 'h@t') |
|
|
1185.48.5
by James Henstridge
Change SFTP url parsing back to treat the path in sftp://host/path as |
150 |
self.assertEquals(s._path, 'relative') |
|
1185.33.58
by Martin Pool
[patch] Better error when sftp urls are given with invalid port numbers (Matthieu Moy) |
151 |
|
|
1185.49.19
by John Arbash Meinel
Testing that sftp.base gets properly sanitized |
152 |
# Base should not keep track of the password
|
|
1534.1.8
by Robert Collins
Update SFTP Urls as per mailing list thread. |
153 |
self.assertEquals(s.base, 'sftp://robey@example.com:2222/~/relative/') |
|
1185.49.23
by John Arbash Meinel
bugreport from Matthieu Moy: relpath was failing, but throwing an unhelpful exception. |
154 |
|
155 |
def test_relpath(self): |
|
156 |
from bzrlib.transport.sftp import SFTPTransport |
|
|
1185.31.44
by John Arbash Meinel
Cleaned up Exceptions for all transports. |
157 |
from bzrlib.errors import PathNotChild |
|
1185.49.23
by John Arbash Meinel
bugreport from Matthieu Moy: relpath was failing, but throwing an unhelpful exception. |
158 |
|
|
1534.1.8
by Robert Collins
Update SFTP Urls as per mailing list thread. |
159 |
s = SFTPTransport('sftp://user@host.com/abs/path', clone_from=fake) |
160 |
self.assertEquals(s.relpath('sftp://user@host.com/abs/path/sub'), 'sub') |
|
|
1185.49.23
by John Arbash Meinel
bugreport from Matthieu Moy: relpath was failing, but throwing an unhelpful exception. |
161 |
# Can't test this one, because we actually get an AssertionError
|
162 |
# TODO: Consider raising an exception rather than an assert
|
|
|
1534.1.8
by Robert Collins
Update SFTP Urls as per mailing list thread. |
163 |
#self.assertRaises(PathNotChild, s.relpath, 'http://user@host.com/abs/path/sub')
|
164 |
self.assertRaises(PathNotChild, s.relpath, 'sftp://user2@host.com/abs/path/sub') |
|
165 |
self.assertRaises(PathNotChild, s.relpath, 'sftp://user@otherhost.com/abs/path/sub') |
|
166 |
self.assertRaises(PathNotChild, s.relpath, 'sftp://user@host.com:33/abs/path/sub') |
|
167 |
self.assertRaises(PathNotChild, s.relpath, 'sftp://user@host.com/~/rel/path/sub') |
|
|
1185.49.19
by John Arbash Meinel
Testing that sftp.base gets properly sanitized |
168 |
|
|
1185.49.25
by John Arbash Meinel
Added a couple more test cases, just in case. |
169 |
# Make sure it works when we don't supply a username
|
|
1534.1.8
by Robert Collins
Update SFTP Urls as per mailing list thread. |
170 |
s = SFTPTransport('sftp://host.com/abs/path', clone_from=fake) |
171 |
self.assertEquals(s.relpath('sftp://host.com/abs/path/sub'), 'sub') |
|
|
1185.49.25
by John Arbash Meinel
Added a couple more test cases, just in case. |
172 |
|
173 |
# Make sure it works when parts of the path will be url encoded
|
|
174 |
# TODO: These may be incorrect, we might need to urllib.urlencode() before
|
|
175 |
# we pass the paths into the SFTPTransport constructor
|
|
176 |
s = SFTPTransport('sftp://host.com/dev/,path', clone_from=fake) |
|
177 |
self.assertEquals(s.relpath('sftp://host.com/dev/,path/sub'), 'sub') |
|
178 |
s = SFTPTransport('sftp://host.com/dev/%path', clone_from=fake) |
|
179 |
self.assertEquals(s.relpath('sftp://host.com/dev/%path/sub'), 'sub') |
|
180 |
||
|
1185.33.58
by Martin Pool
[patch] Better error when sftp urls are given with invalid port numbers (Matthieu Moy) |
181 |
def test_parse_invalid_url(self): |
|
1185.31.44
by John Arbash Meinel
Cleaned up Exceptions for all transports. |
182 |
from bzrlib.transport.sftp import SFTPTransport, TransportError |
|
1185.33.58
by Martin Pool
[patch] Better error when sftp urls are given with invalid port numbers (Matthieu Moy) |
183 |
try: |
184 |
s = SFTPTransport('sftp://lilypond.org:~janneke/public_html/bzr/gub', |
|
185 |
clone_from=fake) |
|
186 |
self.fail('expected exception not raised') |
|
|
1185.31.44
by John Arbash Meinel
Cleaned up Exceptions for all transports. |
187 |
except TransportError, e: |
|
1185.33.58
by Martin Pool
[patch] Better error when sftp urls are given with invalid port numbers (Matthieu Moy) |
188 |
self.assertEquals(str(e), |
|
1824.2.1
by Johan Rydberg
Let TransportError inherit BzrNerError. |
189 |
'Transport error: ~janneke: invalid port number ') |
|
1185.33.58
by Martin Pool
[patch] Better error when sftp urls are given with invalid port numbers (Matthieu Moy) |
190 |
|
|
1185.40.4
by Robey Pointer
fix sftp urls to support the ietf draft url spec wrt relative vs absolute sftp urls (this will break existing branch urls); fix username/password parsing in sftp urls; add unit tests to make sure sftp url parsing is working |
191 |
|
|
1185.49.3
by John Arbash Meinel
Added a form of locking to sftp branches. Refactored _sftp_open_exclusive to take a relative path |
192 |
class SFTPBranchTest(TestCaseWithSFTPServer): |
193 |
"""Test some stuff when accessing a bzr Branch over sftp""" |
|
194 |
||
195 |
def test_lock_file(self): |
|
|
1666.1.4
by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in |
196 |
# old format branches use a special lock file on sftp.
|
197 |
b = self.make_branch('', format=bzrdir.BzrDirFormat6()) |
|
198 |
b = bzrlib.branch.Branch.open(self.get_url()) |
|
|
1185.49.3
by John Arbash Meinel
Added a form of locking to sftp branches. Refactored _sftp_open_exclusive to take a relative path |
199 |
self.failUnlessExists('.bzr/') |
200 |
self.failUnlessExists('.bzr/branch-format') |
|
201 |
self.failUnlessExists('.bzr/branch-lock') |
|
202 |
||
|
1185.31.33
by John Arbash Meinel
A couple more path.join statements needed changing. |
203 |
self.failIf(lexists('.bzr/branch-lock.write-lock')) |
|
1185.49.3
by John Arbash Meinel
Added a form of locking to sftp branches. Refactored _sftp_open_exclusive to take a relative path |
204 |
b.lock_write() |
205 |
self.failUnlessExists('.bzr/branch-lock.write-lock') |
|
206 |
b.unlock() |
|
|
1185.31.33
by John Arbash Meinel
A couple more path.join statements needed changing. |
207 |
self.failIf(lexists('.bzr/branch-lock.write-lock')) |
|
1185.49.3
by John Arbash Meinel
Added a form of locking to sftp branches. Refactored _sftp_open_exclusive to take a relative path |
208 |
|
|
1185.49.26
by John Arbash Meinel
Adding tests for remote sftp branches without working trees, plus a bugfix to allow push to still work with a warning. |
209 |
def test_push_support(self): |
210 |
self.build_tree(['a/', 'a/foo']) |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
211 |
t = bzrdir.BzrDir.create_standalone_workingtree('a') |
|
1534.4.26
by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create. |
212 |
b = t.branch |
|
1185.49.26
by John Arbash Meinel
Adding tests for remote sftp branches without working trees, plus a bugfix to allow push to still work with a warning. |
213 |
t.add('foo') |
214 |
t.commit('foo', rev_id='a1') |
|
215 |
||
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
216 |
b2 = bzrdir.BzrDir.create_branch_and_repo(self.get_url('/b')) |
|
1185.49.26
by John Arbash Meinel
Adding tests for remote sftp branches without working trees, plus a bugfix to allow push to still work with a warning. |
217 |
b2.pull(b) |
218 |
||
219 |
self.assertEquals(b2.revision_history(), ['a1']) |
|
220 |
||
|
1185.31.48
by John Arbash Meinel
Added a small test to sftp to make sure some replacing was going on in the remote side. |
221 |
open('a/foo', 'wt').write('something new in foo\n') |
222 |
t.commit('new', rev_id='a2') |
|
223 |
b2.pull(b) |
|
224 |
||
225 |
self.assertEquals(b2.revision_history(), ['a1', 'a2']) |
|
226 |
||
|
1185.49.3
by John Arbash Meinel
Added a form of locking to sftp branches. Refactored _sftp_open_exclusive to take a relative path |
227 |
|
|
1185.49.32
by John Arbash Meinel
Update tests to show that all ssh vendor failed connections work correctly, has some stipple from real ssh |
228 |
class SSHVendorConnection(TestCaseWithSFTPServer): |
229 |
"""Test that the ssh vendors can all connect. |
|
230 |
||
231 |
Verify that a full-handshake (SSH over loopback TCP) sftp connection works.
|
|
232 |
||
233 |
We have 3 sftp implementations in the test suite:
|
|
234 |
'loopback': Doesn't use ssh, just uses a local socket. Most tests are
|
|
235 |
done this way to save the handshaking time, so it is not
|
|
236 |
tested again here
|
|
237 |
'none': This uses paramiko's built-in ssh client and server, and layers
|
|
238 |
sftp on top of it.
|
|
239 |
None: If 'ssh' exists on the machine, then it will be spawned as a
|
|
240 |
child process.
|
|
241 |
"""
|
|
|
1547.1.4
by Robey Pointer
add a single full-handshake test to verify that sftp-over-ssh works |
242 |
|
|
1185.49.32
by John Arbash Meinel
Update tests to show that all ssh vendor failed connections work correctly, has some stipple from real ssh |
243 |
def setUp(self): |
244 |
super(SSHVendorConnection, self).setUp() |
|
|
1534.4.50
by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running. |
245 |
from bzrlib.transport.sftp import SFTPFullAbsoluteServer |
|
1185.49.32
by John Arbash Meinel
Update tests to show that all ssh vendor failed connections work correctly, has some stipple from real ssh |
246 |
|
247 |
def create_server(): |
|
248 |
"""Just a wrapper so that when created, it will set _vendor""" |
|
249 |
# SFTPFullAbsoluteServer can handle any vendor,
|
|
250 |
# it just needs to be set between the time it is instantiated
|
|
251 |
# and the time .setUp() is called
|
|
252 |
server = SFTPFullAbsoluteServer() |
|
253 |
server._vendor = self._test_vendor |
|
254 |
return server |
|
255 |
self._test_vendor = 'loopback' |
|
256 |
self.transport_server = create_server |
|
257 |
f = open('a_file', 'wb') |
|
258 |
try: |
|
259 |
f.write('foobar\n') |
|
260 |
finally: |
|
261 |
f.close() |
|
262 |
||
263 |
def set_vendor(self, vendor): |
|
264 |
self._test_vendor = vendor |
|
265 |
||
266 |
def test_connection_paramiko(self): |
|
267 |
self.set_vendor('none') |
|
268 |
t = self.get_transport() |
|
269 |
self.assertEqual('foobar\n', t.get('a_file').read()) |
|
270 |
||
271 |
def test_connection_vendor(self): |
|
272 |
raise TestSkipped("We don't test spawning real ssh," |
|
273 |
" because it prompts for a password."
|
|
274 |
" Enable this test if we figure out"
|
|
275 |
" how to prevent this.") |
|
276 |
self.set_vendor(None) |
|
277 |
t = self.get_transport() |
|
278 |
self.assertEqual('foobar\n', t.get('a_file').read()) |
|
279 |
||
280 |
||
281 |
class SSHVendorBadConnection(TestCaseWithTransport): |
|
282 |
"""Test that the ssh vendors handle bad connection properly |
|
283 |
||
284 |
We don't subclass TestCaseWithSFTPServer, because we don't actually
|
|
285 |
need an SFTP connection.
|
|
286 |
"""
|
|
287 |
||
288 |
def setUp(self): |
|
289 |
if not paramiko_loaded: |
|
290 |
raise TestSkipped('you must have paramiko to run this test') |
|
291 |
super(SSHVendorBadConnection, self).setUp() |
|
292 |
import bzrlib.transport.sftp |
|
293 |
||
294 |
self._transport_sftp = bzrlib.transport.sftp |
|
295 |
||
|
1185.49.35
by John Arbash Meinel
Update tests to use a truly unused port |
296 |
# open a random port, so we know nobody else is using it
|
297 |
# but don't actually listen on the port.
|
|
298 |
s = socket.socket() |
|
299 |
s.bind(('localhost', 0)) |
|
300 |
self.bogus_url = 'sftp://%s:%s/' % s.getsockname() |
|
|
1185.49.32
by John Arbash Meinel
Update tests to show that all ssh vendor failed connections work correctly, has some stipple from real ssh |
301 |
|
302 |
orig_vendor = bzrlib.transport.sftp._ssh_vendor |
|
|
1185.49.35
by John Arbash Meinel
Update tests to use a truly unused port |
303 |
def reset(): |
|
1185.49.32
by John Arbash Meinel
Update tests to show that all ssh vendor failed connections work correctly, has some stipple from real ssh |
304 |
bzrlib.transport.sftp._ssh_vendor = orig_vendor |
|
1185.49.35
by John Arbash Meinel
Update tests to use a truly unused port |
305 |
s.close() |
306 |
self.addCleanup(reset) |
|
|
1185.49.32
by John Arbash Meinel
Update tests to show that all ssh vendor failed connections work correctly, has some stipple from real ssh |
307 |
|
308 |
def set_vendor(self, vendor): |
|
309 |
self._transport_sftp._ssh_vendor = vendor |
|
310 |
||
311 |
def test_bad_connection_paramiko(self): |
|
312 |
"""Test that a real connection attempt raises the right error""" |
|
313 |
self.set_vendor('none') |
|
314 |
self.assertRaises(errors.ConnectionError, |
|
315 |
bzrlib.transport.get_transport, self.bogus_url) |
|
316 |
||
317 |
def test_bad_connection_ssh(self): |
|
318 |
"""None => auto-detect vendor""" |
|
319 |
self.set_vendor(None) |
|
|
1185.49.33
by John Arbash Meinel
Spawn another bzr instance using run_bzr_subprocess, so we don't get stipple |
320 |
# This is how I would normally test the connection code
|
321 |
# it makes it very clear what we are testing.
|
|
322 |
# However, 'ssh' will create stipple on the output, so instead
|
|
323 |
# I'm using run_bzr_subprocess, and parsing the output
|
|
324 |
# try:
|
|
325 |
# t = bzrlib.transport.get_transport(self.bogus_url)
|
|
326 |
# except errors.ConnectionError:
|
|
327 |
# # Correct error
|
|
328 |
# pass
|
|
329 |
# except errors.NameError, e:
|
|
330 |
# if 'SSHException' in str(e):
|
|
331 |
# raise TestSkipped('Known NameError bug in paramiko 1.6.1')
|
|
332 |
# raise
|
|
333 |
# else:
|
|
334 |
# self.fail('Excepted ConnectionError to be raised')
|
|
335 |
||
336 |
out, err = self.run_bzr_subprocess('log', self.bogus_url, retcode=3) |
|
337 |
self.assertEqual('', out) |
|
338 |
if "NameError: global name 'SSHException'" in err: |
|
339 |
# We aren't fixing this bug, because it is a bug in
|
|
340 |
# paramiko, but we know about it, so we don't have to
|
|
341 |
# fail the test
|
|
342 |
raise TestSkipped('Known NameError bug with paramiko-1.6.1') |
|
343 |
self.assertContainsRe(err, 'Connection error') |
|
|
1185.49.32
by John Arbash Meinel
Update tests to show that all ssh vendor failed connections work correctly, has some stipple from real ssh |
344 |