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]>
111 lines
2.2 KiB
Go
111 lines
2.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package validation
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/git/modules/binding"
|
|
)
|
|
|
|
func Test_ValidURLValidation(t *testing.T) {
|
|
AddBindingRules()
|
|
|
|
urlValidationTestCases := []validationTestCase{
|
|
{
|
|
description: "Empty URL",
|
|
data: TestForm{
|
|
URL: "",
|
|
},
|
|
expectedErrors: binding.Errors{},
|
|
},
|
|
{
|
|
description: "URL without port",
|
|
data: TestForm{
|
|
URL: "http://test.lan/",
|
|
},
|
|
expectedErrors: binding.Errors{},
|
|
},
|
|
{
|
|
description: "URL with port",
|
|
data: TestForm{
|
|
URL: "http://test.lan:3000/",
|
|
},
|
|
expectedErrors: binding.Errors{},
|
|
},
|
|
{
|
|
description: "URL with IPv6 address without port",
|
|
data: TestForm{
|
|
URL: "http://[::1]/",
|
|
},
|
|
expectedErrors: binding.Errors{},
|
|
},
|
|
{
|
|
description: "URL with IPv6 address with port",
|
|
data: TestForm{
|
|
URL: "http://[::1]:3000/",
|
|
},
|
|
expectedErrors: binding.Errors{},
|
|
},
|
|
{
|
|
description: "Invalid URL",
|
|
data: TestForm{
|
|
URL: "http//test.lan/",
|
|
},
|
|
expectedErrors: binding.Errors{
|
|
binding.Error{
|
|
FieldNames: []string{"URL"},
|
|
Classification: binding.ERR_URL,
|
|
Message: "Url",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "Invalid schema",
|
|
data: TestForm{
|
|
URL: "ftp://test.lan/",
|
|
},
|
|
expectedErrors: binding.Errors{
|
|
binding.Error{
|
|
FieldNames: []string{"URL"},
|
|
Classification: binding.ERR_URL,
|
|
Message: "Url",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "Invalid port",
|
|
data: TestForm{
|
|
URL: "http://test.lan:3x4/",
|
|
},
|
|
expectedErrors: binding.Errors{
|
|
binding.Error{
|
|
FieldNames: []string{"URL"},
|
|
Classification: binding.ERR_URL,
|
|
Message: "Url",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
description: "Invalid port with IPv6 address",
|
|
data: TestForm{
|
|
URL: "http://[::1]:3x4/",
|
|
},
|
|
expectedErrors: binding.Errors{
|
|
binding.Error{
|
|
FieldNames: []string{"URL"},
|
|
Classification: binding.ERR_URL,
|
|
Message: "Url",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, testCase := range urlValidationTestCases {
|
|
t.Run(testCase.description, func(t *testing.T) {
|
|
performValidationTest(t, testCase)
|
|
})
|
|
}
|
|
}
|