@@ -4,6 +4,7 @@ const request = require('request');
44const chai = require ( 'chai' ) ;
55const expect = chai . expect ;
66const os = require ( 'os' ) ;
7+ const { test } = require ( 'mocha' ) ;
78chai . use ( require ( 'chai-string' ) ) ;
89
910// environment variables
@@ -122,4 +123,50 @@ describe('Kerberos', function () {
122123 } ) ;
123124 } ) ;
124125 } ) ;
126+
127+ describe ( 'Client.wrap()' , function ( ) {
128+ async function establishConext ( ) {
129+ const service = `HTTP@${ hostname } ` ;
130+ client = await kerberos . initializeClient ( service , { } ) ;
131+ server = await kerberos . initializeServer ( service ) ;
132+ const clientResponse = await client . step ( '' ) ;
133+ const serverResponse = await server . step ( clientResponse ) ;
134+ await client . step ( serverResponse ) ;
135+ expect ( client . contextComplete ) . to . be . true ;
136+ return { client, server } ;
137+ }
138+
139+ let client ;
140+ let server ;
141+
142+ before ( establishConext ) ;
143+ describe ( 'options.protect' , function ( ) {
144+ context ( 'valid values for `protect`' , function ( ) {
145+ test ( 'no options provided' , async function ( ) {
146+ await client . wrap ( 'challenge' ) ;
147+ } ) ;
148+
149+ test ( 'options provided (protect omitted)' , async function ( ) {
150+ await client . wrap ( 'challenge' , { } ) ;
151+ } ) ;
152+
153+ test ( 'protect = false' , async function ( ) {
154+ await client . wrap ( 'challenge' , { protect : false } ) ;
155+ } ) ;
156+
157+ test ( 'protect = true' , async function ( ) {
158+ await client . wrap ( 'challenge' , { protect : true } ) ;
159+ } ) ;
160+ } ) ;
161+
162+ context ( 'when set to an invalid value' , function ( ) {
163+ it ( 'throws a TypeError' , async function ( ) {
164+ const error = await client . wrap ( 'challenge' , { protect : 'non-boolean' } ) . catch ( e => e ) ;
165+ expect ( error )
166+ . to . be . instanceOf ( TypeError )
167+ . to . match ( / o p t i o n s .p r o t e c t m u s t b e a b o o l e a n / ) ;
168+ } ) ;
169+ } ) ;
170+ } ) ;
171+ } ) ;
125172} ) ;
0 commit comments