mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 12:30:41 +01:00
git url without : with empty login
This commit is contained in:
parent
36be80cce8
commit
65b33dbb8d
@ -2,12 +2,13 @@ package db
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
)
|
||||
|
||||
type RepositoryType string
|
||||
@ -81,7 +82,11 @@ func (r Repository) GetGitURL() string {
|
||||
auth := ""
|
||||
switch r.SSHKey.Type {
|
||||
case AccessKeyLoginPassword:
|
||||
auth = r.SSHKey.LoginPassword.Login + ":" + r.SSHKey.LoginPassword.Password
|
||||
if r.SSHKey.LoginPassword.Login == "" {
|
||||
auth = r.SSHKey.LoginPassword.Password
|
||||
} else {
|
||||
auth = r.SSHKey.LoginPassword.Login + ":" + r.SSHKey.LoginPassword.Password
|
||||
}
|
||||
}
|
||||
if auth != "" {
|
||||
auth += "@"
|
||||
|
@ -1,11 +1,12 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
)
|
||||
|
||||
func TestRepository_GetSchema(t *testing.T) {
|
||||
@ -38,3 +39,37 @@ func TestRepository_ClearCache(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepository_GetGitURL(t *testing.T) {
|
||||
for _, v := range []struct {
|
||||
Repository Repository
|
||||
ExpectedGitUrl string
|
||||
}{
|
||||
{
|
||||
Repository: Repository{GitURL: "https://github.com/user/project.git", SSHKey: AccessKey{
|
||||
Type: AccessKeyLoginPassword,
|
||||
LoginPassword: LoginPassword{
|
||||
Login: "login",
|
||||
Password: "password",
|
||||
},
|
||||
},
|
||||
},
|
||||
ExpectedGitUrl: "https://login:password@github.com/user/project.git",
|
||||
},
|
||||
{
|
||||
Repository: Repository{GitURL: "https://github.com/user/project.git", SSHKey: AccessKey{
|
||||
Type: AccessKeyLoginPassword,
|
||||
LoginPassword: LoginPassword{
|
||||
Password: "password",
|
||||
},
|
||||
},
|
||||
},
|
||||
ExpectedGitUrl: "https://password@github.com/user/project.git",
|
||||
},
|
||||
} {
|
||||
gitUrl := v.Repository.GetGitURL()
|
||||
if gitUrl != v.ExpectedGitUrl {
|
||||
t.Error("wrong gitUrl", "expected: ", v.ExpectedGitUrl, " got: ", gitUrl)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user