Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 88 additions & 10 deletions test/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,10 @@ describe('admin.auth', () => {
state: 'ENABLED',
factorIds: ['phone'],
},
// 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',
Expand All @@ -1199,6 +1203,9 @@ describe('admin.auth', () => {
state: 'DISABLED',
factorIds: [],
},
// 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',
},
Expand Down Expand Up @@ -1248,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);
}
});
});

Expand Down Expand Up @@ -1490,7 +1509,11 @@ describe('admin.auth', () => {
}
});

it('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);
Expand Down Expand Up @@ -1566,8 +1589,12 @@ describe('admin.auth', () => {
});
}
});

it('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);
Expand All @@ -1592,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);
}
});
});

Expand All @@ -1616,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);
Expand Down Expand Up @@ -1675,15 +1740,28 @@ describe('admin.auth', () => {
});

it('deleteTenant() should successfully delete the provided tenant', () => {
const allTenantIds: string[] = [];
const listAllTenantIds = (tenantIds: string[], nextPageToken?: string): Promise<void> => {
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);
});
});
});
Expand Down