You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2012/11/19 17:05:01 UTC

[3/3] git commit: add auth handlers etap test

add auth handlers etap test


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/b5613022
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/b5613022
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/b5613022

Branch: refs/heads/test-for-unexported-functions
Commit: b5613022e3cf11c56eb406b3641ab1ceb1ab9de6
Parents: a27b141
Author: Jan Lehnardt <ja...@apache.org>
Authored: Mon Nov 19 16:59:26 2012 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Mon Nov 19 17:03:51 2012 +0100

----------------------------------------------------------------------
 test/etap/240-auth-handlers.t |   55 ++++++++++++++++++++++++++++++++++++
 1 files changed, 55 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/b5613022/test/etap/240-auth-handlers.t
----------------------------------------------------------------------
diff --git a/test/etap/240-auth-handlers.t b/test/etap/240-auth-handlers.t
new file mode 100644
index 0000000..da913f5
--- /dev/null
+++ b/test/etap/240-auth-handlers.t
@@ -0,0 +1,55 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+main(_) ->
+    test_util:init_code_path(),
+    etap:plan(5),
+
+    test_invalid_cookie(),
+    test_valid_cookie(),
+    test_valid_cookie_with_colons_start(),
+    test_valid_cookie_with_colons_mid(),
+    test_valid_cookie_with_colons_end(),
+
+    etap:end_tests().
+
+test_invalid_cookie() ->
+    Fun = fun() ->
+        couch_httpd_auth:decode_auth_session(<<"asd">>)
+    end,
+    Expected = {bad_request, <<"Malformed AuthSession cookie. Please clear your cookies.">>},
+    etap:throws_ok(Fun, Expected, "Should throw on invalid cookie").
+
+test_cookie(Cookie, Expected, Message) ->
+    Cookie64 = couch_util:encodeBase64Url(Cookie),
+    Result = couch_httpd_auth:decode_auth_session(Cookie64),
+    etap:is(Result, Expected, Message).
+
+test_valid_cookie() ->
+    test_cookie(<<"aaa:bbb:ccc">>, ["aaa", "bbb", "ccc"],
+        "Should decode cookie session.").
+
+test_valid_cookie_with_colons_start() ->
+    test_cookie(<<"aaa:bbb::cc">>, ["aaa", "bbb", ":cc"],
+        "Should decode cookie session start.").
+
+test_valid_cookie_with_colons_mid() ->
+    test_cookie(<<"aaa:bbb:c::c">>, ["aaa", "bbb", "c::c"],
+        "Should decode cookie session mid.").
+
+test_valid_cookie_with_colons_end() ->
+    test_cookie(<<"aaa:bbb:cc:">>, ["aaa", "bbb", "cc:"],
+        "Should decode cookie session end.").
+