mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-16 05:00:24 +00:00
Strip whitespaces when authorization type is unknown
This commit is contained in:
parent
ecb234693c
commit
1c5ce11d13
1 changed files with 5 additions and 3 deletions
|
@ -817,7 +817,7 @@ authorization(UserPass, Type = <<"basic">>) ->
|
|||
end)
|
||||
end);
|
||||
authorization(String, Type) ->
|
||||
{Type, String}.
|
||||
cowboy_http:whitespace(String, fun(Rest) -> {Type, Rest} end).
|
||||
|
||||
%% @doc Parse user credentials.
|
||||
-spec authorization_basic_userid(binary(), fun()) -> any().
|
||||
|
@ -1347,9 +1347,11 @@ http_authorization_test_() ->
|
|||
?_assertEqual({error, badarg},
|
||||
authorization(<<"dXNlcm5hbWUK">>, <<"basic">>)),
|
||||
?_assertEqual({error, badarg},
|
||||
authorization(<<"_[]@#$%^&*()-AA==">>, <<"basic">>)),
|
||||
authorization(<<"_[]@#$%^&*()-AA==">>, <<"basic">>)),
|
||||
?_assertEqual({error, badarg},
|
||||
authorization(<<"dXNlcjpwYXNzCA==">>, <<"basic">>)) %% user:pass\010
|
||||
authorization(<<"dXNlcjpwYXNzCA==">>, <<"basic">>)), %% user:pass\010
|
||||
?_assertEqual({<<"bearer">>,<<"some_secret_key">>},
|
||||
authorization(<<" some_secret_key">>, <<"bearer">>))
|
||||
].
|
||||
|
||||
-endif.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue