Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/tools/auth0/handlers/emailProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default class EmailProviderHandler extends DefaultHandler {
// HTTP DELETE on emails/provider is not supported, as this is not part of our vNext SDK.
if (Object.keys(emailProvider).length === 0) {
if (this.config('AUTH0_ALLOW_DELETE') === true) {
// If no existing provider, there is nothing to delete
if (!existing.name) return;
// await this.client.emails.delete(); is not supported
if (isEmpty(existing.credentials)) {
delete existing.credentials;
Expand Down
32 changes: 32 additions & 0 deletions test/tools/auth0/handlers/emailProvider.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,38 @@ describe('#emailProvider handler', () => {
expect(wasUpdateCalled).to.equal(true);
});

it('should not call update when emailProvider is empty and no existing provider exists, even when AUTH0_ALLOW_DELETE is true', async () => {
const AUTH0_ALLOW_DELETE = true;
let wasUpdateCalled = false;
let wasCreateCalled = false;
const auth0 = {
emails: {
provider: {
create: () => {
wasCreateCalled = true;
return Promise.resolve({});
},
update: () => {
wasUpdateCalled = true;
return Promise.resolve({});
},
get: () => Promise.resolve({}),
},
},
};

const handler = new emailProvider.default({
client: auth0,
config: () => AUTH0_ALLOW_DELETE,
});
const stageFn = Object.getPrototypeOf(handler).processChanges;

await stageFn.apply(handler, [{ emailProvider: {} }]);

expect(wasUpdateCalled).to.equal(false);
expect(wasCreateCalled).to.equal(false);
});

it('should not delete email provider if set to empty object and if AUTH0_ALLOW_DELETE is false', async () => {
const AUTH0_ALLOW_DELETE = false;

Expand Down