Skip to content

Commit

Permalink
Merge pull request #117 from emc-isilon/isi-mfurer-patch-1
Browse files Browse the repository at this point in the history
pike.auth: maxsplit=1 for password and domain
  • Loading branch information
isi-mfurer committed May 3, 2022
2 parents 2fbf3dc + abfdf2e commit 4c043ef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test_samba.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,6 @@ jobs:
PIKE_PORT: ${{ job.services.samba.ports[445] }}
PIKE_SHARE: pike
PIKE_CREDS: pike%GiThubCI123
run: python -m unittest -v pike.test.samba_suite
run: |
python -m unittest -v pike.test.samba_suite
python -m pytest --pyargs pike.test.internal
4 changes: 2 additions & 2 deletions pike/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def split_credentials(creds):
"Pass creds as unicode string, got {!r}".format(creds), UnicodeWarning
)
creds = creds.decode("utf-8")
user, password = creds.split("%")
user, password = creds.split("%", 1)
if "\\" in user:
domain, user = user.split("\\")
domain, user = user.split("\\", 1)
else:
domain = "NONE"
return (domain, user, password)
Expand Down
23 changes: 23 additions & 0 deletions pike/test/internal/test_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import pytest

import pike.auth


# pike uses the "NONE" domain when one isn't provided
NONE = "NONE"


@pytest.mark.parametrize(
"cred_str,exp_cred_tuple",
(
("foo%bar", (NONE, "foo", "bar")),
("foo%ba%r", (NONE, "foo", "ba%r")),
("BAZ\\foo%bar", ("BAZ", "foo", "bar")),
("BAZ\\foo%b%ar", ("BAZ", "foo", "b%ar")),
# not convinced this is valid, but it won't crash the splitter
("BA\\Z\\foo%bar", ("BA", "Z\\foo", "bar")),
("BA\\Z\\foo%bar%", ("BA", "Z\\foo", "bar%")),
),
)
def test_split_credentials(cred_str, exp_cred_tuple):
assert pike.auth.split_credentials(cred_str) == exp_cred_tuple

0 comments on commit 4c043ef

Please sign in to comment.