mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-26 18:20:59 +00:00
fix: artifacts: format IP:port pair using net.JoinHostPort()
This ensures that brackets are added for IPv6 addresses. Without this, This could result in addresses like "2001:db8::1:3456", which - obviously - would break further down and prevent the server from starting. Signed-off-by: Christoph Heiss <christoph@c8h4.io>
This commit is contained in:
parent
cade5051a8
commit
92b7df3da7
3 changed files with 41 additions and 5 deletions
|
@ -746,3 +746,38 @@ func TestHandler_gcCache(t *testing.T) {
|
|||
}
|
||||
require.NoError(t, db.Close())
|
||||
}
|
||||
|
||||
func TestHandler_ExternalURL(t *testing.T) {
|
||||
t.Run("reports correct URL on IPv4", func(t *testing.T) {
|
||||
dir := filepath.Join(t.TempDir(), "artifactcache")
|
||||
handler, err := StartHandler(dir, "127.0.0.1", 34567, "secret", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, handler.ExternalURL(), "http://127.0.0.1:34567")
|
||||
require.NoError(t, handler.Close())
|
||||
assert.Nil(t, handler.server)
|
||||
assert.Nil(t, handler.listener)
|
||||
})
|
||||
|
||||
t.Run("reports correct URL on IPv6 zero host", func(t *testing.T) {
|
||||
dir := filepath.Join(t.TempDir(), "artifactcache")
|
||||
handler, err := StartHandler(dir, "2001:db8::", 34567, "secret", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, handler.ExternalURL(), "http://[2001:db8::]:34567")
|
||||
require.NoError(t, handler.Close())
|
||||
assert.Nil(t, handler.server)
|
||||
assert.Nil(t, handler.listener)
|
||||
})
|
||||
|
||||
t.Run("reports correct URL on IPv6", func(t *testing.T) {
|
||||
dir := filepath.Join(t.TempDir(), "artifactcache")
|
||||
handler, err := StartHandler(dir, "2001:db8::1:2:3:4", 34567, "secret", nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, handler.ExternalURL(), "http://[2001:db8::1:2:3:4]:34567")
|
||||
require.NoError(t, handler.Close())
|
||||
assert.Nil(t, handler.server)
|
||||
assert.Nil(t, handler.listener)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue