Add durable recipe discovery and profession crafting

This commit is contained in:
dingo
2026-09-09 13:28:07 -04:00
parent 940a345613
commit b65f3e8562
42 changed files with 2183 additions and 136 deletions
+53
View File
@@ -114,6 +114,59 @@ func TestHTTPAndSocketSecurity(t *testing.T) {
if bytes.Contains(data, []byte(`"account"`)) {
t.Fatal("account identity leaked")
}
// Public configuration and unauthenticated routes must never expose recipes.
for _, path := range []string{"/api/config", "/api/crafting", "/api/control/catalog"} {
response, e := server.Client().Get(server.URL + path)
if e != nil {
t.Fatal(e)
}
body, _ := io.ReadAll(response.Body)
response.Body.Close()
if bytes.Contains(body, []byte("recipe_spear")) || bytes.Contains(body, []byte(`"recipes"`)) {
t.Fatal("secret recipes exposed", path)
}
if path != "/api/config" && response.StatusCode == 200 {
t.Fatal("unauthenticated crafting/catalog access", path)
}
}
svc.mu.Lock()
c := svc.world.Characters[character.Entity.ID]
c.View.Inventory["herb"] = 10
svc.mu.Unlock()
craft := p.CraftRequest{ID: game.ID(), CharacterID: character.Entity.ID, Profession: "alchemist", Ingredients: map[string]int64{"herb": 2}}
body, _ := json.Marshal(craft)
for _, origin := range []string{"", "https://evil.example"} {
response := request("/api/craft", origin, string(body), cookie)
response.Body.Close()
if response.StatusCode != 403 {
t.Fatal("cross-origin crafting accepted")
}
}
response = request("/api/craft", server.URL, string(body), cookie)
var outcome p.CraftResult
if e := json.NewDecoder(response.Body).Decode(&outcome); e != nil {
t.Fatal(e)
}
response.Body.Close()
if response.StatusCode != 200 || !outcome.Valid || outcome.Recipe == nil {
t.Fatal("ingredient craft did not record valid recipe", outcome)
}
get, _ := http.NewRequest("GET", server.URL+"/api/crafting", nil)
get.AddCookie(cookie)
response, err = server.Client().Do(get)
if err != nil {
t.Fatal(err)
}
var known struct {
Known []p.KnownRecipe `json:"known"`
}
if err = json.NewDecoder(response.Body).Decode(&known); err != nil {
t.Fatal(err)
}
response.Body.Close()
if len(known.Known) != 1 || known.Known[0].Recipe.ID != "recipe_bandage" {
t.Fatal("crafting returned undiscovered recipes")
}
intent := p.Intent{Op: "move", Seq: 1, X: 1}
payload, _ := json.Marshal(intent)
if err = conn.Write(socketCtx, websocket.MessageText, payload); err != nil {