Initial upload to Gitea
This commit is contained in:
1 parent
78193254ad
commit
8478998cae
1485 files changed
+461025
-42348
No files matched your search
@@ -0,0 +1,103 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsMinecraftServerMeta(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
meta map[string]any
|
||||
want bool
|
||||
}{
|
||||
{"nil meta", nil, false},
|
||||
{"empty meta", map[string]any{}, false},
|
||||
{"type minecraft", map[string]any{"type": "minecraft"}, true},
|
||||
{"type minecraft uppercase", map[string]any{"type": "Minecraft"}, true},
|
||||
{"template minecraft", map[string]any{"template": "minecraft"}, true},
|
||||
{"type nil string", map[string]any{"type": "<nil>", "template": "<nil>"}, false},
|
||||
{"known non-minecraft type", map[string]any{"type": "nodejs", "template": "nodejs"}, false},
|
||||
{"known non-minecraft template", map[string]any{"type": "runtime", "template": "cs2"}, false},
|
||||
{"unknown type only", map[string]any{"type": ""}, false},
|
||||
{"minecraft via docker signature", map[string]any{
|
||||
"runtime": map[string]any{"image": "eclipse-temurin", "tag": "21-jre", "command": "java -Xms128M -Xmx1024M -jar /data/server.jar nogui"},
|
||||
}, true},
|
||||
{"eclipse-temurin without server.jar", map[string]any{
|
||||
"runtime": map[string]any{"image": "eclipse-temurin", "command": "java -jar app.jar"},
|
||||
}, false},
|
||||
{"other image with server.jar", map[string]any{
|
||||
"runtime": map[string]any{"image": "node", "command": "java -jar server.jar"},
|
||||
}, false},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := isMinecraftServerMeta(tc.meta); got != tc.want {
|
||||
t.Fatalf("isMinecraftServerMeta() = %v, want %v", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The scaffold must never pre-accept the EULA: consent may only come from the
|
||||
// console EULA prompt (user-initiated accept endpoint).
|
||||
func TestWriteMinecraftScaffoldDoesNotAcceptEula(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
writeMinecraftScaffold(dir, "testsrv", "paper", "1.21.8")
|
||||
|
||||
if _, err := os.Stat(filepath.Join(dir, "eula.txt")); !os.IsNotExist(err) {
|
||||
t.Fatal("writeMinecraftScaffold must not create eula.txt (EULA must be accepted by a user)")
|
||||
}
|
||||
if minecraftEulaAccepted(dir) {
|
||||
t.Fatal("freshly scaffolded server must count as EULA-not-accepted")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(dir, "server.properties")); err != nil {
|
||||
t.Fatalf("scaffold should still create server.properties: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMinecraftEulaAccepted(t *testing.T) { dir := t.TempDir()
|
||||
eulaPath := filepath.Join(dir, "eula.txt")
|
||||
|
||||
if minecraftEulaAccepted(dir) {
|
||||
t.Fatal("missing eula.txt must count as not accepted")
|
||||
}
|
||||
|
||||
if err := os.WriteFile(eulaPath, []byte("eula=false\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if minecraftEulaAccepted(dir) {
|
||||
t.Fatal("eula=false must count as not accepted")
|
||||
}
|
||||
|
||||
if err := os.WriteFile(eulaPath, []byte("#Generated by the server\neula=false\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if minecraftEulaAccepted(dir) {
|
||||
t.Fatal("commented eula=false must count as not accepted")
|
||||
}
|
||||
|
||||
if err := os.WriteFile(eulaPath, []byte("#Generated by the server\n"+time_RFC3339_stub()+"\neula=true\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !minecraftEulaAccepted(dir) {
|
||||
t.Fatal("eula=true with comment lines must count as accepted")
|
||||
}
|
||||
|
||||
if err := os.WriteFile(eulaPath, []byte("eula = TRUE\n"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !minecraftEulaAccepted(dir) {
|
||||
t.Fatal("whitespace/case variants of eula=true must count as accepted")
|
||||
}
|
||||
|
||||
if err := os.WriteFile(eulaPath, []byte(""), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if minecraftEulaAccepted(dir) {
|
||||
t.Fatal("empty eula.txt must count as not accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func time_RFC3339_stub() string { return "Sun Sep 11 02:10:00 UTC 2022" }
|
||||
Reference in new issue
Block a user