docs & feat: add license & attribution notice (Apache-2.0 / GPL-3.0) and core system enhancements
This commit is contained in:
1 parent
507836d367
commit
ce6aabfc55
47 files changed
+5674
-724
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package sdkserver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUnsupportedAndReadOnlyCommandsDoNotRewriteSave(t *testing.T) {
|
||||
chdirRepoRootSDK(t)
|
||||
beforeData, err := os.ReadFile("freesr-data.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
beforePersistent, err := os.ReadFile("persistent")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
command string
|
||||
success bool
|
||||
}{
|
||||
{"/give 200001 100", false}, {"/heal", false}, {"/not_a_command", false}, {"/help", true},
|
||||
} {
|
||||
body, _ := json.Marshal(map[string]string{"command": tc.command})
|
||||
response := httptest.NewRecorder()
|
||||
apiCommand(response, httptest.NewRequest(http.MethodPost, "/api/command", strings.NewReader(string(body))))
|
||||
var result struct {
|
||||
Success bool `json:"success"`
|
||||
Output string `json:"output"`
|
||||
}
|
||||
if err := json.Unmarshal(response.Body.Bytes(), &result); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if result.Success != tc.success || result.Output == "" {
|
||||
t.Fatalf("%s: %+v", tc.command, result)
|
||||
}
|
||||
}
|
||||
afterData, _ := os.ReadFile("freesr-data.json")
|
||||
afterPersistent, _ := os.ReadFile("persistent")
|
||||
if !bytes.Equal(beforeData, afterData) || !bytes.Equal(beforePersistent, afterPersistent) {
|
||||
t.Fatal("read-only or unsupported command rewrote user data")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user