Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Extends createUser to support multi-factor user creation. #718

Merged
merged 3 commits into from
Dec 10, 2019

Conversation

bojeil-google
Copy link
Contributor

Extends createUser to support multi-factor user creation.

Note that only phoneNumber and displayName are allowed to be passed in this operation.

Adds relevant unit and integration tests.

This capability is only available in staging.

Note that only phoneNumber and displayName are allowed to be passed in this operation.

Adds relevant unit and integration tests.

This capability is only available in staging.
Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

Looks pretty good. Just a few nits to improve on.

} catch (e) {
return Promise.reject(e);
}
if (request.mfaInfo.length === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: To keep the mutations to request to a minimum, you can do this:

const mfaInfo = [];
// Populate mfaInfo

if (request.mfaInfo.length > 0) {
  // You can drop the if condition, if you checked for isNonEmptyArray earlier.
  request.mfaInfo = mfaInfo;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -1145,6 +1162,34 @@ export abstract class AbstractAuthRequestHandler {
request.localId = request.uid;
delete request.uid;
}
// Construct mfa related user data.
if (validator.isNonNullObject(request.multiFactor)) {
if (validator.isArray(request.multiFactor.enrolledFactors)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isNonEmptyArray makes more sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

// Confirm second factors added to user.
expect(userRecord.multiFactor.enrolledFactors.length).to.equal(2);
// Confirm first enrolled second factor.
expect(userRecord.multiFactor.enrolledFactors[0].uid).not.to.be.undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

const firstFactor = enrolledFactors[0];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I set firstMultiFactor to userRecord.multiFactor.enrolledFactors[0]. That improves readability.

expect(userRecord.multiFactor.enrolledFactors[0].factorId)
.to.equal(enrolledFactors[0].factorId);
// Confirm second enrolled second factor.
expect(userRecord.multiFactor.enrolledFactors[1].uid).not.to.be.undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

const secondFactor = enrolledFactors[1];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I set secondMultiFactor to userRecord.multiFactor.enrolledFactors[1]. It is easier to read this way.

});
});

it('should be fulfilled given empty enrolled factors array', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems identical to the previous test case. Can we consolidate with an array?

const noEnrolledFactors = [ [], null ];
noEnrolledFactors.forEach((arg) => {
  ...
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

const unsupportedSecondFactor = {
secret: 'SECRET',
displayName: 'Google Authenticator on personal phone',
factorId: 'totp',
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment here indicating totp is not yet supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

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

LGTM

@bojeil-google
Copy link
Contributor Author

Thanks for the quick review!

@bojeil-google bojeil-google merged commit b59b17a into auth-mfa Dec 10, 2019
@bojeil-google bojeil-google deleted the auth-mfa-temp branch December 10, 2019 22:48
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.

None yet

2 participants