This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 8de6e2c0d fix(rmqctl): reject malformed context server URLs (#7293)
8de6e2c0d is described below

commit 8de6e2c0d688ff5e4360f46f62869e93665f7a01
Author: Yexi Xiang <[email protected]>
AuthorDate: Fri Nov 27 12:09:16 2026 +0800

    fix(rmqctl): reject malformed context server URLs (#7293)
---
 rmqctl/cmd/config.go      |  2 +-
 rmqctl/cmd/config_test.go | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/rmqctl/cmd/config.go b/rmqctl/cmd/config.go
index a0468a11c..3f784b68d 100644
--- a/rmqctl/cmd/config.go
+++ b/rmqctl/cmd/config.go
@@ -50,7 +50,7 @@ func newConfigSetContextCommand(runtime commandRuntime) 
*cobra.Command {
                RunE: func(cmd *cobra.Command, args []string) error {
                        if cmd.Flags().Changed("server") {
                                parsed, err := url.Parse(server)
-                               if err != nil {
+                               if err != nil || parsed.Scheme == "" || 
parsed.Hostname() == "" {
                                        return invalidArgument("--server must 
be a valid Studio Server URL")
                                }
                                if parsed.User != nil {
diff --git a/rmqctl/cmd/config_test.go b/rmqctl/cmd/config_test.go
index 47c1b5092..fb699ce81 100644
--- a/rmqctl/cmd/config_test.go
+++ b/rmqctl/cmd/config_test.go
@@ -146,6 +146,29 @@ func 
TestConfigSetContextRejectsServerCredentialsBeforeSaving(t *testing.T) {
        }
 }
 
+func TestConfigSetContextRejectsRelativeServerURLBeforeSaving(t *testing.T) {
+       stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
+       app := NewApp(stdout, stderr)
+       app.Store.Getenv = emptyEnv
+       configPath := newTestConfigPath(t)
+
+       exitCode := app.Execute([]string{
+               "--config", configPath, "config", "set-context", "prod",
+               "--server", "studio.example.com",
+               "--access-key-env", "RMQ_AK", "--secret-key-env", "RMQ_SK",
+       })
+
+       if exitCode == 0 {
+               t.Fatal("set-context accepted a server value without a URL 
scheme")
+       }
+       if stdout.Len() != 0 || !strings.Contains(stderr.String(), 
"INVALID_ARGUMENT") {
+               t.Fatalf("stdout=%q stderr=%q, want an argument error without 
success output", stdout, stderr)
+       }
+       if _, err := os.Stat(configPath); !os.IsNotExist(err) {
+               t.Fatalf("rejected creation wrote config: %v", err)
+       }
+}
+
 func TestConfigSetContextCanRemoveStoredServerCredentials(t *testing.T) {
        stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
        app := NewApp(stdout, stderr)

Reply via email to