Commit Graph

25 Commits

Author SHA1 Message Date
Augie Fackler
a343277143 test-url: move from dict() construction to {} literals
The latter are both faster and more consistent across Python 2 and 3.
2014-03-12 13:21:17 -04:00
Matt Mackall
e82c2e671f merge with stable 2011-12-05 17:48:40 -06:00
Patrick Mezard
3a0effcd7b util: fix url.__str__() for windows file URLs
Before:

  >>> str(url('file:///c:/tmp/foo/bar'))
  'file:c%3C/tmp/foo/bar'

After:

  >>> str(url('file:///c:/tmp/foo/bar'))
  'file:///c%3C/tmp/foo/bar'

The previous behaviour had no effect on mercurial itself (clone command for
instance) because we fortunately called .localpath() on the parsed URL.
hgsubversion was not so lucky and cloning a local subversion repository on
Windows no longer worked on the default branch (it works on stable because
2b62605189dc defeats the hasdriveletter() test in url class).

I do not know if the %3C is correct or not but svn accepts file:// URLs
containing it. Mads fixed it in 2b62605189dc, so we can always backport should
the need arise.
2011-12-04 18:22:25 +01:00
Mads Kiilerich
5d7000644a url: handle file://localhost/c:/foo "correctly"
The path was parsed correctly, but localpath prepended an extra '/' (as in
'/c:/foo') because it assumed it was an absolute unix path.
2011-11-16 00:10:56 +01:00
Matt Mackall
75db0d196a merge with stable 2011-11-17 16:53:17 -06:00
Brodie Rao
114ca03d36 tests: fix readline escape characters in heredoctest.py/test-url.py
This fix mirrors the changes made to test-doctest.py in 04cfbbc5ae97
and 39599b7929c4.

Without this change, tests running heredoctest.py can fail on certain
versions of OS X when TERM is set to xterm-256color:

   $ /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -m heredoctest <<EOF
   > >>> open('b', 'w').write('this' * 1000)
   > EOF
+  \x1b[?1034h (no-eol) (esc)

A similar problem occurs with test-url.py:

  $ ./run-tests.py test-url.py

  --- .../tests/test-url.py.out
  +++ .../tests/test-url.py.err
  @@ -0,0 +1 @@
  +
  ERROR: .../test-url.py output changed
  !
  Failed test-url.py: output changed
  # Ran 1 tests, 0 skipped, 1 failed.
2011-11-01 12:25:54 -07:00
Mads Kiilerich
6485196281 util: don't encode ':' in url paths
':' has no special meaning in paths, so there is no need for encoding it.

Not encoding ':' makes it easier to test on windows.
2011-11-07 03:25:10 +01:00
Mads Kiilerich
965df356e5 url: really handle urls of the form file:///c:/foo/bar/ correctly
8264e5172141 made sure that paths that seemed to start with a windows drive
letter would not get an extra leading slash.

localpath should thus not try to handle this case by removing a leading slash,
and this special handling is thus removed.

(The localpath handling of this case was wrong anyway, because paths that look
like they start with a windows drive letter can't have a leading slash.)

A quick verification of this is to run 'hg id file:///c:/foo/bar/'.
2011-08-04 02:51:29 +02:00
Nicolas Bareil
db42995f2e sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Any entries in subjectAltName would prevent fallback to using commonName, but
RFC 2818 says:

    If a subjectAltName extension of type dNSName is present, that MUST
    be used as the identity. Otherwise, the (most specific) Common Name
    field in the Subject field of the certificate MUST be used.

We now only consider dNSNames in subjectAltName.

(dNSName is known as 'DNS' in OpenSSL/Python.)
2011-06-18 01:03:03 +02:00
Peter Arrenbrecht
af91571a48 util: make str(url) return file:/// for abs paths again
str(url) was recently changed to return only file:/. However, the
canonical way to represent absolute local paths is file:/// [1], which
is also expected by at least hgsubversion.

Relative paths are returned as file:the/relative/path.

[1] http://en.wikipedia.org/wiki/File_URI_scheme
2011-05-12 16:41:56 +02:00
Augie Fackler
71eea02c91 sslutil: extracted ssl methods from httpsconnection in url.py
This makes it easier to share ssl cert validation with other http
implementations.
2011-05-04 22:08:55 -05:00
Brodie Rao
b7f0d2a103 url: move URL parsing functions into util to improve startup time
The introduction of the new URL parsing code has created a startup
time regression. This is mainly due to the use of url.hasscheme() in
the ui class. It ends up importing many libraries that the url module
requires.

This fix helps marginally, but if we can get rid of the urllib import
in the URL parser all together, startup time will go back to normal.

perfstartup time before the URL refactoring (707e4b1e8064):

! wall 0.050692 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)

current startup time (9ad1dce9e7f4):

! wall 0.070685 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)

