Skip to content

Conversation

@MaximilianGaedig
Copy link
Contributor

@MaximilianGaedig MaximilianGaedig commented Aug 2, 2023

Summary

This is an obvious fix, you can see the async function being defined a couple lines down the file so this needs to be awaited

Linked issue(s)

#204

Involved parts of the project

Authorization

Copy link
Member

@jankapunkt jankapunkt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the following test in tests/integration/handlers/authorize-handler.tests line 553

to

it('should return the `code` if successful', function() {
      const client = { grants: ['authorization_code'], redirectUris: ['http://example.com/cb'] };
      const model = {
        getAccessToken: function() {
          return {
            client: client,
            user: {},
            accessTokenExpiresAt: new Date(new Date().getTime() + 10000)
          };
        },
        getClient: function() {
          return client;
        },
        generateAuthorizationCode: async () => 'some-code',
        saveAuthorizationCode: async function(code) {
          return { authorizationCode: code.authorizationCode, client: client };
        }
      };
      const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
      const request = new Request({
        body: {
          client_id: 12345,
          response_type: 'code'
        },
        headers: {
          'Authorization': 'Bearer foo'
        },
        method: {},
        query: {
          state: 'foobar'
        }
      });
      const response = new Response({ body: {}, headers: {} });

      return handler.handle(request, response)
        .then(function(data) {
          data.should.eql({
            authorizationCode: 'some-code',
            client: client
          });
        })
        .catch(should.fail);
    });
  });

This should cover the issue you detecte and fail if the function would not be awaited.

note please run the linter to make sure the formatting is not broken :-)

@MaximilianGaedig
Copy link
Contributor Author

Done :)

@jankapunkt jankapunkt merged commit 47916a7 into node-oauth:release-5.0.0 Aug 2, 2023
@jankapunkt jankapunkt linked an issue Aug 2, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

generateAuthorizationCode not being awaited

2 participants