mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-27 02:52:14 +01:00
git url without : with empty login
This commit is contained in:
parent
36be80cce8
commit
65b33dbb8d
@ -2,12 +2,13 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ansible-semaphore/semaphore/util"
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/ansible-semaphore/semaphore/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RepositoryType string
|
type RepositoryType string
|
||||||
@ -81,7 +82,11 @@ func (r Repository) GetGitURL() string {
|
|||||||
auth := ""
|
auth := ""
|
||||||
switch r.SSHKey.Type {
|
switch r.SSHKey.Type {
|
||||||
case AccessKeyLoginPassword:
|
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 != "" {
|
if auth != "" {
|
||||||
auth += "@"
|
auth += "@"
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package db
|
package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ansible-semaphore/semaphore/util"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/ansible-semaphore/semaphore/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRepository_GetSchema(t *testing.T) {
|
func TestRepository_GetSchema(t *testing.T) {
|
||||||
@ -38,3 +39,37 @@ func TestRepository_ClearCache(t *testing.T) {
|
|||||||
t.Fatal(err)
|
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