-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from zong-zhe/supports-tls-flag
feat: add flag --insecure-skip-tls-verify
- Loading branch information
Showing
29 changed files
with
251 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
gohttp "net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"kcl-lang.io/kpm/pkg/client" | ||
) | ||
|
||
func TestModCmdWithSkipTlsVerify(t *testing.T) { | ||
var buf bytes.Buffer | ||
|
||
mux := gohttp.NewServeMux() | ||
mux.HandleFunc("/", func(w gohttp.ResponseWriter, r *gohttp.Request) { | ||
buf.WriteString("Called Success\n") | ||
fmt.Fprintln(w, "Hello, client") | ||
}) | ||
|
||
mux.HandleFunc("/subpath/tags/list", func(w gohttp.ResponseWriter, r *gohttp.Request) { | ||
buf.WriteString("Called Success\n") | ||
fmt.Fprintln(w, "Hello, client") | ||
}) | ||
|
||
mux.HandleFunc("/subpath", func(w gohttp.ResponseWriter, r *gohttp.Request) { | ||
fmt.Fprintln(w, "Hello from subpath") | ||
}) | ||
|
||
ts := httptest.NewTLSServer(mux) | ||
defer ts.Close() | ||
|
||
fmt.Printf("ts.URL: %v\n", ts.URL) | ||
turl, err := url.Parse(ts.URL) | ||
assert.Equal(t, err, nil) | ||
turl.Scheme = "oci" | ||
turl.Path = filepath.Join(turl.Path, "subpath") | ||
fmt.Printf("turl.String(): %v\n", turl.String()) | ||
|
||
kpmcli, err := client.NewKpmClient() | ||
assert.Equal(t, err, nil) | ||
|
||
originalDir, err := os.Getwd() | ||
assert.NoError(t, err) | ||
testRootDir := filepath.Join(originalDir, "test_data") | ||
|
||
runTest := func(testDir string, testFunc func(), beforeTestFuncs []func()) { | ||
if testDir != "" { | ||
err = os.Chdir(filepath.Join(testRootDir, testDir)) | ||
assert.NoError(t, err) | ||
} | ||
|
||
for _, beforeTestFunc := range beforeTestFuncs { | ||
beforeTestFunc() | ||
} | ||
|
||
testFunc() | ||
assert.Equal(t, buf.String(), "Called Success\n") | ||
buf.Reset() | ||
defer func() { | ||
err := os.Chdir(originalDir) | ||
assert.NoError(t, err) | ||
}() | ||
} | ||
|
||
genKclModWithDep := func(depUrl string) { | ||
fmt.Println("Executing extra function for test_mod_graph") | ||
kclModContent := fmt.Sprintf(`[package] | ||
name = "test_mod" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
[dependencies] | ||
dep1 = { oci = "%s"} | ||
`, depUrl) | ||
err := os.WriteFile("kcl.mod", []byte(kclModContent), 0644) | ||
assert.NoError(t, err) | ||
} | ||
|
||
runTest("", func() { | ||
fmt.Println("test_mod_pull") | ||
cmd := NewModPullCmd(kpmcli) | ||
cmd.SetArgs([]string{turl.String(), "--insecure-skip-tls-verify"}) | ||
_ = cmd.Execute() | ||
}, []func(){}) | ||
|
||
runTest("test_mod_push", func() { | ||
fmt.Println("test_mod_push") | ||
cmd := NewModPushCmd(kpmcli) | ||
cmd.SetArgs([]string{turl.String(), "--insecure-skip-tls-verify"}) | ||
_ = cmd.Execute() | ||
}, []func(){}) | ||
|
||
runTest("test_mod_add", func() { | ||
fmt.Println("test_mod_add") | ||
cmd := NewModAddCmd(kpmcli) | ||
cmd.SetArgs([]string{turl.String(), "--insecure-skip-tls-verify"}) | ||
_ = cmd.Execute() | ||
}, []func(){}) | ||
|
||
runTest("test_mod_graph", func() { | ||
fmt.Println("test_mod_graph") | ||
cmd := NewModGraphCmd(kpmcli) | ||
cmd.SetArgs([]string{"--insecure-skip-tls-verify"}) | ||
_ = cmd.Execute() | ||
}, []func(){ | ||
func() { genKclModWithDep(turl.String()) }, | ||
}) | ||
|
||
runTest("test_mod_metadata", func() { | ||
fmt.Println("test_mod_metadata") | ||
cmd := NewModMetadataCmd(kpmcli) | ||
cmd.SetArgs([]string{"--update", "--insecure-skip-tls-verify"}) | ||
_ = cmd.Execute() | ||
}, []func(){ | ||
func() { genKclModWithDep(turl.String()) }, | ||
}) | ||
|
||
runTest("test_mod_update", func() { | ||
fmt.Println("test_mod_update") | ||
cmd := NewModUpdateCmd(kpmcli) | ||
cmd.SetArgs([]string{"--insecure-skip-tls-verify"}) | ||
_ = cmd.Execute() | ||
}, []func(){ | ||
func() { genKclModWithDep(turl.String()) }, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
gohttp "net/http" | ||
"net/http/httptest" | ||
"net/url" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"kcl-lang.io/kpm/pkg/client" | ||
) | ||
|
||
func TestLoginCmdWithSkipTlsVerify(t *testing.T) { | ||
var buf bytes.Buffer | ||
|
||
mux := gohttp.NewServeMux() | ||
mux.HandleFunc("/", func(w gohttp.ResponseWriter, r *gohttp.Request) { | ||
buf.WriteString("Called Success\n") | ||
fmt.Fprintln(w, "Hello, client") | ||
}) | ||
|
||
ts := httptest.NewTLSServer(mux) | ||
defer ts.Close() | ||
|
||
fmt.Printf("ts.URL: %v\n", ts.URL) | ||
turl, err := url.Parse(ts.URL) | ||
assert.Equal(t, err, nil) | ||
turl.Path = filepath.Join(turl.Path, "subpath") | ||
fmt.Printf("turl.String(): %v\n", turl.String()) | ||
|
||
cli, err := client.NewKpmClient() | ||
assert.Equal(t, err, nil) | ||
cmd := NewRegistryLoginCmd(cli) | ||
cmd.SetArgs([]string{turl.String(), "--username=test-user", "--password=test-pass", "--insecure-skip-tls-verify"}) | ||
err = cmd.Execute() | ||
assert.NoError(t, err) | ||
assert.Equal(t, buf.String(), "Called Success\nCalled Success\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "test_mod" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The_first_kcl_program = 'Hello World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "test_mod" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
dep1 = { oci = "oci://127.0.0.1:50630/subpath"} | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The_first_kcl_program = 'Hello World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "test_mod" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
dep1 = { oci = "oci://127.0.0.1:50630/subpath"} | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The_first_kcl_program = 'Hello World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "test_mod" | ||
edition = "v0.10.0" | ||
version = "0.0.1" |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The_first_kcl_program = 'Hello World!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "test_mod" | ||
edition = "v0.10.0" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
dep1 = { oci = "oci://127.0.0.1:50630/subpath"} | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The_first_kcl_program = 'Hello World!' |
Oops, something went wrong.