after this change:

! wall 0.064667 comb 0.000000 user 0.000000 sys 0.000000 (best of 100)
2011-04-30 09:43:20 -07:00
Brodie Rao
3bbcdd41bc url: be stricter about detecting schemes
While the URL parser is very forgiving about what characters are
allowed in each component, it's useful to be strict about the scheme
so we don't accidentally interpret local paths with colons as URLs.

This restricts schemes to containing alphanumeric characters, dashes,
pluses, and dots (as specified in RFC 2396).
2011-03-31 17:37:33 -07:00
Matt Mackall
d0ca936e58 url: nuke some newly-introduced underbars in identifiers 2011-03-31 10:43:53 -05:00
Brodie Rao
80fd2713db url: abort on file:// URLs with non-localhost hosts 2011-03-30 20:01:31 -07:00
Matt Mackall
b92d665cf7 url: fix tests 2011-03-30 14:42:41 -05:00
Brodie Rao
186bc90ec4 url: provide url object
This adds a url object that re-implements urlsplit() and
unsplit(). The implementation splits out usernames, passwords, and
ports.

The implementation is based on the behavior specified by RFC
2396[1]. However, it is much more forgiving than the RFC's
specification; it places no specific restrictions on what characters
are allowed in each segment of the URL other than what is necessary to
split the URL into its constituent parts.

[1]: http://www.ietf.org/rfc/rfc2396.txt
2011-03-25 22:58:56 -07:00
Yuya Nishihara
593388c52e url: check subjectAltName when verifying ssl certificate
Now it verifies certificate in the same manner as py3k implementation:
http://svn.python.org/view/python/branches/py3k/Lib/ssl.py?view=markup#match_hostname
2011-01-09 00:35:36 +09:00
Yuya Nishihara
ecde2415b3 url: fix UnicodeDecodeError on certificate verification error
SSLSocket.getpeercert() returns tuple containing unicode for 'subject'.
Since Mercurial does't support IDN at all, it just returns error for non-ascii
certname.
2011-01-08 21:52:25 +09:00
Dan Villiom Podlaski Christiansen
f385faac7a *: kill all unnecessary shebangs. 2010-10-26 12:18:39 +02:00
Mads Kiilerich
70b420d9b9 url: validity (notBefore/notAfter) is checked by OpenSSL (issue2407)
Removing the check from our code makes https with cacerts check work with
Python < 2.6.
2010-10-17 04:14:06 +02:00
Augie Fackler
605d8c9578 test-url: skip test when ssl module is unavailable 2010-10-12 11:02:45 -05:00
Augie Fackler
d9ce40564e test-url: remove trailing whitespace 2010-10-12 11:02:05 -05:00
Martin Geisler
1edc738611 test-url: refactor with shorter lines 2010-10-01 16:39:55 +02:00
Mads Kiilerich
916b2a0e20 url: verify correctness of https server certificates (issue2407)
Pythons SSL module verifies that certificates received for HTTPS are valid
according to the specified cacerts, but it doesn't verify that the certificate
is for the host we connect to.

We now explicitly verify that the commonName in the received certificate
matches the requested hostname and is valid for the time being.

This is a minimal patch where we try to fail to the safe side, but we do still
rely on Python's SSL functionality and do not try to implement the standards
fully and correctly. CRLs and subjectAltName are not handled and proxies
haven't been considered.

This change might break connections to some sites if cacerts is specified and
the certificates (by our definition) isn't correct. The workaround is to
disable cacerts which in most cases isn't much worse than it was before with
cacerts.
2010-10-01 00:46:59 +02:00