mirror of https://github.com/gogits/gogs.git
Browse Source
Special characters such as '@', ';', '#' and ':' could occur in password portion of credentials, which breaks the interpretation and saves 'config' file in with extra characters that are not recognized by Git (due to INI library).pull/4248/merge
Unknwon
8 years ago
4 changed files with 59 additions and 3 deletions
@ -0,0 +1,28 @@ |
|||||||
|
// Copyright 2017 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package models |
||||||
|
|
||||||
|
import ( |
||||||
|
"testing" |
||||||
|
|
||||||
|
. "github.com/smartystreets/goconvey/convey" |
||||||
|
) |
||||||
|
|
||||||
|
func Test_escapeMirrorCredentials(t *testing.T) { |
||||||
|
Convey("Escape credentials in mirror address", t, func() { |
||||||
|
testCases := []string{ |
||||||
|
"http://localhost:3000/user/repo.git", "http://localhost:3000/user/repo.git", |
||||||
|
"http://user@localhost:3000/user/repo.git", "http://user@localhost:3000/user/repo.git", |
||||||
|
"http://user:@localhost:3000/user/repo.git", "http://user:@localhost:3000/user/repo.git", |
||||||
|
"http://user:password@localhost:3000/user/repo.git", "http://user:password@localhost:3000/user/repo.git", |
||||||
|
"http://user:my:secure;password@localhost:3000/user/repo.git", "http://user:my%3Asecure%3Bpassword@localhost:3000/user/repo.git", |
||||||
|
"http://user:my@secure#password@localhost:3000/user/repo.git", "http://user:my%40secure%23password@localhost:3000/user/repo.git", |
||||||
|
} |
||||||
|
|
||||||
|
for i := 0; i < len(testCases); i += 2 { |
||||||
|
So(escapeMirrorCredentials(testCases[i]), ShouldEqual, testCases[i+1]) |
||||||
|
} |
||||||
|
}) |
||||||
|
} |
Loading…
Reference in new issue