[merge] SFTP tests run and pass on win32

Robey Pointer robey at lag.net
Fri Jun 30 00:52:09 BST 2006


On 29 Jun 2006, at 14:37, John Arbash Meinel wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> The attached bundle changes how the StubSFTPServer works when on
> Windows, so that it can talk back and forth for the test suite.

[...]

> === modified file 'bzrlib/tests/stub_sftp.py'
> --- bzrlib/tests/stub_sftp.py	2006-06-15 21:16:20 +0000
> +++ bzrlib/tests/stub_sftp.py	2006-06-29 04:07:43 +0000
> @@ -22,6 +22,7 @@
>  import os
>  from paramiko import ServerInterface, SFTPServerInterface,  
> SFTPServer, SFTPAttributes, \
>      SFTPHandle, SFTP_OK, AUTH_SUCCESSFUL, OPEN_SUCCEEDED
> +import sys
>
>  from bzrlib.osutils import pathjoin
>  from bzrlib.trace import mutter
> @@ -64,17 +65,40 @@
>
>      def __init__(self, server, root, home=None):
>          SFTPServerInterface.__init__(self, server)
> +        # All paths are actually relative to 'root'.
> +        # this is like implementing chroot().
>          self.root = root
>          if home is None:
> +            # XXX: if 'home' is None, shouldn't it
> +            #       be set to '', since it should
> +            #       be relative to 'root'?
>              self.home = self.root

You're right here.  This should be: self.home = ''


>          else:
> +            assert home.startswith(self.root), \
> +                    "home must be a subdirectory of root (%s vs % 
> s)" \
> +                    % (home, root)
>              self.home = home[len(self.root):]
> -        if (len(self.home) > 0) and (self.home[0] == '/'):
> +        if self.home.startswith('/'):
>              self.home = self.home[1:]
>          server._test_case.log('sftpserver - new connection')
>
>      def _realpath(self, path):
> -        return self.root + self.canonicalize(path)
> +        if sys.platform == 'win32':
> +            # Win32 sftp paths end up looking like
> +            # sftp://host@foo/h:/foo/bar
> +            # which gets translated here to:
> +            # /h:/foo/bar
> +            # Local paths stay 'foo/bar', though.
> +            # Also, win32 needs to use the Unicode APIs.
> +            thispath = path.decode('utf8')
> +            if path.startswith('/'):
> +                # Abspath
> +                realpath = os.path.normpath(thispath[1:])
> +            else:
> +                realpath = os.path.normpath(os.path.join 
> (self.home, thispath))
> +        else:
> +            realpath = self.root + self.canonicalize(path)
> +        return realpath

I think theoretically most of this logic should be in canonicalize,  
since the sftp server calls 'canonicalize' to do all (sftp path ->  
local path) translation.  It probably doesn't matter here since we're  
using this only for tests and there are therefore no security  
issues.  It would matter for things like chdir and symlinks.

Btw, I'm embarrassed to say that I just did a little research and  
found out that "canonicalize" isn't a word.  I think I wanted  
"canonize".  And now it's enshrined in an API.  Doh.

I only looked at the sftp-related sections, but aside from the  
comments above, they looked fine.

robey





More information about the bazaar mailing list