Skip to content

Commit

Permalink
fix: [#4684] ESLint issues in botframework-connector (#4822)
Browse files Browse the repository at this point in the history
* Fix ESLint in botframework-connector

* Fix jsdoc formatting
  • Loading branch information
sw-joelmut authored Jan 6, 2025
1 parent 6e388ce commit fc263a2
Show file tree
Hide file tree
Showing 54 changed files with 341 additions and 306 deletions.
12 changes: 3 additions & 9 deletions libraries/botframework-connector/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
const onlyWarn = require("eslint-plugin-only-warn");
const sharedConfig = require("../../eslint.config.cjs")
const sharedConfig = require('../../eslint.config.cjs');

module.exports = [
...sharedConfig,
{
ignores: ["src/connectorApi/**/*", "src/tokenApi/**/*", "**/*.nock.js"],

ignores: ['src/connectorApi/**/*', 'src/tokenApi/**/*', '**/*.nock.js'],
},
{
plugins: {
"only-warn": onlyWarn,
},
}]
];
1 change: 0 additions & 1 deletion libraries/botframework-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"botframework-schema": "4.1.6",
"buffer": "^6.0.3",
"cross-fetch": "^4.0.0",
"eslint-plugin-only-warn": "^1.1.0",
"https-proxy-agent": "^7.0.5",
"jsonwebtoken": "^9.0.2",
"node-fetch": "^2.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function allowedCallersClaimsValidator(allowedCallers: string[]): Validat
const appId = JwtTokenValidation.getAppIdFromClaims(claims);
if (!allowed.has(appId)) {
throw new Error(
`Received a request from an application with an appID of "${appId}". To enable requests from this skill, add the skill to your configuration file.`
`Received a request from an application with an appID of "${appId}". To enable requests from this skill, add the skill to your configuration file.`,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions libraries/botframework-connector/src/auth/appCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export abstract class AppCredentials implements ServiceClientCredentials {
*
* @param appId The App ID.
* @param channelAuthTenant Tenant ID of the Azure AD tenant where the bot is created.
* * Required for SingleTenant app types.
* * Optional for MultiTenant app types. **Note**: '_botframework.com_' is the default tenant when no value is provided.
* - Required for SingleTenant app types.
* - Optional for MultiTenant app types. **Note**: '_botframework.com_' is the default tenant when no value is provided.
*
* More information: https://learn.microsoft.com/en-us/security/zero-trust/develop/identity-supported-account-types.
* @param oAuthScope The scope for the token.
Expand Down
19 changes: 9 additions & 10 deletions libraries/botframework-connector/src/auth/aseChannelValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import { ClaimsIdentity } from './claimsIdentity';
import { AuthenticationConstants } from './authenticationConstants';
import { AuthenticationConfiguration } from './authenticationConfiguration';
import { GovernmentConstants } from './governmentConstants';
import { ICredentialProvider } from './credentialProvider';
import { ICredentialProvider, SimpleCredentialProvider } from './credentialProvider';
import { JwtTokenExtractor } from './jwtTokenExtractor';
import { JwtTokenValidation } from './jwtTokenValidation';
import { AuthenticationError } from './authenticationError';
import { SimpleCredentialProvider } from './credentialProvider';
import { StatusCodes } from 'botframework-schema';
import { BetweenBotAndAseChannelTokenValidationParameters } from './tokenValidationParameters';

Expand Down Expand Up @@ -80,18 +79,18 @@ export namespace AseChannelValidation {
*/
export async function authenticateAseChannelToken(
authHeader: string,
authConfig: AuthenticationConfiguration = new AuthenticationConfiguration()
authConfig: AuthenticationConfiguration = new AuthenticationConfiguration(),
): Promise<ClaimsIdentity> {
const tokenExtractor: JwtTokenExtractor = new JwtTokenExtractor(
BetweenBotAndAseChannelTokenValidationParameters,
MetadataUrl,
AuthenticationConstants.AllowedSigningAlgorithms
AuthenticationConstants.AllowedSigningAlgorithms,
);

const identity: ClaimsIdentity = await tokenExtractor.getIdentityFromAuthHeader(
authHeader,
ChannelId,
authConfig.requiredEndorsements
authConfig.requiredEndorsements,
);
if (!identity) {
// No valid identity. Not Authorized.
Expand All @@ -111,7 +110,7 @@ export namespace AseChannelValidation {
if (versionClaim === null) {
throw new AuthenticationError(
'Unauthorized. "ver" claim is required on Emulator Tokens.',
StatusCodes.UNAUTHORIZED
StatusCodes.UNAUTHORIZED,
);
}

Expand All @@ -127,7 +126,7 @@ export namespace AseChannelValidation {
// No claim around AppID. Not Authorized.
throw new AuthenticationError(
'Unauthorized. "appid" claim is required on Emulator Token version "1.0".',
StatusCodes.UNAUTHORIZED
StatusCodes.UNAUTHORIZED,
);
}

Expand All @@ -139,7 +138,7 @@ export namespace AseChannelValidation {
// No claim around AppID. Not Authorized.
throw new AuthenticationError(
'Unauthorized. "azp" claim is required on Emulator Token version "2.0".',
StatusCodes.UNAUTHORIZED
StatusCodes.UNAUTHORIZED,
);
}

Expand All @@ -148,14 +147,14 @@ export namespace AseChannelValidation {
// Unknown Version. Not Authorized.
throw new AuthenticationError(
`Unauthorized. Unknown Emulator Token version "${versionClaim}".`,
StatusCodes.UNAUTHORIZED
StatusCodes.UNAUTHORIZED,
);
}

if (!(await _creadentialProvider.isValidAppId(appId))) {
throw new AuthenticationError(
`Unauthorized. Invalid AppId passed on token: ${appId}`,
StatusCodes.UNAUTHORIZED
StatusCodes.UNAUTHORIZED,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export class AuthenticationConfiguration {
constructor(
public requiredEndorsements: string[] = [],
public validateClaims?: ValidateClaims,
public validTokenIssuers?: string[]
public validTokenIssuers?: string[],
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export class AuthenticationError extends Error implements IStatusCodeError {
* @param message The Error message.
* @param statusCode The `StatusCode` number to use.
*/
constructor(message: string, public readonly statusCode: StatusCode) {
constructor(
message: string,
readonly statusCode: StatusCode,
) {
super(message);
}

Expand All @@ -27,7 +30,6 @@ export class AuthenticationError extends Error implements IStatusCodeError {
* @param err The error to validate.
* @returns If `err` is an [IStatusCodeError](xref:botframework-schema.IStatusCodeError), the result is true; otherwise false.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
static isStatusCodeError(err: any): err is IStatusCodeError {
return !!(err && typeof err.statusCode === 'number');
}
Expand All @@ -38,7 +40,6 @@ export class AuthenticationError extends Error implements IStatusCodeError {
* @param err The error thrown, used to determine an appropriate status code.
* @returns The error message to be sent as a response.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
static determineStatusCodeAndBuildMessage(err: any): string {
const errMessage: string = err && err.message ? err.message : 'Internal Server Error';
const code: number = AuthenticationError.determineStatusCode(errMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export abstract class BotFrameworkAuthentication {
*/
abstract authenticateStreamingRequest(
authHeader: string,
channelIdHeader: string
channelIdHeader: string,
): Promise<AuthenticateRequestResult>;

/**
Expand Down Expand Up @@ -96,7 +96,7 @@ export abstract class BotFrameworkAuthentication {
protected async generateCallerId(
credentialFactory: ServiceClientCredentialsFactory,
claimsIdentity: ClaimsIdentity,
callerId: string
callerId: string,
): Promise<string | null> {
// Is the bot accepting all incoming messages?
if (await credentialFactory.isAuthenticationDisabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class BotFrameworkAuthenticationFactory {
credentialFactory: ServiceClientCredentialsFactory,
authConfiguration: AuthenticationConfiguration,
botFrameworkClientFetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>,
connectorClientOptions?: ConnectorClientOptions
connectorClientOptions?: ConnectorClientOptions,
): BotFrameworkAuthentication;

/**
Expand Down Expand Up @@ -84,7 +84,7 @@ export class BotFrameworkAuthenticationFactory {
maybeCredentialFactory?: ServiceClientCredentialsFactory,
maybeAuthConfiguration?: AuthenticationConfiguration,
maybeBotFrameworkClientFetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>,
maybeConnectorClientOptions: ConnectorClientOptions = {}
maybeConnectorClientOptions: ConnectorClientOptions = {},
): BotFrameworkAuthentication {
if (
!stringExt.isNilOrEmpty(maybeToChannelFromBotLoginUrl) ||
Expand All @@ -108,7 +108,7 @@ export class BotFrameworkAuthenticationFactory {
maybeCredentialFactory,
maybeAuthConfiguration,
maybeBotFrameworkClientFetch,
maybeConnectorClientOptions
maybeConnectorClientOptions,
);
} else {
// else apply the built in default behavior, which is either the public cloud or the gov cloud depending on whether we have a channelService value present
Expand All @@ -125,7 +125,7 @@ export class BotFrameworkAuthenticationFactory {
maybeCredentialFactory,
maybeAuthConfiguration,
maybeBotFrameworkClientFetch,
maybeConnectorClientOptions
maybeConnectorClientOptions,
);
} else if (maybeChannelService === GovernmentConstants.ChannelService) {
return new ParameterizedBotFrameworkAuthentication(
Expand All @@ -140,7 +140,7 @@ export class BotFrameworkAuthenticationFactory {
maybeCredentialFactory,
maybeAuthConfiguration,
maybeBotFrameworkClientFetch,
maybeConnectorClientOptions
maybeConnectorClientOptions,
);
} else {
// The ChannelService value is used an indicator of which built in set of constants to use. If it is not recognized, a full configuration is expected.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class BotFrameworkClientImpl implements BotFrameworkClient {
private readonly credentialsFactory: ServiceClientCredentialsFactory,
private readonly loginEndpoint: string,
private readonly botFrameworkClientFetch?: ReturnType<typeof botFrameworkClientFetchImpl>,
private readonly connectorClientOptions?: ConnectorClientOptions
private readonly connectorClientOptions?: ConnectorClientOptions,
) {
this.botFrameworkClientFetch ??= botFrameworkClientFetchImpl(this.connectorClientOptions);

Expand Down Expand Up @@ -82,7 +82,7 @@ export class BotFrameworkClientImpl implements BotFrameworkClient {
toUrl: string,
serviceUrl: string,
conversationId: string,
activity: Activity
activity: Activity,
): Promise<InvokeResponse<T>> {
z.object({
fromBotId: z.string().optional(),
Expand All @@ -104,7 +104,7 @@ export class BotFrameworkClientImpl implements BotFrameworkClient {
fromBotId,
toBotId,
this.loginEndpoint,
true
true,
);

// Capture current activity settings before changing them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class CertificateAppCredentials extends AppCredentials {
* @param certificateThumbprint A hex encoded thumbprint of the certificate.
* @param certificatePrivateKey A PEM encoded certificate private key.
* @param channelAuthTenant Tenant ID of the Azure AD tenant where the bot is created.
* * Required for SingleTenant app types.
* * Optional for MultiTenant app types. **Note**: '_botframework.com_' is the default tenant when no value is provided.
* - Required for SingleTenant app types.
* - Optional for MultiTenant app types. **Note**: '_botframework.com_' is the default tenant when no value is provided.
*
* More information: https://learn.microsoft.com/en-us/security/zero-trust/develop/identity-supported-account-types.
* @param oAuthScope Optional. The scope for the token.
Expand All @@ -42,7 +42,7 @@ export class CertificateAppCredentials extends AppCredentials {
certificatePrivateKey: string,
channelAuthTenant?: string,
oAuthScope?: string,
x5c?: string
x5c?: string,
) {
super(appId, channelAuthTenant, oAuthScope);
this.certificateThumbprint = certificateThumbprint;
Expand All @@ -58,7 +58,7 @@ export class CertificateAppCredentials extends AppCredentials {
this.createClientApplication(),
this.appId,
this.oAuthEndpoint,
this.oAuthScope
this.oAuthScope,
);
return this.credentials.getToken(forceRefresh);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class CertificateServiceClientCredentialsFactory extends ServiceClientCre
* @param certificateThumbprint A hex encoded thumbprint of the certificate.
* @param certificatePrivateKey A PEM encoded certificate private key.
* @param tenantId Tenant ID of the Azure AD tenant where the bot is created.
* * Required for SingleTenant app types.
* * Optional for MultiTenant app types. **Note**: '_botframework.com_' is the default tenant when no value is provided.
* - Required for SingleTenant app types.
* - Optional for MultiTenant app types. **Note**: '_botframework.com_' is the default tenant when no value is provided.
*
* More information: https://learn.microsoft.com/en-us/security/zero-trust/develop/identity-supported-account-types.
* @param x5c Optional. Enables application developers to achieve easy certificates roll-over in Azure AD:
Expand All @@ -43,7 +43,7 @@ export class CertificateServiceClientCredentialsFactory extends ServiceClientCre
certificateThumbprint: string,
certificatePrivateKey: string,
tenantId?: string,
x5c?: string
x5c?: string,
);

/**
Expand All @@ -54,8 +54,8 @@ export class CertificateServiceClientCredentialsFactory extends ServiceClientCre
* set this parameter to send the public certificate (BEGIN CERTIFICATE) to Azure AD, so that Azure AD can use it to validate the subject name based on a trusted issuer policy.
* @param certificatePrivateKey A PEM encoded certificate private key.
* @param tenantId Tenant ID of the Azure AD tenant where the bot is created.
* * Required for SingleTenant app types.
* * Optional for MultiTenant app types. **Note**: '_botframework.com_' is the default tenant when no value is provided.
* - Required for SingleTenant app types.
* - Optional for MultiTenant app types. **Note**: '_botframework.com_' is the default tenant when no value is provided.
*
* More information: https://learn.microsoft.com/en-us/security/zero-trust/develop/identity-supported-account-types.
*/
Expand All @@ -69,22 +69,22 @@ export class CertificateServiceClientCredentialsFactory extends ServiceClientCre
certificateThumbprintOrx5c: string,
certificatePrivateKey: string,
tenantId?: string,
x5c?: string
x5c?: string,
) {
super();

ok(appId?.trim(), 'CertificateServiceClientCredentialsFactory.constructor(): missing appId.');
ok(
certificatePrivateKey?.trim(),
'CertificateServiceClientCredentialsFactory.constructor(): missing certificatePrivateKey.'
'CertificateServiceClientCredentialsFactory.constructor(): missing certificatePrivateKey.',
);

if (certificateThumbprintOrx5c?.includes('-----BEGIN CERTIFICATE-----')) {
this.x5c = certificateThumbprintOrx5c;
} else {
ok(
certificateThumbprintOrx5c?.trim(),
'CertificateServiceClientCredentialsFactory.constructor(): missing certificateThumbprint or x5c value.'
'CertificateServiceClientCredentialsFactory.constructor(): missing certificateThumbprint or x5c value.',
);
this.certificateThumbprint = certificateThumbprintOrx5c;
this.x5c = x5c;
Expand Down Expand Up @@ -128,7 +128,7 @@ export class CertificateServiceClientCredentialsFactory extends ServiceClientCre
async createCredentials(appId: string, audience: string): Promise<ServiceClientCredentials> {
ok(
await this.isValidAppId(appId),
'CertificateServiceClientCredentialsFactory.createCredentials(): Invalid Managed ID.'
'CertificateServiceClientCredentialsFactory.createCredentials(): Invalid Managed ID.',
);

return new CertificateAppCredentials(
Expand All @@ -137,7 +137,7 @@ export class CertificateServiceClientCredentialsFactory extends ServiceClientCre
this.certificatePrivateKey,
this.tenantId,
audience,
this.x5c
this.x5c,
);
}
}
Loading

0 comments on commit fc263a2

Please sign in to comment.