diff --git a/view/who.go b/view/who.go index c714f07..160cabf 100644 --- a/view/who.go +++ b/view/who.go @@ -21,6 +21,7 @@ import ( "github.com/gomarkdown/markdown" "github.com/gomarkdown/markdown/html" "github.com/gomarkdown/markdown/parser" + "github.com/google/uuid" "github.com/iancoleman/orderedmap" "go.mongodb.org/mongo-driver/bson" ) @@ -198,6 +199,11 @@ func whoPost(namespace string, g storage.RateLimitedGraph, w http.ResponseWriter return nil } one.Name = id + if one.ID != "" { + http.Error(w, `{"error":"cannot specify ID in body"}`, http.StatusBadRequest) + return nil + } + one.ID = uuid.New().String() if err := g.Insert(r.Context(), namespace, one); err != nil { return err } diff --git a/view/who_test.go b/view/who_test.go index fbb5261..0f7a766 100644 --- a/view/who_test.go +++ b/view/who_test.go @@ -278,7 +278,8 @@ func TestWho(t *testing.T) { handler, _, iwant, _, can := fresh(t) defer can() want := iwant - r := httptest.NewRequest(http.MethodPost, "/who?namespace=col&id="+want.Name, strings.NewReader(`{"title":"this should fail to insert", "_id":"trash"}`)) + want.ID = "" + r := httptest.NewRequest(http.MethodPost, "/who?namespace=col&id="+want.Name, strings.NewReader(`{"title":"this should fail to insert"}`)) w := httptest.NewRecorder() handler.ServeHTTP(w, r) if w.Code != http.StatusConflict { @@ -291,7 +292,7 @@ func TestWho(t *testing.T) { defer can() iwant := want iwant.Name = "" - iwant.ID = "NEWBIE" + iwant.ID + iwant.ID = "" b, err := json.Marshal(iwant) if err != nil { t.Fatal(err) @@ -320,7 +321,7 @@ func TestWho(t *testing.T) { handler, _, want, _, can := fresh(t) defer can() want.Name = "hello world #1 e ę" - want.ID = "hello world #1 e ę" + want.ID + want.ID = "" want.Connections = nil b, err := json.Marshal(want) if err != nil { @@ -371,7 +372,7 @@ func TestWho(t *testing.T) { defer can() want.Name = "hello world #4" - want.ID = "hello world #4" + want.ID + want.ID = "" want.Connections = nil b, err := json.Marshal(want) if err != nil { @@ -413,7 +414,7 @@ func TestWho(t *testing.T) { defer can() want.Name = "hello world #1 e ę" - want.ID = "hello world #1 e ę" + want.ID + want.ID = "" want.Connections = nil b, err := json.Marshal(want) if err != nil {