@@ -117,3 +117,69 @@ describe('auth(req)', function () {
117117 } )
118118 } )
119119} )
120+
121+ describe ( 'auth.parse(string)' , function ( ) {
122+ describe ( 'with undefined string' , function ( ) {
123+ it ( 'should return undefined' , function ( ) {
124+ assert . strictEqual ( auth . parse ( ) , undefined )
125+ } )
126+ } )
127+
128+ describe ( 'with malformed string' , function ( ) {
129+ it ( 'should return undefined' , function ( ) {
130+ assert . strictEqual ( auth . parse ( 'Something' ) , undefined )
131+ } )
132+ } )
133+
134+ describe ( 'with malformed scheme' , function ( ) {
135+ it ( 'should return undefined' , function ( ) {
136+ assert . strictEqual ( auth . parse ( 'basic_Zm9vOmJhcg==' ) , undefined )
137+ } )
138+ } )
139+
140+ describe ( 'with malformed credentials' , function ( ) {
141+ it ( 'should return undefined' , function ( ) {
142+ assert . strictEqual ( auth . parse ( 'basic Zm9vcgo=' ) , undefined )
143+ } )
144+ } )
145+
146+ describe ( 'with valid credentials' , function ( ) {
147+ it ( 'should return .name and .pass' , function ( ) {
148+ var creds = auth . parse ( 'basic Zm9vOmJhcg==' )
149+ assert . equal ( creds . name , 'foo' )
150+ assert . equal ( creds . pass , 'bar' )
151+ } )
152+ } )
153+
154+ describe ( 'with empty password' , function ( ) {
155+ it ( 'should return .name and .pass' , function ( ) {
156+ var creds = auth . parse ( 'basic Zm9vOg==' )
157+ assert . equal ( creds . name , 'foo' )
158+ assert . equal ( creds . pass , '' )
159+ } )
160+ } )
161+
162+ describe ( 'with empty userid' , function ( ) {
163+ it ( 'should return .name and .pass' , function ( ) {
164+ var creds = auth . parse ( 'basic OnBhc3M=' )
165+ assert . equal ( creds . name , '' )
166+ assert . equal ( creds . pass , 'pass' )
167+ } )
168+ } )
169+
170+ describe ( 'with empty userid and pass' , function ( ) {
171+ it ( 'should return .name and .pass' , function ( ) {
172+ var creds = auth . parse ( 'basic Og==' )
173+ assert . equal ( creds . name , '' )
174+ assert . equal ( creds . pass , '' )
175+ } )
176+ } )
177+
178+ describe ( 'with colon in pass' , function ( ) {
179+ it ( 'should return .name and .pass' , function ( ) {
180+ var creds = auth . parse ( 'basic Zm9vOnBhc3M6d29yZA==' )
181+ assert . equal ( creds . name , 'foo' )
182+ assert . equal ( creds . pass , 'pass:word' )
183+ } )
184+ } )
185+ } )
0 commit comments