mirror_test.go 1.1 KB

12345678910111213141516171819202122232425262728
  1. // Copyright 2017 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func Test_escapeMirrorCredentials(t *testing.T) {
  10. Convey("Escape credentials in mirror address", t, func() {
  11. testCases := []string{
  12. "http://localhost:3000/user/repo.git", "http://localhost:3000/user/repo.git",
  13. "http://user@localhost:3000/user/repo.git", "http://user@localhost:3000/user/repo.git",
  14. "http://user:@localhost:3000/user/repo.git", "http://user:@localhost:3000/user/repo.git",
  15. "http://user:password@localhost:3000/user/repo.git", "http://user:password@localhost:3000/user/repo.git",
  16. "http://user:my:secure;password@localhost:3000/user/repo.git", "http://user:my%3Asecure%3Bpassword@localhost:3000/user/repo.git",
  17. "http://user:my@secure#password@localhost:3000/user/repo.git", "http://user:my%40secure%23password@localhost:3000/user/repo.git",
  18. }
  19. for i := 0; i < len(testCases); i += 2 {
  20. So(escapeMirrorCredentials(testCases[i]), ShouldEqual, testCases[i+1])
  21. }
  22. })
  23. }