ci: expand shared package validation and test coverage
- Add lint, formatting, vet, and publish workflow checks - Run Go database tests with PostgreSQL and add Java tests - Make consumer sync opt-in; update docs and Go dependency
This commit is contained in:
1 parent
937f51b4fb
commit
0ff94f9b10
107 files changed
+10124
-410
No files matched your search
@@ -11,8 +11,11 @@
|
||||
package coreconfig
|
||||
|
||||
import (
|
||||
"crypto/subtle"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
@@ -179,7 +182,7 @@ func normalizeInfo(info Info) Info {
|
||||
// own internal-auth-gated routes use).
|
||||
func Handler(secret string, store *Store) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if secret == "" || r.Header.Get("X-Internal-Auth") != secret {
|
||||
if secret == "" || subtle.ConstantTimeCompare([]byte(r.Header.Get("X-Internal-Auth")), []byte(secret)) != 1 {
|
||||
writeError(w, http.StatusUnauthorized, "internal service authentication required")
|
||||
return
|
||||
}
|
||||
@@ -188,6 +191,10 @@ func Handler(secret string, store *Store) http.HandlerFunc {
|
||||
writeError(w, http.StatusBadRequest, "invalid JSON body")
|
||||
return
|
||||
}
|
||||
if err := validateServiceURLs(input); err != nil {
|
||||
writeError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
store.Set(input)
|
||||
// Do not echo service credentials to the caller. The push is authenticated, but
|
||||
// these credentials are needed only by the recipient.
|
||||
@@ -198,6 +205,23 @@ func Handler(secret string, store *Store) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// validateServiceURLs refuses a pushed URL that is not an http or https URL with a host, so a push
|
||||
// cannot point this service's clients at another scheme or at an empty host.
|
||||
func validateServiceURLs(info Info) error {
|
||||
urls := append([]string{info.AuthGuardURL, info.ComfyUIURL, info.ProjectConfiguratorURL, info.ContentScannerURL, info.CarrierNodeURL}, info.CarrierNodeURLs...)
|
||||
for _, raw := range urls {
|
||||
value := strings.TrimSpace(raw)
|
||||
if value == "" {
|
||||
continue
|
||||
}
|
||||
parsed, err := url.Parse(value)
|
||||
if err != nil || (parsed.Scheme != "http" && parsed.Scheme != "https") || parsed.Host == "" {
|
||||
return errors.New("core service URL must be an http or https URL with a host")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeJSON(w http.ResponseWriter, status int, value any) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(status)
|
||||
|
||||
Reference in new issue
Block a user