mirror of
https://github.com/simonw/dclient.git
synced 2026-09-27 04:14:33 +02:00
Use longest possible matching URL for auth, refs #3
This commit is contained in:
parent
7807b8363f
commit
98d714c5e1
3 changed files with 41 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
|||
from dclient.utils import url_matches_prefix
|
||||
from dclient.utils import token_for_url, url_matches_prefix
|
||||
import pytest
|
||||
|
||||
|
||||
|
|
@ -39,3 +39,29 @@ import pytest
|
|||
)
|
||||
def test_url_matches_prefix(url, prefix_url, expected):
|
||||
assert url_matches_prefix(url, prefix_url) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"url,tokens,expected",
|
||||
(
|
||||
("https://foo.com/bar", {"https://foo.com": "foo"}, "foo"),
|
||||
("https://foo.com/bar", {"https://foo.com/baz": "baz"}, None),
|
||||
(
|
||||
"https://foo.com/bar",
|
||||
{"https://foo.com": "foo", "https://foo.com/bar": "bar"},
|
||||
"bar",
|
||||
),
|
||||
(
|
||||
"https://foo.com/bar/baz",
|
||||
{
|
||||
"https://foo.com": "foo",
|
||||
"https://foo.com/bar/baz": "baz",
|
||||
"https://foo.com/bar": "bar",
|
||||
},
|
||||
"baz",
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_token_for_url(url, tokens, expected):
|
||||
# Should always return longest matching of the available options
|
||||
assert token_for_url(url, tokens) == expected
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue