From 953f44eb99d76109c580b1da651a6b32fede989a Mon Sep 17 00:00:00 2001 From: Tracy Boehrer Date: Tue, 21 Mar 2023 09:08:25 -0500 Subject: [PATCH] Revert "Add expired token exception and tests" This reverts commit a2bdf1031d053719e3923f9becdeb1a126d16f32. --- .../botbuilder/tests/cloudAdapter.test.js | 63 +------------------ .../src/auth/jwtTokenExtractor.ts | 4 -- .../tests/auth/jwtTokenExtractor.test.js | 24 ------- 3 files changed, 2 insertions(+), 89 deletions(-) diff --git a/libraries/botbuilder/tests/cloudAdapter.test.js b/libraries/botbuilder/tests/cloudAdapter.test.js index bb6adc81b9..893efcf663 100644 --- a/libraries/botbuilder/tests/cloudAdapter.test.js +++ b/libraries/botbuilder/tests/cloudAdapter.test.js @@ -5,18 +5,9 @@ const assert = require('assert'); const httpMocks = require('node-mocks-http'); const net = require('net'); const sinon = require('sinon'); -const { - AuthenticationConfiguration, - BotFrameworkAuthenticationFactory, - allowedCallersClaimsValidator, -} = require('botframework-connector'); -const { - ConfigurationServiceClientCredentialFactory, - createBotFrameworkAuthenticationFromConfiguration, -} = require('botbuilder'); +const { BotFrameworkAuthenticationFactory } = require('botframework-connector'); const { CloudAdapter, ActivityTypes, INVOKE_RESPONSE_KEY } = require('..'); const { NamedPipeServer } = require('botframework-streaming'); -const { StatusCodes } = require('botframework-schema'); const FakeBuffer = () => Buffer.from([]); const FakeNodeSocket = () => new net.Socket(); @@ -25,7 +16,7 @@ const noop = () => null; describe('CloudAdapter', function () { let sandbox; beforeEach(function () { - sandbox = sinon.createSandbox({ useFakeTimers: false }); + sandbox = sinon.createSandbox({ useFakeTimers: true }); }); afterEach(function () { @@ -96,56 +87,6 @@ describe('CloudAdapter', function () { mock.verify(); }); - - it('throws exception on expired token', async function () { - // Expired token with removed AppID - const authorization = - 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjJaUXBKM1VwYmpBWVhZR2FYRUpsOGxWMFRPSSIsImtpZCI6IjJaUXBKM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pMocks.createRequest({ - method: 'POST', - headers: { authorization }, - body: activity, - }); - - const res = httpMocks.createResponse(); - - const logic = async (context) => { - context.turnState.set(INVOKE_RESPONSE_KEY, { - type: ActivityTypes.InvokeResponse, - value: { - status: 200, - body: 'invokeResponse', - }, - }); - }; - - const validTokenIssuers = []; - const claimsValidators = allowedCallersClaimsValidator(['*']); - const authConfig = new AuthenticationConfiguration([], claimsValidators, validTokenIssuers); - const credentialsFactory = new ConfigurationServiceClientCredentialFactory({ - MicrosoftAppId: '', - MicrosoftAppPassword: '', - MicrosoftAppType: '', - MicrosoftAppTenantId: '', - }); - - const botFrameworkAuthentication = createBotFrameworkAuthenticationFromConfiguration( - null, - credentialsFactory, - authConfig, - undefined, - undefined - ); - - const adapter = new CloudAdapter(botFrameworkAuthentication); - - await adapter.process(req, res, logic); - - assert.equal(StatusCodes.UNAUTHORIZED, res.statusCode); - }); }); describe('connectNamedPipe', function () { diff --git a/libraries/botframework-connector/src/auth/jwtTokenExtractor.ts b/libraries/botframework-connector/src/auth/jwtTokenExtractor.ts index fd2f1f71bf..0aea0117bd 100644 --- a/libraries/botframework-connector/src/auth/jwtTokenExtractor.ts +++ b/libraries/botframework-connector/src/auth/jwtTokenExtractor.ts @@ -196,10 +196,6 @@ export class JwtTokenExtractor { // from a validated JWT (see `verify` above), so no harm in doing so. return new ClaimsIdentity(claims, true); } catch (err) { - if (err.name === 'TokenExpiredError') { - console.error(err); - throw new AuthenticationError('The token has expired', StatusCodes.UNAUTHORIZED); - } console.error(`Error finding key for token. Available keys: ${metadata.key}`); throw err; } diff --git a/libraries/botframework-connector/tests/auth/jwtTokenExtractor.test.js b/libraries/botframework-connector/tests/auth/jwtTokenExtractor.test.js index f1027ae85e..d8ff38ef39 100644 --- a/libraries/botframework-connector/tests/auth/jwtTokenExtractor.test.js +++ b/libraries/botframework-connector/tests/auth/jwtTokenExtractor.test.js @@ -4,7 +4,6 @@ const assert = require('assert'); const { jwt } = require('botbuilder-test-utils'); const { JwtTokenExtractor } = require('../../lib/auth/jwtTokenExtractor'); -const { StatusCodes } = require('../../../botframework-schema'); describe('JwtTokenExtractor', function () { jwt.mocha(); @@ -38,27 +37,4 @@ describe('JwtTokenExtractor', function () { verify(); }); }); - - describe('validateToken', function () { - it('throws with expired token', async function () { - const { algorithm, issuer, metadata, sign } = jwt.stub(); - const key = 'value'; - const token = sign({ key }); - - const client = new JwtTokenExtractor( - { - issuer, - clockTimestamp: Date.now(), - clockTolerance: -10, - }, - metadata, - [algorithm] - ); - - await assert.rejects(client.getIdentityFromAuthHeader(`Bearer ${token}`), { - message: 'The token has expired', - statusCode: StatusCodes.UNAUTHORIZED, - }); - }); - }); });