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

fix(api): prevent /account/destroy failing due to subhub errors #1741

Merged
merged 1 commit into from Jul 11, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/fxa-auth-server/lib/subhub/client.js
Expand Up @@ -307,12 +307,13 @@ module.exports = function(log, config) {
try {
return await api.deleteCustomer(uid);
} catch (err) {
log.error('subhub.deleteCustomer.failed', { uid, err });

if (err.statusCode === 404) {
throw error.unknownCustomer(uid);
// This method is called optimistically, so swallow `unknownCustomer` errors.
return { message: 'unknown customer' };
}

log.error('subhub.deleteCustomer.failed', { uid, err });

throw err;
}
},
Expand Down
13 changes: 13 additions & 0 deletions packages/fxa-auth-server/test/local/routes/account.js
Expand Up @@ -2780,6 +2780,19 @@ describe('/account/destroy', () => {
});
});

it('should fail if subhub.deleteCustomer fails', async () => {
mockSubhub.deleteCustomer = sinon.spy(async function() {
throw new Error('wibble');
});
let failed = false;
try {
await runTest(buildRoute(), mockRequest);
} catch (err) {
failed = true;
}
assert.isTrue(failed);
});

it('should not attempt to cancel subscriptions with config.subscriptions.enabled = false', async () => {
const route = buildRoute(false);
return runTest(route, mockRequest, () => {
Expand Down
13 changes: 11 additions & 2 deletions packages/fxa-auth-server/test/local/subhub/client.js
Expand Up @@ -567,11 +567,20 @@ describe('subhub client', () => {
assert.deepEqual(response, { message: 'wibble' });
});

it('should throw on unknown user', async () => {
it('should not fail for unknown user', async () => {
mockServer
.delete(`/v1/customer/${UID}`)
.reply(404, { message: 'invalid uid' });
const { subhub } = makeSubject();
const response = await subhub.deleteCustomer(UID);
assert.deepEqual(response, { message: 'unknown customer' });
});

it('should fail for other errors', async () => {
mockServer
.delete(`/v1/customer/${UID}`)
.reply(400, { message: 'wibble' });
const { subhub } = makeSubject();

let failed = false;

Expand All @@ -580,7 +589,7 @@ describe('subhub client', () => {
} catch (err) {
failed = true;

assert.equal(err.errno, error.ERRNO.UNKNOWN_SUBSCRIPTION_CUSTOMER);
assert.equal(err.message, 'wibble');
}

assert.isTrue(failed);
Expand Down