Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,10 +954,6 @@ class Connection extends EventEmitter {
* @private
*/
declare closed: boolean;
/**
* @private
*/
declare loginError: undefined | AggregateError | ConnectionError;
/**
* @private
*/
Expand Down Expand Up @@ -3491,13 +3487,12 @@ class Connection extends EventEmitter {

if (handler.loginAckReceived) {
return handler.routingData;
} else if (this.loginError) {
throw this.loginError;
} else if (handler.loginError) {
throw handler.loginError;
} else {
throw new ConnectionError('Login failed.', 'ELOGIN');
}
} finally {
this.loginError = undefined;
signal.removeEventListener('abort', onAbort);
}
}
Expand Down Expand Up @@ -3547,14 +3542,13 @@ class Connection extends EventEmitter {
});

this.ntlmpacket = undefined;
} else if (this.loginError) {
throw this.loginError;
} else if (handler.loginError) {
throw handler.loginError;
} else {
throw new ConnectionError('Login failed.', 'ELOGIN');
}
}
} finally {
this.loginError = undefined;
signal.removeEventListener('abort', onAbort);
}
}
Expand Down Expand Up @@ -3655,13 +3649,12 @@ class Connection extends EventEmitter {
// sent the fedAuth token message, the rest is similar to standard login 7
this.transitionTo(this.STATE.SENT_LOGIN7_WITH_STANDARD_LOGIN);
return await this.performSentLogin7WithStandardLogin(signal);
} else if (this.loginError) {
throw this.loginError;
} else if (handler.loginError) {
throw handler.loginError;
} else {
throw new ConnectionError('Login failed.', 'ELOGIN');
}
} finally {
this.loginError = undefined;
signal.removeEventListener('abort', onAbort);
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/token/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,13 @@ export class Login7TokenHandler extends TokenHandler {

declare loginAckReceived: boolean;

declare loginError: ConnectionError | undefined;

constructor(connection: Connection) {
super();
this.loginAckReceived = false;
this.connection = connection;
this.loginError = undefined;
}

onInfoMessage(token: InfoMessageToken) {
Expand All @@ -270,7 +273,7 @@ export class Login7TokenHandler extends TokenHandler {
error.isTransient = true;
}

this.connection.loginError = error;
this.loginError = error;
}

onSSPI(token: SSPIToken) {
Expand Down Expand Up @@ -309,27 +312,27 @@ export class Login7TokenHandler extends TokenHandler {

if (authentication.type === 'azure-active-directory-password' || authentication.type === 'azure-active-directory-access-token' || authentication.type === 'azure-active-directory-msi-vm' || authentication.type === 'azure-active-directory-msi-app-service' || authentication.type === 'azure-active-directory-service-principal-secret' || authentication.type === 'azure-active-directory-default') {
if (token.fedAuth === undefined) {
this.connection.loginError = new ConnectionError('Did not receive Active Directory authentication acknowledgement');
this.loginError = new ConnectionError('Did not receive Active Directory authentication acknowledgement');
} else if (token.fedAuth.length !== 0) {
this.connection.loginError = new ConnectionError(`Active Directory authentication acknowledgment for ${authentication.type} authentication method includes extra data`);
this.loginError = new ConnectionError(`Active Directory authentication acknowledgment for ${authentication.type} authentication method includes extra data`);
}
} else if (token.fedAuth === undefined && token.utf8Support === undefined) {
this.connection.loginError = new ConnectionError('Received acknowledgement for unknown feature');
this.loginError = new ConnectionError('Received acknowledgement for unknown feature');
} else if (token.fedAuth) {
this.connection.loginError = new ConnectionError('Did not request Active Directory authentication, but received the acknowledgment');
this.loginError = new ConnectionError('Did not request Active Directory authentication, but received the acknowledgment');
}
}

onLoginAck(token: LoginAckToken) {
if (!token.tdsVersion) {
// unsupported TDS version
this.connection.loginError = new ConnectionError('Server responded with unknown TDS version.', 'ETDS');
this.loginError = new ConnectionError('Server responded with unknown TDS version.', 'ETDS');
return;
}

if (!token.interface) {
// unsupported interface
this.connection.loginError = new ConnectionError('Server responded with unsupported interface.', 'EINTERFACENOTSUPP');
this.loginError = new ConnectionError('Server responded with unsupported interface.', 'EINTERFACENOTSUPP');
return;
}

Expand Down
Loading