Skip to content

Adds basic integration tests for the following in multi-tenancy context: #584

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

Merged
merged 3 commits into from
Jun 27, 2019

Conversation

bojeil-google
Copy link
Contributor

  • User management
  • Custom claims
  • Import users
  • List users
  • Token revocation
  • Email link generation (skipped due to backend bug)
  • OIDC/SAML management APIs.

- User management
- Custom claims
- Import users
- List users
- Token revocation
- Email link generation (skipped due to backend bug)
- OIDC/SAML management APIs.
Copy link

@wuyanna wuyanna left a comment

Choose a reason for hiding this comment

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

How about verifyIdToken()? Do we need integration test for that, or is unit test sufficient already?

@bojeil-google
Copy link
Contributor Author

I want to add testing for verifyIdToken() but i want a token scoped for a specific tenant. We pull in the client SDK Node.js library which can help us sign in to a specific tenant but the latest version does not support multi-tenancy (not publicly available). So for now, I have to wait for client SDK to be updated before we can add that test.

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.

This looks pretty good. Just a few suggestions for improvement.

.then((userRecord) => {
createdUserUid = userRecord.uid;
expect(userRecord.tenantId).to.equal(createdTenantId);
expect(userRecord.email.toLowerCase()).to.equal(newUserData.email.toLowerCase());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we call toLowerCase() on line 515 instead?

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


it('revokeRefreshTokens() should revoke the tokens for the tenant specific user', () => {
// Revoke refresh tokens.
currentTime = new Date().getTime() - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps add a comment to explain - 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 made some changes to clarify and added comments.

.then((listUsersResult) => {
// Confirm expected user returned in the list.
let expectedUserFound = false;
listUsersResult.users.forEach((user) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps the functional style is more readable for this sort of things:

const allUsersBelongToTenant = listUsersResult.users.every(user => user.tenantId == createdTenantId);
expect(allUsersBelongToTenant).to.be.true;

const knownUserInTenant = listUsersResult.users.some(user => user.uid == createdUserUid);
expect(knownUserInTenant).to.be.true;

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 rawSalt = 'NaCl';

before(() => {
tenantAwareAuth = admin.auth().forTenant(createdTenantId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do this outside before? Something like:

const tenantAwareAuth = admin.auth().forTenant(createdTenantId);

Here and in other similar describe blocks.

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 can't because initializeApp has to be called before I do this. We call it in before at setup: https://github.com/firebase/firebase-admin-node/blob/auth-multi-tenancy/test/integration/setup.ts#L40

It is not worth a refactor.

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 bojeil-google merged commit 3f37111 into auth-multi-tenancy Jun 27, 2019
@bojeil-google bojeil-google deleted the temp-multi-tenancy branch August 6, 2019 09:02
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.

3 participants