Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 44B83D08D for ; Mon, 19 Nov 2012 16:05:07 +0000 (UTC) Received: (qmail 32101 invoked by uid 500); 19 Nov 2012 16:05:07 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 31863 invoked by uid 500); 19 Nov 2012 16:05:02 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 31817 invoked by uid 99); 19 Nov 2012 16:05:01 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2012 16:05:01 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 3C2D9314B09; Mon, 19 Nov 2012 16:05:01 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jan@apache.org To: commits@couchdb.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [3/3] git commit: add auth handlers etap test Message-Id: <20121119160501.3C2D9314B09@tyr.zones.apache.org> Date: Mon, 19 Nov 2012 16:05:01 +0000 (UTC) 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 Authored: Mon Nov 19 16:59:26 2012 +0100 Committer: Jan Lehnardt 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."). +