Coder Social home page Coder Social logo

Comments (3)

buccfer avatar buccfer commented on May 20, 2024 1

@robertbullen Since issues like this one have been open for so long I created a different library aws-cognito-express.

from cognito-express.

robertbullen avatar robertbullen commented on May 20, 2024

The unit tests mask this bug because of how they are passing an async callback:

it("should check if Validate function can fail successfully when invalid token is passed (Promise)", async () => {
await strategy.init(async callback => {
try {
await strategy.validate("token");
expect(true).to.eql(false);
} catch (err) {
expect(err).to.eql("Not a valid JWT token");
};
});
});

Because the callback is async, it will be executed after the strategy.init() promise, and hence the test itself, resolves. This means that the expect assertions occur outside of the detection of chai.

Restructuring the test as follows:

	it("should check if Validate function can fail successfully when invalid token is passed (Promise)", async () => {
		await strategy.init(result => expect(result).to.eql(true));
		try {
			await strategy.validate("token");
		} catch (err) {
			expect(err).to.eql("Not a valid JWT token");
		};
	});

Surfaces the failure:

  Strategy Positive Scenarios
    ✓ should check if GeneratePem function exists
    ✓ should check if jwtVerify function exists
    ✓ should check if configurationIsCorrect function exists
    ✓ should check if Validate function exists
    ✓ should check if Strategy can initialized successfully (208ms)
    ✓ should check if Validate function can fail successfully when invalid token is passed (129ms)
    1) should check if Validate function can fail successfully when invalid token is passed (Promise)
    ✓ should check if Validate function can execute successfully by detecting an expired token (134ms)


  14 passing (632ms)
  1 failing

  1) Strategy Positive Scenarios
       should check if Validate function can fail successfully when invalid token is passed (Promise):
     AssertionError: expected [TypeError: callback is not a function] to deeply equal 'Not a valid JWT token'
      at Context.it (test/strategy.js:126:19)
      at <anonymous>

from cognito-express.

robertbullen avatar robertbullen commented on May 20, 2024

@ghdna, do you have any thoughts on or plans for this PR?

from cognito-express.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.