From 6ad4e2f92b7bd7f11426ed2877802aa6dc1a3dbc Mon Sep 17 00:00:00 2001 From: mraitersw Date: Wed, 9 Mar 2022 15:30:05 -0300 Subject: [PATCH 1/5] add test --- .../botbuilder-dialogs/tests/dialogSet.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libraries/botbuilder-dialogs/tests/dialogSet.test.js b/libraries/botbuilder-dialogs/tests/dialogSet.test.js index 85a6de6719..792248f5f5 100644 --- a/libraries/botbuilder-dialogs/tests/dialogSet.test.js +++ b/libraries/botbuilder-dialogs/tests/dialogSet.test.js @@ -12,6 +12,20 @@ describe('DialogSet', function () { const conversationState = new ConversationState(storage); const dialogState = conversationState.createProperty('dialogState'); + it('should check case insensitive', async function () { + const dialogSet = new DialogSet(dialogState); + dialogSet.add(new WaterfallDialog('a')).add(new WaterfallDialog('A')); + assert(dialogSet.find('a'), `dialog a found.`); + assert(dialogSet.find('a'), `dialog a found.`); + }); + + it('should check case sensitive', async function () { + const dialogSet = new DialogSet(dialogState); + dialogSet.add(new WaterfallDialog('a')).add(new WaterfallDialog('A')); + assert(dialogSet.find('a'), `dialog a found.`); + assert(dialogSet.find('A'), `dialog A found.`); + }); + it('should throw on createContext(undefined)', async function () { const dialogSet = new DialogSet(dialogState); await assert.rejects(async () => await dialogSet.createContext(undefined), { From 38d11892a968d338faa0812bc651bc391ddef851 Mon Sep 17 00:00:00 2001 From: mraitersw Date: Wed, 9 Mar 2022 15:32:14 -0300 Subject: [PATCH 2/5] Revert "add test" This reverts commit 6ad4e2f92b7bd7f11426ed2877802aa6dc1a3dbc. --- .../botbuilder-dialogs/tests/dialogSet.test.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/libraries/botbuilder-dialogs/tests/dialogSet.test.js b/libraries/botbuilder-dialogs/tests/dialogSet.test.js index 792248f5f5..85a6de6719 100644 --- a/libraries/botbuilder-dialogs/tests/dialogSet.test.js +++ b/libraries/botbuilder-dialogs/tests/dialogSet.test.js @@ -12,20 +12,6 @@ describe('DialogSet', function () { const conversationState = new ConversationState(storage); const dialogState = conversationState.createProperty('dialogState'); - it('should check case insensitive', async function () { - const dialogSet = new DialogSet(dialogState); - dialogSet.add(new WaterfallDialog('a')).add(new WaterfallDialog('A')); - assert(dialogSet.find('a'), `dialog a found.`); - assert(dialogSet.find('a'), `dialog a found.`); - }); - - it('should check case sensitive', async function () { - const dialogSet = new DialogSet(dialogState); - dialogSet.add(new WaterfallDialog('a')).add(new WaterfallDialog('A')); - assert(dialogSet.find('a'), `dialog a found.`); - assert(dialogSet.find('A'), `dialog A found.`); - }); - it('should throw on createContext(undefined)', async function () { const dialogSet = new DialogSet(dialogState); await assert.rejects(async () => await dialogSet.createContext(undefined), { From 168be8ea077944fcfa5da7e5e96787d32f9df45a Mon Sep 17 00:00:00 2001 From: mraitersw Date: Thu, 10 Mar 2022 11:05:45 -0300 Subject: [PATCH 3/5] add logger --- libraries/botbuilder/src/activityValidator.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/botbuilder/src/activityValidator.ts b/libraries/botbuilder/src/activityValidator.ts index d6d6c37978..fef6452b1d 100644 --- a/libraries/botbuilder/src/activityValidator.ts +++ b/libraries/botbuilder/src/activityValidator.ts @@ -19,6 +19,7 @@ export function validateAndFixActivity(activity: Activity): Activity { throw new Error('validateAndFixActivity(): invalid request body.'); } if (typeof activity.type !== 'string') { + console.warn('BadRequest: Missing activity or activity type.'); throw new Error('validateAndFixActivity(): missing activity type.'); } if (typeof activity.timestamp === 'string') { From 8a195bde0d6bc8224cdfd5bcb75581682bcf01a4 Mon Sep 17 00:00:00 2001 From: mraitersw Date: Fri, 11 Mar 2022 09:37:19 -0300 Subject: [PATCH 4/5] apply corrections --- libraries/botbuilder/src/activityValidator.ts | 1 - libraries/botbuilder/src/botFrameworkAdapter.ts | 6 ++++++ libraries/botbuilder/src/cloudAdapter.ts | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder/src/activityValidator.ts b/libraries/botbuilder/src/activityValidator.ts index fef6452b1d..d6d6c37978 100644 --- a/libraries/botbuilder/src/activityValidator.ts +++ b/libraries/botbuilder/src/activityValidator.ts @@ -19,7 +19,6 @@ export function validateAndFixActivity(activity: Activity): Activity { throw new Error('validateAndFixActivity(): invalid request body.'); } if (typeof activity.type !== 'string') { - console.warn('BadRequest: Missing activity or activity type.'); throw new Error('validateAndFixActivity(): missing activity type.'); } if (typeof activity.timestamp === 'string') { diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index 308a385d04..e414404253 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -1195,6 +1195,12 @@ export class BotFrameworkAdapter status = 400; const request = await parseRequest(req); + if (!req.body.type) { + console.warn('BadRequest: Missing activity or activity type.'); + status = StatusCodes.BAD_REQUEST; + return; + } + // Authenticate the incoming request status = 401; const authHeader: string = req.headers.authorization || req.headers.Authorization || ''; diff --git a/libraries/botbuilder/src/cloudAdapter.ts b/libraries/botbuilder/src/cloudAdapter.ts index 36af7138d5..3b5de6aaad 100644 --- a/libraries/botbuilder/src/cloudAdapter.ts +++ b/libraries/botbuilder/src/cloudAdapter.ts @@ -128,6 +128,7 @@ export class CloudAdapter extends CloudAdapterBase implements BotFrameworkHttpAd const activity = validateAndFixActivity(ActivityT.parse(req.body)); if (!activity.type) { + console.warn('BadRequest: Missing activity or activity type.'); return end(StatusCodes.BAD_REQUEST); } From a617d3e359cc8662600281f6d62f46f5c8be65a7 Mon Sep 17 00:00:00 2001 From: mraitersw Date: Fri, 11 Mar 2022 10:14:56 -0300 Subject: [PATCH 5/5] delete unsed code --- libraries/botbuilder/src/botFrameworkAdapter.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libraries/botbuilder/src/botFrameworkAdapter.ts b/libraries/botbuilder/src/botFrameworkAdapter.ts index e414404253..308a385d04 100644 --- a/libraries/botbuilder/src/botFrameworkAdapter.ts +++ b/libraries/botbuilder/src/botFrameworkAdapter.ts @@ -1195,12 +1195,6 @@ export class BotFrameworkAdapter status = 400; const request = await parseRequest(req); - if (!req.body.type) { - console.warn('BadRequest: Missing activity or activity type.'); - status = StatusCodes.BAD_REQUEST; - return; - } - // Authenticate the incoming request status = 401; const authHeader: string = req.headers.authorization || req.headers.Authorization || '';