From 538cfe5ca28cb1aef3a692c829c954f43b9ed0c2 Mon Sep 17 00:00:00 2001 From: Lisa Jian Date: Mon, 11 Oct 2021 18:09:49 -0700 Subject: [PATCH 1/3] Update multi-tenancy tests to run against auth emulator --- test/integration/auth.spec.ts | 47 ++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index 946d43e34b..bcaab20c5d 100644 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -1183,10 +1183,9 @@ describe('admin.auth', () => { state: 'ENABLED', factorIds: ['phone'], }, - testPhoneNumbers: { - '+16505551234': '019287', - '+16505550676': '985235', - }, + // Test phone numbers are ignored in auth emulator. For more information, + // please refer to this section of the auth emulator DD: + // go/firebase-auth-emulator-dd#heading=h.odk06so2ydjd }; const expectedUpdatedTenant: any = { displayName: 'testTenantUpdated', @@ -1199,9 +1198,10 @@ describe('admin.auth', () => { state: 'DISABLED', factorIds: [], }, - testPhoneNumbers: { - '+16505551234': '123456', - }, + // Though test phone numbers are ignored in the auth emulator, + // non-standard update behavior will still initialize this to an empty + // object. + testPhoneNumbers: {}, }; const expectedUpdatedTenant2: any = { displayName: 'testTenantUpdated', @@ -1214,6 +1214,10 @@ describe('admin.auth', () => { state: 'ENABLED', factorIds: ['phone'], }, + // Though test phone numbers are ignored in the auth emulator, + // non-standard update behavior will still initialize this to an empty + // object. + testPhoneNumbers: {}, }; // https://mochajs.org/ @@ -1490,7 +1494,8 @@ describe('admin.auth', () => { } }); - it('should support CRUD operations', () => { + // TODO(lisajian): Unskip once auth emulator supports OIDC/SAML + it.skip('should support CRUD operations', () => { return tenantAwareAuth.createProviderConfig(authProviderConfig) .then((config) => { assertDeepEqualUnordered(authProviderConfig, config); @@ -1567,7 +1572,8 @@ describe('admin.auth', () => { } }); - it('should support CRUD operations', () => { + // TODO(lisajian): Unskip once auth emulator supports OIDC/SAML + it.skip('should support CRUD operations', () => { return tenantAwareAuth.createProviderConfig(authProviderConfig) .then((config) => { assertDeepEqualUnordered(authProviderConfig, config); @@ -1675,15 +1681,28 @@ describe('admin.auth', () => { }); it('deleteTenant() should successfully delete the provided tenant', () => { + const allTenantIds: string[] = []; + const listAllTenantIds = (tenantIds: string[], nextPageToken?: string): Promise => { + return getAuth().tenantManager().listTenants(100, nextPageToken) + .then((result) => { + result.tenants.forEach((tenant) => { + tenantIds.push(tenant.tenantId); + }); + if (result.pageToken) { + return listAllTenantIds(tenantIds, result.pageToken); + } + }); + }; + return getAuth().tenantManager().deleteTenant(createdTenantId) .then(() => { - return getAuth().tenantManager().getTenant(createdTenantId); + // Use listTenants() instead of getTenant() to check that the tenant + // is no longer present, because Auth Emulator implicitly creates the + // tenant in getTenant() when it is not found + return listAllTenantIds(allTenantIds); }) .then(() => { - throw new Error('unexpected success'); - }) - .catch((error) => { - expect(error.code).to.equal('auth/tenant-not-found'); + expect(allTenantIds).to.not.contain(createdTenantId); }); }); }); From f57c7d7056d68fc3ef39119070551e8f599cfdf0 Mon Sep 17 00:00:00 2001 From: Lisa Jian Date: Thu, 14 Oct 2021 16:43:40 -0700 Subject: [PATCH 2/3] Branch tenant checks based on emulator vs prod --- test/integration/auth.spec.ts | 95 ++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 18 deletions(-) diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index bcaab20c5d..da8c68bae6 100644 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -1183,9 +1183,14 @@ describe('admin.auth', () => { state: 'ENABLED', factorIds: ['phone'], }, - // Test phone numbers are ignored in auth emulator. For more information, - // please refer to this section of the auth emulator DD: - // go/firebase-auth-emulator-dd#heading=h.odk06so2ydjd + // These test phone numbers will not be checked when running integration + // tests against the emulator suite and are ignored in auth emulator + // altogether. For more information, please refer to this section of the + // auth emulator DD: go/firebase-auth-emulator-dd#heading=h.odk06so2ydjd + testPhoneNumbers: { + '+16505551234': '019287', + '+16505550676': '985235', + }, }; const expectedUpdatedTenant: any = { displayName: 'testTenantUpdated', @@ -1198,10 +1203,12 @@ describe('admin.auth', () => { state: 'DISABLED', factorIds: [], }, - // Though test phone numbers are ignored in the auth emulator, - // non-standard update behavior will still initialize this to an empty - // object. - testPhoneNumbers: {}, + // Test phone numbers will not be checked when running integration tests + // against emulator suite. For more information, please refer to: + // go/firebase-auth-emulator-dd#heading=h.odk06so2ydjd + testPhoneNumbers: { + '+16505551234': '123456', + }, }; const expectedUpdatedTenant2: any = { displayName: 'testTenantUpdated', @@ -1214,10 +1221,6 @@ describe('admin.auth', () => { state: 'ENABLED', factorIds: ['phone'], }, - // Though test phone numbers are ignored in the auth emulator, - // non-standard update behavior will still initialize this to an empty - // object. - testPhoneNumbers: {}, }; // https://mochajs.org/ @@ -1252,7 +1255,19 @@ describe('admin.auth', () => { createdTenantId = actualTenant.tenantId; createdTenants.push(createdTenantId); expectedCreatedTenant.tenantId = createdTenantId; - expect(actualTenant.toJSON()).to.deep.equal(expectedCreatedTenant); + const actualTenantObj = actualTenant.toJSON(); + if (authEmulatorHost) { + expect(actualTenantObj).to.have.property('displayName') + .eql(expectedCreatedTenant.displayName); + expect(actualTenantObj).to.have.property('emailSignInConfig') + .eql(expectedCreatedTenant.emailSignInConfig); + expect(actualTenantObj).to.have.property('anonymousSignInEnabled') + .eql(expectedCreatedTenant.anonymousSignInEnabled); + expect(actualTenantObj).to.have.property('multiFactorConfig') + .eql(expectedCreatedTenant.multiFactorConfig); + } else { + expect(actualTenantObj).to.deep.equal(expectedCreatedTenant); + } }); }); @@ -1494,8 +1509,11 @@ describe('admin.auth', () => { } }); - // TODO(lisajian): Unskip once auth emulator supports OIDC/SAML - it.skip('should support CRUD operations', () => { + it('should support CRUD operations', function () { + // TODO(lisajian): Unskip once auth emulator supports OIDC/SAML + if (authEmulatorHost) { + return this.skip(); // Not yet supported in Auth Emulator. + } return tenantAwareAuth.createProviderConfig(authProviderConfig) .then((config) => { assertDeepEqualUnordered(authProviderConfig, config); @@ -1571,9 +1589,12 @@ describe('admin.auth', () => { }); } }); - - // TODO(lisajian): Unskip once auth emulator supports OIDC/SAML - it.skip('should support CRUD operations', () => { + + it('should support CRUD operations', function () { + // TODO(lisajian): Unskip once auth emulator supports OIDC/SAML + if (authEmulatorHost) { + return this.skip(); // Not yet supported in Auth Emulator. + } return tenantAwareAuth.createProviderConfig(authProviderConfig) .then((config) => { assertDeepEqualUnordered(authProviderConfig, config); @@ -1598,7 +1619,19 @@ describe('admin.auth', () => { it('getTenant() should resolve with expected tenant', () => { return getAuth().tenantManager().getTenant(createdTenantId) .then((actualTenant) => { - expect(actualTenant.toJSON()).to.deep.equal(expectedCreatedTenant); + const actualTenantObj = actualTenant.toJSON(); + if (authEmulatorHost) { + expect(actualTenantObj).to.have.property('displayName') + .eql(expectedCreatedTenant.displayName); + expect(actualTenantObj).to.have.property('emailSignInConfig') + .eql(expectedCreatedTenant.emailSignInConfig); + expect(actualTenantObj).to.have.property('anonymousSignInEnabled') + .eql(expectedCreatedTenant.anonymousSignInEnabled); + expect(actualTenantObj).to.have.property('multiFactorConfig') + .eql(expectedCreatedTenant.multiFactorConfig); + } else { + expect(actualTenantObj).to.deep.equal(expectedCreatedTenant); + } }); }); @@ -1622,6 +1655,32 @@ describe('admin.auth', () => { // Test clearing of phone numbers. testPhoneNumbers: null, }; + if (authEmulatorHost) { + return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions) + .then((actualTenant) => { + const actualTenantObj = actualTenant.toJSON(); + expect(actualTenantObj).to.have.property('displayName') + .eql(expectedUpdatedTenant.displayName); + expect(actualTenantObj).to.have.property('emailSignInConfig') + .eql(expectedUpdatedTenant.emailSignInConfig); + expect(actualTenantObj).to.have.property('anonymousSignInEnabled') + .eql(expectedUpdatedTenant.anonymousSignInEnabled); + expect(actualTenantObj).to.have.property('multiFactorConfig') + .eql(expectedUpdatedTenant.multiFactorConfig); + return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2); + }) + .then((actualTenant) => { + const actualTenantObj = actualTenant.toJSON(); + expect(actualTenantObj).to.have.property('displayName') + .eql(expectedUpdatedTenant2.displayName); + expect(actualTenantObj).to.have.property('emailSignInConfig') + .eql(expectedUpdatedTenant2.emailSignInConfig); + expect(actualTenantObj).to.have.property('anonymousSignInEnabled') + .eql(expectedUpdatedTenant2.anonymousSignInEnabled); + expect(actualTenantObj).to.have.property('multiFactorConfig') + .eql(expectedUpdatedTenant2.multiFactorConfig); + }); + } return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions) .then((actualTenant) => { expect(actualTenant.toJSON()).to.deep.equal(expectedUpdatedTenant); From 50f756b02886fc2a31c2c7602f869a04285a07a9 Mon Sep 17 00:00:00 2001 From: Lisa Jian Date: Fri, 15 Oct 2021 10:42:48 -0700 Subject: [PATCH 3/3] Shorten tenant tests --- test/integration/auth.spec.ts | 52 +++++++++++------------------------ 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/test/integration/auth.spec.ts b/test/integration/auth.spec.ts index da8c68bae6..2b8e287a94 100644 --- a/test/integration/auth.spec.ts +++ b/test/integration/auth.spec.ts @@ -1257,17 +1257,11 @@ describe('admin.auth', () => { expectedCreatedTenant.tenantId = createdTenantId; const actualTenantObj = actualTenant.toJSON(); if (authEmulatorHost) { - expect(actualTenantObj).to.have.property('displayName') - .eql(expectedCreatedTenant.displayName); - expect(actualTenantObj).to.have.property('emailSignInConfig') - .eql(expectedCreatedTenant.emailSignInConfig); - expect(actualTenantObj).to.have.property('anonymousSignInEnabled') - .eql(expectedCreatedTenant.anonymousSignInEnabled); - expect(actualTenantObj).to.have.property('multiFactorConfig') - .eql(expectedCreatedTenant.multiFactorConfig); - } else { - expect(actualTenantObj).to.deep.equal(expectedCreatedTenant); + // Not supported in Auth Emulator + delete (actualTenantObj as {testPhoneNumbers: Record}).testPhoneNumbers; + delete expectedCreatedTenant.testPhoneNumbers; } + expect(actualTenantObj).to.deep.equal(expectedCreatedTenant); }); }); @@ -1621,17 +1615,11 @@ describe('admin.auth', () => { .then((actualTenant) => { const actualTenantObj = actualTenant.toJSON(); if (authEmulatorHost) { - expect(actualTenantObj).to.have.property('displayName') - .eql(expectedCreatedTenant.displayName); - expect(actualTenantObj).to.have.property('emailSignInConfig') - .eql(expectedCreatedTenant.emailSignInConfig); - expect(actualTenantObj).to.have.property('anonymousSignInEnabled') - .eql(expectedCreatedTenant.anonymousSignInEnabled); - expect(actualTenantObj).to.have.property('multiFactorConfig') - .eql(expectedCreatedTenant.multiFactorConfig); - } else { - expect(actualTenantObj).to.deep.equal(expectedCreatedTenant); + // Not supported in Auth Emulator + delete (actualTenantObj as {testPhoneNumbers: Record}).testPhoneNumbers; + delete expectedCreatedTenant.testPhoneNumbers; } + expect(actualTenantObj).to.deep.equal(expectedCreatedTenant); }); }); @@ -1659,26 +1647,18 @@ describe('admin.auth', () => { return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions) .then((actualTenant) => { const actualTenantObj = actualTenant.toJSON(); - expect(actualTenantObj).to.have.property('displayName') - .eql(expectedUpdatedTenant.displayName); - expect(actualTenantObj).to.have.property('emailSignInConfig') - .eql(expectedUpdatedTenant.emailSignInConfig); - expect(actualTenantObj).to.have.property('anonymousSignInEnabled') - .eql(expectedUpdatedTenant.anonymousSignInEnabled); - expect(actualTenantObj).to.have.property('multiFactorConfig') - .eql(expectedUpdatedTenant.multiFactorConfig); + // Not supported in Auth Emulator + delete (actualTenantObj as {testPhoneNumbers: Record}).testPhoneNumbers; + delete expectedUpdatedTenant.testPhoneNumbers; + expect(actualTenantObj).to.deep.equal(expectedUpdatedTenant); return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2); }) .then((actualTenant) => { const actualTenantObj = actualTenant.toJSON(); - expect(actualTenantObj).to.have.property('displayName') - .eql(expectedUpdatedTenant2.displayName); - expect(actualTenantObj).to.have.property('emailSignInConfig') - .eql(expectedUpdatedTenant2.emailSignInConfig); - expect(actualTenantObj).to.have.property('anonymousSignInEnabled') - .eql(expectedUpdatedTenant2.anonymousSignInEnabled); - expect(actualTenantObj).to.have.property('multiFactorConfig') - .eql(expectedUpdatedTenant2.multiFactorConfig); + // Not supported in Auth Emulator + delete (actualTenantObj as {testPhoneNumbers: Record}).testPhoneNumbers; + delete expectedUpdatedTenant2.testPhoneNumbers; + expect(actualTenantObj).to.deep.equal(expectedUpdatedTenant2); }); } return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions)