From 09746536e6c0d9b660357b670ef81d55b7b51070 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Thu, 7 Jun 2007 22:03:55 +0000 Subject: [PATCH] New tests svn: r6530 --- collects/web-server/servlet/basic-auth.ss | 8 ------ .../tests/servlet/basic-auth-test.ss | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/collects/web-server/servlet/basic-auth.ss b/collects/web-server/servlet/basic-auth.ss index 6ce733ea0f..302112ef9a 100644 --- a/collects/web-server/servlet/basic-auth.ss +++ b/collects/web-server/servlet/basic-auth.ss @@ -4,14 +4,6 @@ (lib "base64.ss" "net")) (require "../private/request-structs.ss") - ; Authentication - ; extract-user-pass : (listof (cons sym bytes)) -> (or/c #f (cons str str)) - ;; Notes (GregP) - ;; 1. This is Basic Authentication (RFC 1945 SECTION 11.1) - ;; e.g. an authorization header will look like this: - ;; Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== - ;; 2. Headers should be read as bytes and then translated to unicode as appropriate. - ;; 3. The Authorization header should have bytes (i.e. (cdr pass-pair) is bytes (define (extract-user-pass headers) (match (headers-assq* #"Authorization" headers) [#f #f] diff --git a/collects/web-server/tests/servlet/basic-auth-test.ss b/collects/web-server/tests/servlet/basic-auth-test.ss index 50d8dcacf8..90c8531b96 100644 --- a/collects/web-server/tests/servlet/basic-auth-test.ss +++ b/collects/web-server/tests/servlet/basic-auth-test.ss @@ -1,8 +1,27 @@ (module basic-auth-test mzscheme - (require (planet "test.ss" ("schematics" "schemeunit.plt" 2))) + (require (planet "test.ss" ("schematics" "schemeunit.plt" 2)) + (lib "request-structs.ss" "web-server" "private") + (lib "basic-auth.ss" "web-server" "servlet")) (provide basic-auth-tests) - ; XXX (define basic-auth-tests (test-suite - "BASIC Authentication"))) \ No newline at end of file + "BASIC Authentication" + + (test-case + "Simple" + (check-equal? (extract-user-pass (list (make-header #"Authorization" #"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="))) + (cons #"Aladdin" #"open sesame"))) + + (test-case + "Value error" + (check-false (extract-user-pass (list (make-header #"Authorization" #"Basic adfadQWxhZGRpb124134jpvcGVu="))))) + + (test-case + "No header" + (check-false (extract-user-pass (list)))) + + (test-case + "Case" + (check-equal? (extract-user-pass (list (make-header #"AuthoRIZation" #"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="))) + (cons #"Aladdin" #"open sesame")))))) \ No newline at end of file