@@ -14,17 +14,34 @@ var digestServer = http.createServer(function (req, res) {
14
14
15
15
var ok ;
16
16
17
- if ( req . headers . authorization ) {
18
- if ( / ^ D i g e s t u s e r n a m e = " t e s t " , r e a l m = " P r i v a t e " , n o n c e = " W p c H S 2 \/ T B A A = d f f c c 0 d b d 5 f 9 6 d 4 9 a 5 4 7 7 1 6 6 6 4 9 b 7 c 0 a e 3 8 6 6 a 9 3 " , u r i = " \/ t e s t \/ " , q o p = " a u t h " , r e s p o n s e = " [ a - f 0 - 9 ] { 32 } " , n c = " 1 " , c n o n c e = " [ a - f 0 - 9 ] { 32 } " $ / . exec ( req . headers . authorization ) ) {
19
- ok = true ;
17
+ if ( req . url === '/test/' ) {
18
+ if ( req . headers . authorization ) {
19
+ if ( / ^ D i g e s t u s e r n a m e = " t e s t " , r e a l m = " P r i v a t e " , n o n c e = " W p c H S 2 \/ T B A A = d f f c c 0 d b d 5 f 9 6 d 4 9 a 5 4 7 7 1 6 6 6 4 9 b 7 c 0 a e 3 8 6 6 a 9 3 " , u r i = " \/ t e s t \/ " , q o p = a u t h , r e s p o n s e = " [ a - f 0 - 9 ] { 32 } " , n c = 0 0 0 0 0 0 0 1 , c n o n c e = " [ a - f 0 - 9 ] { 32 } " , a l g o r i t h m = M D 5 , o p a q u e = " 5 c c c 0 6 9 c 4 0 3 e b a f 9 f 0 1 7 1 e 9 5 1 7 f 4 0 e 4 1 " $ / . exec ( req . headers . authorization ) ) {
20
+ ok = true ;
21
+ } else {
22
+ // Bad auth header, don't send back WWW-Authenticate header
23
+ ok = false ;
24
+ }
20
25
} else {
21
- // Bad auth header, don't send back WWW-Authenticate header
26
+ // No auth header, send back WWW-Authenticate header
22
27
ok = false ;
28
+ res . setHeader ( 'www-authenticate' , 'Digest realm="Private", nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93", algorithm=MD5, qop="auth", opaque="5ccc069c403ebaf9f0171e9517f40e41"' ) ;
29
+ }
30
+ } else if ( req . url === '/dir/index.html' ) {
31
+ // RFC2069-compatible mode
32
+ // check: http://www.rfc-editor.org/errata_search.php?rfc=2069
33
+ if ( req . headers . authorization ) {
34
+ if ( / ^ D i g e s t u s e r n a m e = " M u f a s a " , r e a l m = " t e s t r e a l m @ h o s t .c o m " , n o n c e = " d c d 9 8 b 7 1 0 2 d d 2 f 0 e 8 b 1 1 d 0 f 6 0 0 b f b 0 c 0 9 3 " , u r i = " \/ d i r \/ i n d e x .h t m l " , r e s p o n s e = " [ a - f 0 - 9 ] { 32 } " , o p a q u e = " 5 c c c 0 6 9 c 4 0 3 e b a f 9 f 0 1 7 1 e 9 5 1 7 f 4 0 e 4 1 " $ / . exec ( req . headers . authorization ) ) {
35
+ ok = true ;
36
+ } else {
37
+ // Bad auth header, don't send back WWW-Authenticate header
38
+ ok = false ;
39
+ }
40
+ } else {
41
+ // No auth header, send back WWW-Authenticate header
42
+ ok = false ;
43
+ res . setHeader ( 'www-authenticate' , 'Digest realm="testrealm@host.com", nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093", opaque="5ccc069c403ebaf9f0171e9517f40e41"' ) ;
23
44
}
24
- } else {
25
- // No auth header, send back WWW-Authenticate header
26
- ok = false ;
27
- res . setHeader ( 'www-authenticate' , 'Digest realm="Private", nonce="WpcHS2/TBAA=dffcc0dbd5f96d49a5477166649b7c0ae3866a93", algorithm=MD5, qop="auth"' ) ;
28
45
}
29
46
30
47
if ( ok ) {
@@ -63,7 +80,20 @@ request({
63
80
assert . equal ( response . statusCode , 401 ) ;
64
81
assert . equal ( numDigestRequests , 3 ) ;
65
82
66
- console . log ( 'All tests passed' ) ;
67
- digestServer . close ( ) ;
83
+ request ( {
84
+ 'method' : 'GET' ,
85
+ 'uri' : 'http://localhost:6767/dir/index.html' ,
86
+ 'auth' : {
87
+ 'user' : 'Mufasa' ,
88
+ 'pass' : 'CircleOfLife' ,
89
+ 'sendImmediately' : false
90
+ }
91
+ } , function ( error , response , body ) {
92
+ assert . equal ( response . statusCode , 200 ) ;
93
+ assert . equal ( numDigestRequests , 5 ) ;
94
+
95
+ console . log ( 'All tests passed' ) ;
96
+ digestServer . close ( ) ;
97
+ } ) ;
68
98
} ) ;
69
99
} ) ;
0 commit comments