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

Defines TenantAwareAuth #551

Merged
merged 4 commits into from
Jun 10, 2019
Merged

Conversation

bojeil-google
Copy link
Contributor

Defines TenantAwareAuth and its user management APIs, email action link APIs, OIDC/SAML provider config mgmt APIs.

…nk APIs, OIDC/SAML provider config mgmt APIs.
src/auth/auth.ts Outdated Show resolved Hide resolved
…uth API requests.

Adds detailed tenant mismatch error for uploadAccount on tenant Id mismatch for TenantAwareAuth.
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 suggestions, and a question about the tests.

src/auth/auth-api-request.ts Show resolved Hide resolved
src/auth/auth.ts Outdated Show resolved Hide resolved
utils.getProjectId(auth.app),
new TenantAwareAuthRequestHandler(auth.app, tenantId),
cryptoSignerFromApp(auth.app));
utils.addReadonlyGetter(this, 'tenantId', tenantId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just mark the constructor argument as public readonly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One problem with this is that if they are not using typescript, they can overwrite this without any error thrown. I tried it and the property can be overwritten. Since this is publicly available, i think we should enforce the readonly.

Copy link
Contributor

Choose a reason for hiding this comment

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

I expected the TS compiler to generate a readonly getter for this, but looks like that only happens if we expose this as a getter in the code. So this is ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

I expected the TS compiler to add a readonly getter, but looks like that only happens if we define a getter explicitly here. So this is ok.

src/auth/auth.ts Outdated
*/
export class Auth extends BaseAuth implements FirebaseServiceInterface {
public INTERNAL: AuthInternals = new AuthInternals();
private tenantsMap: {[key: string]: TenantAwareAuth};
Copy link
Contributor

Choose a reason for hiding this comment

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

readonly

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

mockCredentialAuth.verifyIdToken(mocks.generateIdToken());
}).to.throw(expected);
});
it('should not throw on valid tenant ID', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty much the same as the following test case. Consider removing it.

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

@@ -47,6 +49,15 @@ chai.use(chaiAsPromised);
const expect = chai.expect;


interface AuthTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

This file is bit complicated to review. Can I assume it's just running the existing tests in 2 test configs, with the tests specific to an auth implementation enclosed in if-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.

Yeah, I completely understand. This is the same GitHub diff issue. This should no longer be an issue in the next PRs.
You are mostly right. Same tests are run for both. There are cases where I add specific tests for tenant specific behavior. For example:

  • createCustomToken should throw unsupported tenant operation error
  • verifyIdToken with token missing or mismatching tenant ID
  • verifySessionCookie with missing or mismatching tenant ID
  • importUsers with explicit mismatching tenant IDs
  • confirm createSessionCookie calls verifyIdToken before making call to create a session cookie

I do this by checking testConfig.Auth === TenantAwareAuth

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. Thanks.

utils.getProjectId(auth.app),
new TenantAwareAuthRequestHandler(auth.app, tenantId),
cryptoSignerFromApp(auth.app));
utils.addReadonlyGetter(this, 'tenantId', tenantId);
Copy link
Contributor

Choose a reason for hiding this comment

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

I expected the TS compiler to add a readonly getter, but looks like that only happens if we define a getter explicitly here. So this is ok.

@bojeil-google
Copy link
Contributor Author

Thanks for the review!

@bojeil-google bojeil-google merged commit 8507d93 into auth-multi-tenancy Jun 10, 2019
@bojeil-google bojeil-google deleted the temp-multi-tenancy branch June 10, 2019 06:25
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