Skip to content

Commit b26501b

Browse files
authored
Update multi-tenancy integration tests to run against auth emulator (#1453)
Update multi-tenancy integration tests to pass against auth emulator. Notable changes includes: - Not checking test phone numbers on tenant config object - Skipping tenant OIDC/SAML tests until it's supported in emulator Corresponding internal bug: b/192387245
1 parent 4bef8fa commit b26501b

File tree

1 file changed

+68
-10
lines changed

1 file changed

+68
-10
lines changed

test/integration/auth.spec.ts

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,10 @@ describe('admin.auth', () => {
11831183
state: 'ENABLED',
11841184
factorIds: ['phone'],
11851185
},
1186+
// These test phone numbers will not be checked when running integration
1187+
// tests against the emulator suite and are ignored in auth emulator
1188+
// altogether. For more information, please refer to this section of the
1189+
// auth emulator DD: go/firebase-auth-emulator-dd#heading=h.odk06so2ydjd
11861190
testPhoneNumbers: {
11871191
'+16505551234': '019287',
11881192
'+16505550676': '985235',
@@ -1199,6 +1203,9 @@ describe('admin.auth', () => {
11991203
state: 'DISABLED',
12001204
factorIds: [],
12011205
},
1206+
// Test phone numbers will not be checked when running integration tests
1207+
// against emulator suite. For more information, please refer to:
1208+
// go/firebase-auth-emulator-dd#heading=h.odk06so2ydjd
12021209
testPhoneNumbers: {
12031210
'+16505551234': '123456',
12041211
},
@@ -1248,7 +1255,13 @@ describe('admin.auth', () => {
12481255
createdTenantId = actualTenant.tenantId;
12491256
createdTenants.push(createdTenantId);
12501257
expectedCreatedTenant.tenantId = createdTenantId;
1251-
expect(actualTenant.toJSON()).to.deep.equal(expectedCreatedTenant);
1258+
const actualTenantObj = actualTenant.toJSON();
1259+
if (authEmulatorHost) {
1260+
// Not supported in Auth Emulator
1261+
delete (actualTenantObj as {testPhoneNumbers: Record<string, string>}).testPhoneNumbers;
1262+
delete expectedCreatedTenant.testPhoneNumbers;
1263+
}
1264+
expect(actualTenantObj).to.deep.equal(expectedCreatedTenant);
12521265
});
12531266
});
12541267

@@ -1490,7 +1503,11 @@ describe('admin.auth', () => {
14901503
}
14911504
});
14921505

1493-
it('should support CRUD operations', () => {
1506+
it('should support CRUD operations', function () {
1507+
// TODO(lisajian): Unskip once auth emulator supports OIDC/SAML
1508+
if (authEmulatorHost) {
1509+
return this.skip(); // Not yet supported in Auth Emulator.
1510+
}
14941511
return tenantAwareAuth.createProviderConfig(authProviderConfig)
14951512
.then((config) => {
14961513
assertDeepEqualUnordered(authProviderConfig, config);
@@ -1566,8 +1583,12 @@ describe('admin.auth', () => {
15661583
});
15671584
}
15681585
});
1569-
1570-
it('should support CRUD operations', () => {
1586+
1587+
it('should support CRUD operations', function () {
1588+
// TODO(lisajian): Unskip once auth emulator supports OIDC/SAML
1589+
if (authEmulatorHost) {
1590+
return this.skip(); // Not yet supported in Auth Emulator.
1591+
}
15711592
return tenantAwareAuth.createProviderConfig(authProviderConfig)
15721593
.then((config) => {
15731594
assertDeepEqualUnordered(authProviderConfig, config);
@@ -1592,7 +1613,13 @@ describe('admin.auth', () => {
15921613
it('getTenant() should resolve with expected tenant', () => {
15931614
return getAuth().tenantManager().getTenant(createdTenantId)
15941615
.then((actualTenant) => {
1595-
expect(actualTenant.toJSON()).to.deep.equal(expectedCreatedTenant);
1616+
const actualTenantObj = actualTenant.toJSON();
1617+
if (authEmulatorHost) {
1618+
// Not supported in Auth Emulator
1619+
delete (actualTenantObj as {testPhoneNumbers: Record<string, string>}).testPhoneNumbers;
1620+
delete expectedCreatedTenant.testPhoneNumbers;
1621+
}
1622+
expect(actualTenantObj).to.deep.equal(expectedCreatedTenant);
15961623
});
15971624
});
15981625

@@ -1616,6 +1643,24 @@ describe('admin.auth', () => {
16161643
// Test clearing of phone numbers.
16171644
testPhoneNumbers: null,
16181645
};
1646+
if (authEmulatorHost) {
1647+
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions)
1648+
.then((actualTenant) => {
1649+
const actualTenantObj = actualTenant.toJSON();
1650+
// Not supported in Auth Emulator
1651+
delete (actualTenantObj as {testPhoneNumbers: Record<string, string>}).testPhoneNumbers;
1652+
delete expectedUpdatedTenant.testPhoneNumbers;
1653+
expect(actualTenantObj).to.deep.equal(expectedUpdatedTenant);
1654+
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions2);
1655+
})
1656+
.then((actualTenant) => {
1657+
const actualTenantObj = actualTenant.toJSON();
1658+
// Not supported in Auth Emulator
1659+
delete (actualTenantObj as {testPhoneNumbers: Record<string, string>}).testPhoneNumbers;
1660+
delete expectedUpdatedTenant2.testPhoneNumbers;
1661+
expect(actualTenantObj).to.deep.equal(expectedUpdatedTenant2);
1662+
});
1663+
}
16191664
return getAuth().tenantManager().updateTenant(createdTenantId, updatedOptions)
16201665
.then((actualTenant) => {
16211666
expect(actualTenant.toJSON()).to.deep.equal(expectedUpdatedTenant);
@@ -1675,15 +1720,28 @@ describe('admin.auth', () => {
16751720
});
16761721

16771722
it('deleteTenant() should successfully delete the provided tenant', () => {
1723+
const allTenantIds: string[] = [];
1724+
const listAllTenantIds = (tenantIds: string[], nextPageToken?: string): Promise<void> => {
1725+
return getAuth().tenantManager().listTenants(100, nextPageToken)
1726+
.then((result) => {
1727+
result.tenants.forEach((tenant) => {
1728+
tenantIds.push(tenant.tenantId);
1729+
});
1730+
if (result.pageToken) {
1731+
return listAllTenantIds(tenantIds, result.pageToken);
1732+
}
1733+
});
1734+
};
1735+
16781736
return getAuth().tenantManager().deleteTenant(createdTenantId)
16791737
.then(() => {
1680-
return getAuth().tenantManager().getTenant(createdTenantId);
1738+
// Use listTenants() instead of getTenant() to check that the tenant
1739+
// is no longer present, because Auth Emulator implicitly creates the
1740+
// tenant in getTenant() when it is not found
1741+
return listAllTenantIds(allTenantIds);
16811742
})
16821743
.then(() => {
1683-
throw new Error('unexpected success');
1684-
})
1685-
.catch((error) => {
1686-
expect(error.code).to.equal('auth/tenant-not-found');
1744+
expect(allTenantIds).to.not.contain(createdTenantId);
16871745
});
16881746
});
16891747
});

0 commit comments

Comments
 (0)