@@ -42,6 +42,9 @@ const originalStep = KerberosClient.prototype.step;
4242 * @return {Promise<string> }
4343 */
4444KerberosClient . prototype . step = async function step ( challenge ) {
45+ if ( typeof challenge !== 'string' ) {
46+ throw new Error ( 'parameter `challenge` must be a string.' ) ;
47+ }
4548 return await promisify ( originalStep . bind ( this ) ) ( challenge ) ;
4649} ;
4750
@@ -52,12 +55,20 @@ const originalWrap = KerberosClient.prototype.wrap;
5255 * @kind function
5356 * @memberof KerberosClient
5457 * @param {string } challenge The response returned after calling `unwrap`
55- * @param {object } [options] Optional settings
58+ * @param {object } [options] Options
5659 * @param {string } [options.user] The user to authorize
5760 * @param {boolean } [options.protect] Indicates if the wrap should request message confidentiality
5861 * @return {Promise<string> }
5962 */
60- KerberosClient . prototype . wrap = async function wrap ( challenge , options = { } ) {
63+ KerberosClient . prototype . wrap = async function wrap ( challenge , options ) {
64+ if ( typeof challenge !== 'string' ) {
65+ throw new Error ( 'parameter `challenge` must be a string.' ) ;
66+ }
67+
68+ // eslint-disable-next-line no-restricted-syntax
69+ if ( typeof challenge !== 'object' || challenge === null ) {
70+ throw new Error ( 'parameter `challenge` must be an object.' ) ;
71+ }
6172 return await promisify ( originalWrap . bind ( this ) ) ( challenge , options ) ;
6273} ;
6374
@@ -71,6 +82,9 @@ const originalUnwrap = KerberosClient.prototype.unwrap;
7182 * @return {Promise<string> }
7283 */
7384KerberosClient . prototype . unwrap = async function unwrap ( challenge ) {
85+ if ( typeof challenge !== 'string' ) {
86+ throw new Error ( 'parameter `challenge` must be a string.' ) ;
87+ }
7488 return await promisify ( originalUnwrap . bind ( this ) ) ( challenge ) ;
7589} ;
7690
@@ -93,6 +107,9 @@ const originalServerStep = KerberosServer.prototype.step;
93107 * @return {Promise<KerberosServer> }
94108 */
95109KerberosServer . prototype . step = async function step ( challenge ) {
110+ if ( typeof challenge !== 'string' ) {
111+ throw new Error ( 'parameter `challenge` must be a string.' ) ;
112+ }
96113 return await promisify ( originalServerStep . bind ( this ) ) ( challenge ) ;
97114} ;
98115
@@ -121,6 +138,18 @@ KerberosServer.prototype.step = async function step(challenge) {
121138 * @return {Promise<null> } returns Promise that rejects if the password is invalid
122139 */
123140async function checkPassword ( username , password , service , defaultRealm ) {
141+ if ( typeof username !== 'string' ) {
142+ throw new Error ( 'parameter `username` must be a string.' ) ;
143+ }
144+ if ( typeof password !== 'string' ) {
145+ throw new Error ( 'parameter `password` must be a string.' ) ;
146+ }
147+ if ( typeof service !== 'string' ) {
148+ throw new Error ( 'parameter `service` must be a string.' ) ;
149+ }
150+ if ( defaultRealm && typeof defaultRealm !== 'string' ) {
151+ throw new Error ( 'if specified, parameter `defaultRealm` must be a string.' ) ;
152+ }
124153 return await promisify ( kerberos . checkPassword ) ( username , password , service , defaultRealm ) ;
125154}
126155
@@ -135,6 +164,12 @@ async function checkPassword(username, password, service, defaultRealm) {
135164 * @return {Promise } returns Promise
136165 */
137166async function principalDetails ( service , hostname ) {
167+ if ( typeof service !== 'string' ) {
168+ throw new Error ( 'parameter `service` must be a string.' ) ;
169+ }
170+ if ( typeof hostname !== 'string' ) {
171+ throw new Error ( 'parameter `hostname` must be a string.' ) ;
172+ }
138173 return await promisify ( kerberos . principalDetails ) ( service , hostname ) ;
139174}
140175
@@ -150,6 +185,9 @@ async function principalDetails(service, hostname) {
150185 * @return {Promise<KerberosClient> } returns Promise
151186 */
152187async function initializeClient ( service , options = { mechOID : GSS_C_NO_OID } ) {
188+ if ( typeof service !== 'string' ) {
189+ throw new Error ( 'parameter `service` must be a string.' ) ;
190+ }
153191 return await promisify ( kerberos . initializeClient ) ( service , options ) ;
154192}
155193
@@ -161,6 +199,9 @@ async function initializeClient(service, options = { mechOID: GSS_C_NO_OID }) {
161199 * @return {Promise<KerberosServer> } returns Promise
162200 */
163201async function initializeServer ( service ) {
202+ if ( typeof service !== 'string' ) {
203+ throw new Error ( 'parameter `service` must be a string.' ) ;
204+ }
164205 return await promisify ( kerberos . initializeServer ) ( service ) ;
165206}
166207
0 commit comments