Skip to content

Commit

Permalink
Fix auth method logical error
Browse files Browse the repository at this point in the history
  • Loading branch information
rexzhang committed Aug 2, 2021
1 parent 0720098 commit 89b379f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
29 changes: 18 additions & 11 deletions asgi_webdav/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,27 @@ def pick_out_user(self, request: DAVRequest) -> (Optional[DAVUser], str):
return None, "Unknown authentication method"

def create_response_401(self, request: DAVRequest, message: str) -> DAVResponse:
if not self.config.http_digest_auth.enable or self._match_user_agent(
rule=self.config.http_digest_auth.disable_rule,
user_agent=request.client_user_agent,
):
challenge_string = self.basic_auth.make_auth_challenge_string()
logger.debug("response Basic auth challenge")
if self.config.http_digest_auth.enable:
if self._match_user_agent(
rule=self.config.http_digest_auth.disable_rule,
user_agent=request.client_user_agent,
):
enable_digest = False
else:
enable_digest = True

elif self.config.http_digest_auth.enable or self._match_user_agent(
rule=self.config.http_digest_auth.enable_rule,
user_agent=request.client_user_agent,
):
else:
if self._match_user_agent(
rule=self.config.http_digest_auth.enable_rule,
user_agent=request.client_user_agent,
):
enable_digest = True
else:
enable_digest = False

if enable_digest:
challenge_string = self.digest_auth.make_auth_challenge_string()
logger.debug("response Digest auth challenge")

else:
challenge_string = self.basic_auth.make_auth_challenge_string()
logger.debug("response Basic auth challenge")
Expand Down
4 changes: 2 additions & 2 deletions asgi_webdav/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
{"username": "guest", "password": "password", "permissions": list()},
],
"http_digest_auth": {
"enable": True,
"enable": False,
# "disable_rule": "neon/",
"enable_rule": "TEST",
},
"provider_mapping": [
{
Expand Down Expand Up @@ -69,7 +70,6 @@
"user_ignore_rule": "",
},
"logging_level": "DEBUG", # for debug
# "logging_level": "INFO", # for debug
}

app_args = AppArgs(in_docker_container=False)
Expand Down
15 changes: 11 additions & 4 deletions test_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional
import json
import xml
import pprint
from pprint import pprint
from dataclasses import dataclass

import requests
Expand All @@ -26,12 +26,13 @@ def call(conn):
print("---------------------")
print(result)
pprint(result.headers)
print(result.content)
if len(result.content) > 0:
try:
pprint(json.loads((json.dumps(xmltodict.parse(result.content)))))
except xml.parsers.expat.ExpatError:
pprint(result.content)
pass
else:
pprint(result.content)


def server_basic_auth(method, path, headers=None):
Expand Down Expand Up @@ -64,6 +65,11 @@ def main_test_auth():
server_digest_auth("OPTIONS", "/litmus")


def user_agent_test():
headers = {"user-agent": "TEST-AGENT"}
server_digest_auth("GET", "/", headers=headers)


def main():
# test_apache('PROPFIND', '/home', headers={'depth': '1'})
# test_apache('PROPFIND', '/.sync')
Expand All @@ -79,4 +85,5 @@ def main():


if __name__ == "__main__":
main_test_auth()
# main_test_auth()
user_agent_test()

0 comments on commit 89b379f

Please sign in to comment.