mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package private
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/git/modules/setting"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestInternalAPIConnectionIsLocal(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
protocol setting.Scheme
|
|
localURL string
|
|
want bool
|
|
}{
|
|
// HTTPUnix always dials the unix socket (a local target), whatever LOCAL_ROOT_URL says
|
|
{"unix socket", setting.HTTPUnix, "https://forge.example.com/", true},
|
|
{"localhost", setting.HTTP, "http://localhost:3000/", true},
|
|
{"loopback ipv4", setting.HTTPS, "https://127.0.0.1:3000/", true},
|
|
{"loopback ipv6", setting.HTTPS, "https://[::1]:3000/", true},
|
|
// a non-loopback LOCAL_ROOT_URL is a real network hop and must be verified
|
|
{"remote host", setting.HTTPS, "https://forge.internal:443/", false},
|
|
{"remote ip", setting.HTTPS, "https://10.0.0.5:3000/", false},
|
|
// an unparseable LOCAL_ROOT_URL is a hard misconfiguration; fail closed to verification
|
|
{"invalid url", setting.HTTPS, "://bad", false},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
assert.Equal(t, c.want, internalAPIConnectionIsLocal(c.protocol, c.localURL))
|
|
})
|
|
}
|
|
}
|