Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from sthadka/master

Add option of having a hidden auth page
  • Loading branch information...
commit 269117362c9f705ccb71ced737388c0eab167ea1 2 parents 1be247a + 4fe7620
@martinrehfeld authored
Showing with 24 additions and 0 deletions.
  1. +3 −0  src/elli_basicauth.erl
  2. +21 −0 test/elli_basicauth_tests.erl
View
3  src/elli_basicauth.erl
@@ -20,6 +20,9 @@ handle(Req, Config) ->
forbidden ->
throw({403, [], <<"Forbidden">>});
+ hidden ->
+ throw({404, [], <<>>});
+
_ ->
ignore
end.
View
21 test/elli_basicauth_tests.erl
@@ -77,6 +77,21 @@ invalid_credentials_test() ->
meck:unload(elli_request).
+hidden_auth_test() ->
+ meck:new(elli_request),
+ meck:expect(elli_request, get_header,
+ fun (<<"Authorization">>, mock_request) ->
+ ?INVALID_CREDENTIALS
+ end),
+
+ Result = (catch elli_basicauth:handle(mock_request,
+ hidden_basicauth_config())),
+
+ ?assertEqual({404, [], <<>>}, Result),
+ ?assert(meck:validate(elli_request)),
+ meck:unload(elli_request).
+
+
elli_handler_behaviour_test() ->
?assertEqual(ok, elli_basicauth:handle_event(request_complete,
[mock_request,
@@ -114,6 +129,8 @@ elli_handler_behaviour_test() ->
basicauth_config() ->
[{auth_fun, fun auth_fun/3}].
+hidden_basicauth_config() ->
+ [{auth_fun, fun hidden_auth_fun/3}].
basicauth_config_with_custom_realm() ->
[{auth_fun, fun auth_fun/3},
@@ -123,3 +140,7 @@ basicauth_config_with_custom_realm() ->
auth_fun(_Req, undefined, undefined) -> unauthorized;
auth_fun(_Req, ?USER, ?PASSWORD) -> ok;
auth_fun(_Req, _User, _Password) -> forbidden.
+
+hidden_auth_fun(_Req, undefined, undefined) -> hidden;
+hidden_auth_fun(_Req, ?USER, ?PASSWORD) -> ok;
+hidden_auth_fun(_Req, _User, _Password) -> hidden.
Please sign in to comment.
Something went wrong with that request. Please try again.