From 15cf1382614d90121ca980f19a4c2b7783fd0d29 Mon Sep 17 00:00:00 2001 From: Carlos IL Date: Thu, 30 Nov 2023 22:46:53 +0000 Subject: [PATCH 1/2] Add StatusPendingAutomatedRemoval handling to submit API and change handling of PendingRemoval domains, so they go back to preloaded --- api/api_test.go | 22 ++++++++++++++-------- api/domain_handlers.go | 22 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/api/api_test.go b/api/api_test.go index 1b40282..d37b72b 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -210,13 +210,6 @@ func TestAPI(t *testing.T) { Warnings: []hstspreload.Issue{{Code: "server.preload.already_pending"}}, }}}, - // pending automated removal - {"pending automated removal", data1, failNone, api.PendingAutomatedRemoval, "GET", "", - 200, jsonContentType, wantBody{text: "[\n \"pending-automated-removal.test\"\n]\n"}}, - {"pending automated removal status", data1, failNone, api.Status, "GET", "?domain=pending-automated-removal.test", - 200, jsonContentType, wantBody{state: &database.DomainState{ - Name: "pending-automated-removal.test", Status: database.StatusPendingAutomatedRemoval}}}, - // update {"garron.net pending", data1, failNone, api.Status, "GET", "?domain=garron.net", 200, jsonContentType, wantBody{state: &database.DomainState{ @@ -230,6 +223,19 @@ func TestAPI(t *testing.T) { {"pending 3", data1, failNone, api.Pending, "GET", "", 200, jsonContentType, wantBody{text: "[\n]\n"}}, + // pending automated removal + {"pending automated removal", data1, failNone, api.PendingAutomatedRemoval, "GET", "", + 200, jsonContentType, wantBody{text: "[\n \"pending-automated-removal.test\"\n]\n"}}, + {"pending automated removal status", data1, failNone, api.Status, "GET", "?domain=pending-automated-removal.test", + 200, jsonContentType, wantBody{state: &database.DomainState{ + Name: "pending-automated-removal.test", Status: database.StatusPendingAutomatedRemoval}}}, + // CHECK IF TEXT IS CORRECT vvv + {"submit previously pending automated removal", data1, failNone, api.Submit, "POST", "?domain=pending-automated-removal.test", + 200, jsonContentType, wantBody{text: "", issues: &emptyIssues}}, + {"pending-automated-removal.test status is now preloaded", data1, failNone, api.Status, "GET", "?domain=pending-automated-removal.test", + 200, jsonContentType, wantBody{state: &database.DomainState{ + Name: "pending-automated-removal.test", Status: database.StatusPreloaded}}}, + // create removable pending {"create removable pending eligible", data1, failNone, api.Submit, "POST", "?domain=removal-pending-eligible.test", 200, jsonContentType, wantBody{issues: &emptyIssues}}, @@ -325,7 +331,7 @@ func TestAPI(t *testing.T) { // update with removal {"update with removal", data2, failNone, api.Update, "GET", "", - 200, textContentType, wantBody{text: "The preload list has 2 entries.\n- # of preloaded HSTS entries: 1\n- # to be added in this update: 0\n- # to be removed this update: 4\n- # to be self-rejected this update: 2\nSuccess. 6 domain states updated.\n"}}, + 200, textContentType, wantBody{text: "The preload list has 2 entries.\n- # of preloaded HSTS entries: 1\n- # to be added in this update: 0\n- # to be removed this update: 5\n- # to be self-rejected this update: 2\nSuccess. 7 domain states updated.\n"}}, {"garron.net after update with removal", data2, failNone, api.Status, "GET", "?domain=garron.net", 200, jsonContentType, wantBody{state: &database.DomainState{ Name: "garron.net", Status: database.StatusRemoved}}}, diff --git a/api/domain_handlers.go b/api/domain_handlers.go index 68018fb..1671943 100644 --- a/api/domain_handlers.go +++ b/api/domain_handlers.go @@ -222,8 +222,6 @@ func (api API) Submit(w http.ResponseWriter, r *http.Request) { fallthrough case database.StatusRejected: fallthrough - case database.StatusPendingRemoval: - fallthrough case database.StatusRemoved: putErr := api.database.PutState(database.DomainState{ Name: domain, @@ -263,6 +261,26 @@ func (api API) Submit(w http.ResponseWriter, r *http.Request) { Errors: append(issues.Errors, issue), Warnings: issues.Warnings, } + case database.StatusPendingAutomatedRemoval: + fallthrough + case database.StatusPendingRemoval: + putErr := api.database.PutState(database.DomainState{ + Name: domain, + Status: database.StatusPreloaded, + IncludeSubDomains: true, + SubmissionDate: state.SubmissionDate, + }) + if putErr != nil { + issue := hstspreload.Issue{ + Code: "internal.server.preload.save_failed", + Summary: "Internal error", + Message: "Unable to save to the preloaded list.", + } + issues = hstspreload.Issues{ + Errors: append(issues.Errors, issue), + Warnings: issues.Warnings, + } + } default: issue := hstspreload.Issue{ Code: "internal.server.preload.unknown_status", From 779520f71ba0345cbca6b15073d28e94db53fdf3 Mon Sep 17 00:00:00 2001 From: Carlos IL Date: Thu, 30 Nov 2023 22:54:40 +0000 Subject: [PATCH 2/2] remove leftover comment --- api/api_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/api/api_test.go b/api/api_test.go index d37b72b..8470789 100644 --- a/api/api_test.go +++ b/api/api_test.go @@ -229,7 +229,6 @@ func TestAPI(t *testing.T) { {"pending automated removal status", data1, failNone, api.Status, "GET", "?domain=pending-automated-removal.test", 200, jsonContentType, wantBody{state: &database.DomainState{ Name: "pending-automated-removal.test", Status: database.StatusPendingAutomatedRemoval}}}, - // CHECK IF TEXT IS CORRECT vvv {"submit previously pending automated removal", data1, failNone, api.Submit, "POST", "?domain=pending-automated-removal.test", 200, jsonContentType, wantBody{text: "", issues: &emptyIssues}}, {"pending-automated-removal.test status is now preloaded", data1, failNone, api.Status, "GET", "?domain=pending-automated-removal.test",