Repository: datalad/datalad

Issue:
create-sibling-ria changes ssh username
#### What is the problem?
When trying to create a ria sibling the user name gets switched from the name in the ssh url to the current user name

#### What steps will reproduce the problem?

```
[rbc@cubic-login1 bidsdatasets]$ datalad create-sibling-ria \
    --name pmacs-ria ria+ssh://user2@scisub.pmacs.upenn.edu:/project/RBC/BIDS/CCNP
rbc@scisub.pmacs.upenn.edu's password:   
```

#### What version of DataLad are you using (run `datalad --version`)? On what operating system (consider running `datalad wtf`)?
0.14.0
#### Is there anything else that would be useful to know in this context?
#### Have you had any success using DataLad before? (to assess your expertise/prior luck.  We would welcome your testimonial additions to https://github.com/datalad/datalad/wiki/Testimonials as well)
No luck on create-sibling-ria :(

Is there some place I need to specify the user name for the remote server? It's replacing the user in the connection string with the name of the current user that's running the commands.


Discussion:

Patch:
diff --git a/datalad/customremotes/ria_utils.py b/datalad/customremotes/ria_utils.py
index 3795d6952..c0b6c7dc2 100644
--- a/datalad/customremotes/ria_utils.py
+++ b/datalad/customremotes/ria_utils.py
@@ -79,6 +79,8 @@ def verify_ria_url(url, cfg):
     -------
     tuple
       (host, base-path, rewritten url)
+      `host` is not just a hostname, but is a stub URL that may also contain
+      username, password, and port, if specified in a given URL.
     """
     from datalad.config import rewrite_url
     from datalad.support.network import URL
@@ -99,7 +101,17 @@ def verify_ria_url(url, cfg):
                          "Supported: ssh, file, http(s)" %
                          protocol)
 
-    return url_ri.hostname if protocol != 'file' else None, \
+    host = '{proto}://{user}{pdlm}{passwd}{udlm}{host}{portdlm}{port}'.format(
+        proto=protocol,
+        user=url_ri.username or '',
+        pdlm=':' if url_ri.password else '',
+        passwd=url_ri.password or '',
+        udlm='@' if url_ri.username else '',
+        host=url_ri.hostname or '',
+        portdlm=':' if url_ri.port else '',
+        port=url_ri.port or '',
+    )
+    return host if protocol != 'file' else None, \
         url_ri.path if url_ri.path else '/', \
         url
 


Test patch:
diff --git a/datalad/customremotes/tests/test_ria_utils.py b/datalad/customremotes/tests/test_ria_utils.py
index 03c6c5a65..4817b9344 100644
--- a/datalad/customremotes/tests/test_ria_utils.py
+++ b/datalad/customremotes/tests/test_ria_utils.py
@@ -5,6 +5,7 @@ from datalad.distributed.ora_remote import (
 from datalad.customremotes.ria_utils import (
     create_store,
     create_ds_in_store,
+    verify_ria_url,
     UnknownLayoutVersion
 )
 from datalad.utils import (
@@ -122,3 +123,37 @@ def test_setup_ds_in_store():
         raise SkipTest('ora_remote.SSHRemoteIO stalls on Windows')
 
     yield skip_ssh(_test_setup_ds_in_store), SSHRemoteIO, ['datalad-test']
+
+
+def test_verify_ria_url():
+    # unsupported protocol
+    assert_raises(ValueError,
+                  verify_ria_url, 'ria+ftp://localhost/tmp/this', {})
+    # bunch of caes that should work
+    cases = {
+        'ria+file:///tmp/this': (None, '/tmp/this'),
+        # no normalization
+        'ria+file:///tmp/this/': (None, '/tmp/this/'),
+        # with hosts
+        'ria+ssh://localhost/tmp/this': ('ssh://localhost', '/tmp/this'),
+        'ria+http://localhost/tmp/this': ('http://localhost', '/tmp/this'),
+        'ria+https://localhost/tmp/this': ('https://localhost', '/tmp/this'),
+        # with username
+        'ria+ssh://humbug@localhost/tmp/this':
+            ('ssh://humbug@localhost', '/tmp/this'),
+        # with port
+        'ria+ssh://humbug@localhost:2222/tmp/this':
+            ('ssh://humbug@localhost:2222', '/tmp/this'),
+        'ria+ssh://localhost:2200/tmp/this':
+            ('ssh://localhost:2200', '/tmp/this'),
+        # with password
+        'ria+https://humbug:1234@localhost:8080/tmp/this':
+            ('https://humbug:1234@localhost:8080', '/tmp/this'),
+        # document a strange (MIH thinks undesirable), but pre-existing
+        # behavior an 'ssh example.com' would end up in the user HOME,
+        # not in '/'
+        'ria+ssh://example.com': ('ssh://example.com', '/')
+    }
+    for i, o in cases.items():
+        # we are not testing the URL rewriting here
+        assert_equal(o, verify_ria_url(i, {})[:2])