@ -9,253 +9,252 @@ import (
"gitea.com/go-chi/binding"
"gitea.com/go-chi/binding"
)
)
var gitRefNameValidationTestCases = [ ] validationTestCase {
func Test_GitRefNameValidation ( t * testing . T ) {
{
AddBindingRules ( )
description : "Reference name contains only characters" ,
gitRefNameValidationTestCases := [ ] validationTestCase {
data : TestForm {
{
BranchName : "test" ,
description : "Reference name contains only characters" ,
} ,
data : TestForm {
expectedErrors : binding . Errors { } ,
BranchName : "test" ,
} ,
{
description : "Reference name contains single slash" ,
data : TestForm {
BranchName : "feature/test" ,
} ,
expectedErrors : binding . Errors { } ,
} ,
{
description : "Reference name has allowed special characters" ,
data : TestForm {
BranchName : "debian/1%1.6.0-2" ,
} ,
expectedErrors : binding . Errors { } ,
} ,
{
description : "Reference name contains backslash" ,
data : TestForm {
BranchName : "feature\\test" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
expectedErrors : binding . Errors { } ,
} ,
} ,
} ,
{
{
description : "Reference name contains single slash" ,
description : "Reference name starts with dot" ,
data : TestForm {
data : TestForm {
BranchName : "feature/test" ,
BranchName : ".test" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
expectedErrors : binding . Errors { } ,
} ,
} ,
} ,
{
{
description : "Reference name has allowed special characters" ,
description : "Reference name ends with dot" ,
data : TestForm {
data : TestForm {
BranchName : "debian/1%1.6.0-2" ,
BranchName : "test." ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
expectedErrors : binding . Errors { } ,
} ,
} ,
} ,
{
{
description : "Reference name contains backslash" ,
description : "Reference name starts with slash" ,
data : TestForm {
data : TestForm {
BranchName : "feature\\test" ,
BranchName : "/test" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
} ,
binding . Error {
{
FieldNames : [ ] string { "BranchName" } ,
description : "Reference name ends with slash" ,
Classification : ErrGitRefName ,
data : TestForm {
Message : "GitRefName" ,
BranchName : "test/" ,
} ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name starts with dot" ,
description : "Reference name ends with .lock" ,
data : TestForm {
data : TestForm {
BranchName : ".test" ,
BranchName : "test.lock" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
} ,
binding . Error {
{
FieldNames : [ ] string { "BranchName" } ,
description : "Reference name contains multiple consecutive dots" ,
Classification : ErrGitRefName ,
data : TestForm {
Message : "GitRefName" ,
BranchName : "te..st" ,
} ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name ends with dot" ,
description : "Reference name contains multiple consecutive slashes" ,
data : TestForm {
data : TestForm {
BranchName : "test." ,
BranchName : "te//st" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
} ,
binding . Error {
{
FieldNames : [ ] string { "BranchName" } ,
description : "Reference name is single @" ,
Classification : ErrGitRefName ,
data : TestForm {
Message : "GitRefName" ,
BranchName : "@" ,
} ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name starts with slash" ,
description : "Reference name has @{" ,
data : TestForm {
data : TestForm {
BranchName : "/test" ,
BranchName : "branch@{" ,
} ,
} ,
expectedErrors : binding . Errors {
expectedErrors : binding . Errors {
binding . Error {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name ends with slash" ,
description : "Reference name has unallowed special character ~" ,
data : TestForm {
data : TestForm {
BranchName : "test/" ,
BranchName : "~debian/1%1.6.0-2" ,
} ,
} ,
expectedErrors : binding . Errors {
expectedErrors : binding . Errors {
binding . Error {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name ends with .lock" ,
description : "Reference name has unallowed special character *" ,
data : TestForm {
data : TestForm {
BranchName : "test.lock" ,
BranchName : "*debian/1%1.6.0-2" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
{
binding . Error {
description : "Reference name contains multiple consecutive dots" ,
FieldNames : [ ] string { "BranchName" } ,
data : TestForm {
Classification : ErrGitRefName ,
BranchName : "te..st" ,
Message : "GitRefName" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name contains multiple consecutive slashes" ,
description : "Reference name has unallowed special character ?" ,
data : TestForm {
data : TestForm {
BranchName : "te//st" ,
BranchName : "?debian/1%1.6.0-2" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
{
binding . Error {
description : "Reference name is single @" ,
FieldNames : [ ] string { "BranchName" } ,
data : TestForm {
Classification : ErrGitRefName ,
BranchName : "@" ,
Message : "GitRefName" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name has @{" ,
description : "Reference name has unallowed special character ^" ,
data : TestForm {
data : TestForm {
BranchName : "branch@{" ,
BranchName : "^debian/1%1.6.0-2" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
{
binding . Error {
description : "Reference name has unallowed special character ~" ,
FieldNames : [ ] string { "BranchName" } ,
data : TestForm {
Classification : ErrGitRefName ,
BranchName : "~debian/1%1.6.0-2" ,
Message : "GitRefName" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name has unallowed special character *" ,
description : "Reference name has unallowed special character :" ,
data : TestForm {
data : TestForm {
BranchName : "*debian/1%1.6.0-2" ,
BranchName : "debian:jessie" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
{
binding . Error {
description : "Reference name has unallowed special character ?" ,
FieldNames : [ ] string { "BranchName" } ,
data : TestForm {
Classification : ErrGitRefName ,
BranchName : "?debian/1%1.6.0-2" ,
Message : "GitRefName" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name has unallowed special character ^" ,
description : "Reference name has unallowed special character (whitespace)" ,
data : TestForm {
data : TestForm {
BranchName : "^debian/1%1.6.0-2" ,
BranchName : "debian jessie" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
{
binding . Error {
description : "Reference name has unallowed special character :" ,
FieldNames : [ ] string { "BranchName" } ,
data : TestForm {
Classification : ErrGitRefName ,
BranchName : "debian:jessie" ,
Message : "GitRefName" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
} ,
{
{
description : "Reference name has unallowed special character (whitespace)" ,
description : "Reference name has unallowed special character [" ,
data : TestForm {
data : TestForm {
BranchName : "debian jessie" ,
BranchName : "debian[jessie" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
expectedErrors : binding . Errors {
{
binding . Error {
description : "Reference name has unallowed special character [" ,
FieldNames : [ ] string { "BranchName" } ,
data : TestForm {
Classification : ErrGitRefName ,
BranchName : "debian[jessie" ,
Message : "GitRefName" ,
} ,
expectedErrors : binding . Errors {
binding . Error {
FieldNames : [ ] string { "BranchName" } ,
Classification : ErrGitRefName ,
Message : "GitRefName" ,
} ,
} ,
} ,
} ,
} ,
} ,
}
}
func Test_GitRefNameValidation ( t * testing . T ) {
AddBindingRules ( )
for _ , testCase := range gitRefNameValidationTestCases {
for _ , testCase := range gitRefNameValidationTestCases {
t . Run ( testCase . description , func ( t * testing . T ) {
t . Run ( testCase . description , func ( t * testing . T ) {