mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
fix: validate Agones assigned endpoints
This commit is contained in:
@@ -142,3 +142,28 @@ func TestDrainRequiresAndUsesAuthenticatedLocalEndpoint(t *testing.T) {
|
||||
t.Fatal("unauthenticated drain was allowed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignedEndpointRejectsMalformedAddressAndPort(t *testing.T) {
|
||||
for _, response := range []string{
|
||||
`{"status":{"address":"203.0.113.9","ports":[{"name":"game","port":65536}]}}`,
|
||||
`{"status":{"address":" ","ports":[{"name":"game","port":31001}]}}`,
|
||||
`{"status":{"address":"203.0.113.9 bad","ports":[{"name":"game","port":31001}]}}`,
|
||||
} {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == "/gameserver" {
|
||||
_, _ = w.Write([]byte(response))
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
s, err := New(Config{Command: []string{"/bin/sh", "-c", "exit 0"}, SDKBaseURL: server.URL, ReadyURL: server.URL + "/probe", ReadyTimeout: time.Second})
|
||||
if err != nil {
|
||||
server.Close()
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.Start(context.Background()); err == nil {
|
||||
t.Errorf("malformed endpoint was accepted: %s", response)
|
||||
}
|
||||
server.Close()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user