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 Submit handling for domains in StatusPendingAutomatedRemoval and StatusPendingRemoval states #252

Merged
merged 2 commits into from
Dec 1, 2023
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
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
Loading