@@ -230,3 +230,74 @@ describe('auth.parse(string)', function () {
230230 } )
231231 } )
232232} )
233+
234+ describe ( 'auth.format(credentials)' , function ( ) {
235+ describe ( 'arguments' , function ( ) {
236+ describe ( 'credentials' , function ( ) {
237+ it ( 'should be required' , function ( ) {
238+ assert . throws ( auth . format , / a r g u m e n t c r e d e n t i a l s i s r e q u i r e d / )
239+ } )
240+
241+ it ( 'should accept credentials' , function ( ) {
242+ var header = auth . format ( { name : 'foo' , pass : 'bar' } )
243+ assert . strictEqual ( header , 'Basic Zm9vOmJhcg==' )
244+ } )
245+
246+ it ( 'should reject null' , function ( ) {
247+ assert . throws ( auth . format . bind ( null , null ) , / a r g u m e n t c r e d e n t i a l s i s r e q u i r e d / )
248+ } )
249+
250+ it ( 'should reject a number' , function ( ) {
251+ assert . throws ( auth . format . bind ( null , 42 ) , / a r g u m e n t c r e d e n t i a l s i s r e q u i r e d / )
252+ } )
253+
254+ it ( 'should reject a string' , function ( ) {
255+ assert . throws ( auth . format . bind ( null , '' ) , / a r g u m e n t c r e d e n t i a l s i s r e q u i r e d / )
256+ } )
257+
258+ it ( 'should reject an object without name' , function ( ) {
259+ assert . throws ( auth . format . bind ( null , { pass : 'bar' } ) , / a r g u m e n t c r e d e n t i a l s i s r e q u i r e d t o h a v e n a m e a n d p a s s p r o p e r t i e s / )
260+ } )
261+
262+ it ( 'should reject an object without pass' , function ( ) {
263+ assert . throws ( auth . format . bind ( null , { name : 'foo' } ) , / a r g u m e n t c r e d e n t i a l s i s r e q u i r e d t o h a v e n a m e a n d p a s s p r o p e r t i e s / )
264+ } )
265+
266+ it ( 'should reject an object with non-string name' , function ( ) {
267+ assert . throws ( auth . format . bind ( null , { name : 42 , pass : 'bar' } ) , / a r g u m e n t c r e d e n t i a l s i s r e q u i r e d t o h a v e n a m e a n d p a s s p r o p e r t i e s / )
268+ } )
269+
270+ it ( 'should reject an object with non-string pass' , function ( ) {
271+ assert . throws ( auth . format . bind ( null , { name : 'foo' , pass : 42 } ) , / a r g u m e n t c r e d e n t i a l s i s r e q u i r e d t o h a v e n a m e a n d p a s s p r o p e r t i e s / )
272+ } )
273+ } )
274+ } )
275+
276+ describe ( 'with valid credentials' , function ( ) {
277+ it ( 'should return header' , function ( ) {
278+ var header = auth . format ( { name : 'foo' , pass : 'bar' } )
279+ assert . strictEqual ( header , 'Basic Zm9vOmJhcg==' )
280+ } )
281+ } )
282+
283+ describe ( 'with empty password' , function ( ) {
284+ it ( 'should return header' , function ( ) {
285+ var header = auth . format ( { name : 'foo' , pass : '' } )
286+ assert . strictEqual ( header , 'Basic Zm9vOg==' )
287+ } )
288+ } )
289+
290+ describe ( 'with empty userid' , function ( ) {
291+ it ( 'should return header' , function ( ) {
292+ var header = auth . format ( { name : '' , pass : 'pass' } )
293+ assert . strictEqual ( header , 'Basic OnBhc3M=' )
294+ } )
295+ } )
296+
297+ describe ( 'with empty userid and pass' , function ( ) {
298+ it ( 'should return header' , function ( ) {
299+ var header = auth . format ( { name : '' , pass : '' } )
300+ assert . strictEqual ( header , 'Basic Og==' )
301+ } )
302+ } )
303+ } )
0 commit comments