From cfa2f0e1024f6eac6f29e245fba657a19144c1d4 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Mon, 25 Apr 2022 17:21:19 +0100 Subject: [PATCH] Changed `/authentication/reset_all_passwords` to return 204 response code refs https://github.com/TryGhost/Toolbox/issues/308 - this endpoint has no body to return but it was initially implemented as returning a 200 which we couldn't change until 5.0 - this changes it to a 204, removes the serializer and updates tests to take this into account --- core/server/api/canary/authentication.js | 1 + .../api/canary/utils/serializers/output/authentication.js | 4 ---- .../api/admin/__snapshots__/authentication.test.js.snap | 6 ++---- test/regression/api/admin/authentication.test.js | 5 ++--- 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/core/server/api/canary/authentication.js b/core/server/api/canary/authentication.js index 912c818491..9e05a99869 100644 --- a/core/server/api/canary/authentication.js +++ b/core/server/api/canary/authentication.js @@ -221,6 +221,7 @@ module.exports = { }, resetAllPasswords: { + statusCode: 204, permissions: true, async query(frame) { await userService.resetAllPasswords(frame.options); diff --git a/core/server/api/canary/utils/serializers/output/authentication.js b/core/server/api/canary/utils/serializers/output/authentication.js index 5f26284a18..7faddbe22d 100644 --- a/core/server/api/canary/utils/serializers/output/authentication.js +++ b/core/server/api/canary/utils/serializers/output/authentication.js @@ -47,10 +47,6 @@ module.exports = { }; }, - resetAllPasswords(data, apiConfig, frame) { - frame.response = data; - }, - acceptInvitation(data, apiConfig, frame) { debug('acceptInvitation'); diff --git a/test/regression/api/admin/__snapshots__/authentication.test.js.snap b/test/regression/api/admin/__snapshots__/authentication.test.js.snap index 02dc8abb11..6234257c13 100644 --- a/test/regression/api/admin/__snapshots__/authentication.test.js.snap +++ b/test/regression/api/admin/__snapshots__/authentication.test.js.snap @@ -449,14 +449,12 @@ Object { } `; -exports[`Authentication API Reset all passwords reset all passwords returns 200 1: [headers] 1`] = ` +exports[`Authentication API Reset all passwords reset all passwords returns 204 1: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "2", - "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, - "vary": "Origin, Accept-Encoding", + "vary": "Origin", "x-powered-by": "Express", } `; diff --git a/test/regression/api/admin/authentication.test.js b/test/regression/api/admin/authentication.test.js index 424e70c228..da80299eb6 100644 --- a/test/regression/api/admin/authentication.test.js +++ b/test/regression/api/admin/authentication.test.js @@ -478,12 +478,11 @@ describe('Authentication API', function () { mockManager.restore(); }); - it('reset all passwords returns 200', async function () { + it('reset all passwords returns 204', async function () { await agent.post('authentication/reset_all_passwords') .header('Accept', 'application/json') .body({}) - // @TODO: change to a 204 in 5.0 - .expectStatus(200) + .expectStatus(204) .expectEmptyBody() .matchHeaderSnapshot({ etag: anyEtag