Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: management methods throwing error on access #500

Merged
merged 2 commits into from
Jun 19, 2020

Conversation

pmalouin
Copy link
Contributor

Changes

A few of the methods defined directly on the ManagementClient are throwing errors when accessed:

var ManagementClient = require('auth0').ManagementClient;
var management = new ManagementClient({
  token: '{YOUR_API_V2_TOKEN}',
  domain: '{YOUR_ACCOUNT}.auth0.com'
});
management.updateGuardianFactor

Throws:

TypeError: Cannot read property 'bind' of undefined
    at ManagementClient.get (./node-auth0/src/utils.js:59:37)

After debugging, I found that the error comes from the utils.wrapPropertyMethod() method that only supports a single level of nesting for propertyMethod (ex. a.b works, but not a.b.c).

In this PR, I review all methods defined on ManagementClient and ensure they all use one level of nesting instead of 2.

I also fixed the unit test that was supposed to catch this.

References

Please include relevant links supporting this change such as a:

  • support ticket
  • community post
  • StackOverflow post
  • support forum thread

Testing

Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

  • This change adds unit test coverage
  • This change adds integration test coverage

Checklist

@pmalouin pmalouin requested a review from a team June 19, 2020 20:41
@@ -839,7 +838,7 @@ describe('ManagementClient', function() {
'getUsers',
'getUser',
'deleteAllUsers',
'deleteUsers',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method does not exist, but deleteUser does.

@@ -872,12 +878,10 @@ describe('ManagementClient', function() {
this.client = new ManagementClient(config);
});

for (var i = 0, l = methods.length; i < l; i++) {
method = methods[i];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

method was always set to the last item in the methods array.

@pmalouin pmalouin force-pushed the fix-management-guardian-methods branch from dde3721 to f66875d Compare June 19, 2020 20:46
@@ -50,6 +50,9 @@ utils.generateClientInfo = function() {
*/
utils.wrapPropertyMethod = function(Parent, name, propertyMethod) {
var path = propertyMethod.split('.');
if (path.length > 2) {
throw new Error('wrapPropertyMethod() only supports one level of nesting for propertyMethod');
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@lbalmaceda lbalmaceda merged commit 2f41322 into auth0:master Jun 19, 2020
@lbalmaceda lbalmaceda added this to the v2Next milestone Jun 19, 2020
@davidpatrick davidpatrick mentioned this pull request Jun 30, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants