Skip to content
quarry Artifact [bfeba5072d]
Login

Artifact [bfeba5072d]

Artifact bfeba5072d0e727a9ed560979e12707e137001133b92cdccc4fca8cfce18b883:


package zitcli

import (
	"strings"
	"testing"
)

// The push's command line is fixed, passes the argument guard, and has
// no place for the password.
func TestAFossilPushCarriesNoPasswordInItsArguments(t *testing.T) {
	args := fossilPushArgs("https://fossil.example.org/r", "pusher", []string{"fossil.example.org:443:93.184.216.34"})
	want := []string{"push", "https://fossil.example.org/r", "--user", "pusher", "--once",
		"--resolve", "fossil.example.org:443:93.184.216.34"}
	if strings.Join(args, "\x00") != strings.Join(want, "\x00") {
		t.Fatalf("FAIL: argv is %q, want %q", args, want)
	}
	if err := checkArgs(args); err != nil {
		t.Errorf("FAIL: the guard refuses the push: %v", err)
	}
	for _, a := range args {
		if a == "--password" {
			t.Error("FAIL: --password in argv")
		}
	}
	// An operand that looks like an option is still refused.
	if err := checkArgs(fossilPushArgs("https://fossil.example.org/r", "--evil", nil)); err == nil {
		t.Error("FAIL: a user named like an option passed the guard")
	}
	if err := checkArgs(fossilPushArgs("https://f.example.org/r", "u", []string{"-x.example:443:1.2.3.4"})); err == nil {
		t.Error("FAIL: a pinned host named like an option passed the guard")
	}
	t.Log("ok")
}