Repository: conda/conda

Issue:
scrambled URL of non-alias channel with token
The URL parsing would swap around locations of URL parts if passed a `/t/<TOKEN>` URL that was not the `channel_alias`.
scrambled URL of non-alias channel with token
The URL parsing would swap around locations of URL parts if passed a `/t/<TOKEN>` URL that was not the `channel_alias`.


Discussion:

Resolving patch:
diff --git a/conda/models/channel.py b/conda/models/channel.py
--- a/conda/models/channel.py
+++ b/conda/models/channel.py
@@ -16,10 +16,10 @@
 
 try:
     from cytoolz.functoolz import excepts
-    from cytoolz.itertoolz import concatv, topk
+    from cytoolz.itertoolz import concatv, drop
 except ImportError:  # pragma: no cover
     from .._vendor.toolz.functoolz import excepts  # NOQA
-    from .._vendor.toolz.itertoolz import concatv, topk  # NOQA
+    from .._vendor.toolz.itertoolz import concatv, drop  # NOQA
 
 log = getLogger(__name__)
 
@@ -420,7 +420,13 @@ def _read_channel_configuration(scheme, host, port, path):
         return location, name, _scheme, _auth, _token
 
     # Step 7. fall through to host:port as channel_location and path as channel_name
-    return (Url(host=host, port=port).url.rstrip('/'), path.strip('/') or None,
+    #  but bump the first token of paths starting with /conda for compatibility with
+    #  Anaconda Enterprise Repository software.
+    bump = None
+    path_parts = path.strip('/').split('/')
+    if path_parts and path_parts[0] == 'conda':
+        bump, path = 'conda', '/'.join(drop(1, path_parts))
+    return (Url(host=host, port=port, path=bump).url.rstrip('/'), path.strip('/') or None,
             scheme or None, None, None)
 
 


Test patch:
diff --git a/tests/models/test_channel.py b/tests/models/test_channel.py
--- a/tests/models/test_channel.py
+++ b/tests/models/test_channel.py
@@ -20,7 +20,6 @@
 from conda.utils import on_win
 from logging import getLogger
 from unittest import TestCase
-import conda.models.channel
 
 try:
     from unittest.mock import patch
@@ -248,6 +247,31 @@ def test_canonicalized_url_gets_correct_token(self):
             "https://10.2.3.4:8080/conda/t/x1029384756/bioconda/noarch",
         ]
 
+    def test_token_in_custom_channel(self):
+        channel = Channel("https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/label/dev")
+        assert channel.name == "bioconda/label/dev"
+        assert channel.location == "10.2.8.9:8080/conda"
+        assert channel.urls() == [
+            "https://10.2.8.9:8080/conda/bioconda/label/dev/%s" % self.platform,
+            "https://10.2.8.9:8080/conda/bioconda/label/dev/noarch",
+        ]
+        assert channel.urls(with_credentials=True) == [
+            "https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/label/dev/%s" % self.platform,
+            "https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/label/dev/noarch",
+        ]
+
+        channel = Channel("https://10.2.8.9:8080/conda/t/tk-987-321/bioconda")
+        assert channel.name == "bioconda"
+        assert channel.location == "10.2.8.9:8080/conda"
+        assert channel.urls() == [
+            "https://10.2.8.9:8080/conda/bioconda/%s" % self.platform,
+            "https://10.2.8.9:8080/conda/bioconda/noarch",
+        ]
+        assert channel.urls(with_credentials=True) == [
+            "https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/%s" % self.platform,
+            "https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/noarch",
+        ]
+
 
 class CustomConfigChannelTests(TestCase):
     """