* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
/*
|
|
* Please refer to the LICENSE file in the root directory of the project.
|
|
* https://github.com/kubesphere/kubesphere/blob/master/LICENSE
|
|
*/
|
|
|
|
package git
|
|
|
|
import (
|
|
"testing"
|
|
|
|
runtimefakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
|
|
|
|
"kubesphere.io/kubesphere/pkg/scheme"
|
|
)
|
|
|
|
func TestGitReadVerifyWithBasicAuth(t *testing.T) {
|
|
shouldSuccess := []map[string]string{
|
|
{
|
|
"username": "",
|
|
"password": "",
|
|
"remote": "https://github.com/kubesphere/kubesphere",
|
|
},
|
|
}
|
|
shouldFailed := []map[string]string{
|
|
{
|
|
"username": "",
|
|
"password": "",
|
|
"remote": "https://github.com/kubesphere/kubesphere12222",
|
|
},
|
|
{
|
|
"username": "",
|
|
"password": "",
|
|
"remote": "git@github.com:kubesphere/kubesphere.git",
|
|
},
|
|
{
|
|
"username": "runzexia",
|
|
"password": "",
|
|
"remote": "git@github.com:kubesphere/kubesphere.git",
|
|
},
|
|
{
|
|
"username": "",
|
|
"password": "",
|
|
"remote": "git@fdsfs41342`@@@2414!!!!github.com:kubesphere/kubesphere.git",
|
|
},
|
|
}
|
|
client := runtimefakeclient.NewClientBuilder().
|
|
WithScheme(scheme.Scheme).
|
|
Build()
|
|
|
|
verifier := gitVerifier{cache: client}
|
|
|
|
for _, item := range shouldSuccess {
|
|
err := verifier.gitReadVerifyWithBasicAuth(item["username"], item["password"], item["remote"])
|
|
if err != nil {
|
|
|
|
t.Errorf("should could access repo [%s] with %s:%s, %v", item["username"], item["password"], item["remote"], err)
|
|
}
|
|
}
|
|
|
|
for _, item := range shouldFailed {
|
|
err := verifier.gitReadVerifyWithBasicAuth(item["username"], item["password"], item["remote"])
|
|
if err == nil {
|
|
t.Errorf("should could access repo [%s] with %s:%s ", item["username"], item["password"], item["remote"])
|
|
}
|
|
}
|
|
}
|