Skip to content

Commit

Permalink
Fix Submit handling for domains in StatusPendingAutomatedRemoval and …
Browse files Browse the repository at this point in the history
…StatusPendingRemoval states (#252)

Add StatusPendingAutomatedRemoval handling to submit API and change
handling of PendingRemoval domains, so they go back to preloaded if
submitted again.

This addresses the Submit part of #251
  • Loading branch information
carlosjoan91 committed Dec 1, 2023
1 parent e3bfdbb commit ecfa083
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
21 changes: 13 additions & 8 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -230,6 +223,18 @@ 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}}},
{"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}},
Expand Down Expand Up @@ -325,7 +330,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}}},
Expand Down
22 changes: 20 additions & 2 deletions api/domain_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit ecfa083

Please sign in to comment.