// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package validation
import (
"testing"
"gitea.com/go-chi/binding"
)
var urlValidationTestCases = []validationTestCase{
{
description: "Empty URL",
data: TestForm{
URL: "",
},
expectedErrors: binding.Errors{},
description: "URL without port",
URL: "http://test.lan/",
description: "URL with port",
URL: "http://test.lan:3000/",
description: "URL with IPv6 address without port",
URL: "http://[::1]/",
description: "URL with IPv6 address with port",
URL: "http://[::1]:3000/",
description: "Invalid URL",
URL: "http//test.lan/",
expectedErrors: binding.Errors{
binding.Error{
FieldNames: []string{"URL"},
Classification: binding.ERR_URL,
Message: "Url",
description: "Invalid schema",
URL: "ftp://test.lan/",
description: "Invalid port",
URL: "http://test.lan:3x4/",
description: "Invalid port with IPv6 address",
URL: "http://[::1]:3x4/",
}
func Test_ValidURLValidation(t *testing.T) {
AddBindingRules()
for _, testCase := range urlValidationTestCases {
t.Run(testCase.description, func(t *testing.T) {
performValidationTest(t, testCase)
})