fix(tasks): limit titles and display descriptions
This commit is contained in:
1 parent
1b8abd3509
commit
dcc201e7bb
6 files changed
+117
-76
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
@@ -94,6 +95,10 @@ func (s *Server) handleWorkRequest(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "identity, workflow, title, and instructions are required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if utf8.RuneCountInString(request.Title) > 80 {
|
||||
http.Error(w, "title must be 80 characters or fewer; put details in instructions", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
iface, code, err := s.workRequestInterface(r.Context(), request)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), code)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWorkRequestRejectsLongTitle(t *testing.T) {
|
||||
for _, title := range []string{strings.Repeat("a", 81), strings.Repeat("界", 81)} {
|
||||
t.Run(title[:3], func(t *testing.T) {
|
||||
body, err := json.Marshal(workRequest{Identity: "operator", Workflow: "implement", Title: title, Instructions: "Full task description"})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
request := httptest.NewRequestWithContext(t.Context(), http.MethodPost, "/api/work-requests", strings.NewReader(string(body)))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
request.Header.Set("X-Archie-CSRF", "1")
|
||||
response := httptest.NewRecorder()
|
||||
(&Server{}).handleWorkRequest(response, request)
|
||||
if response.Code != http.StatusBadRequest || !strings.Contains(response.Body.String(), "title must be 80 characters or fewer") {
|
||||
t.Fatalf("response = %d %s", response.Code, response.Body.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user