Exemple #1
0
// AuthPasswd tests whether `deis auth:passwd` updates a user's password.
func AuthPasswd(t *testing.T, params *DeisTestConfig, password string) {
	fmt.Println("deis auth:passwd")
	child, err := gexpect.Spawn(Deis + " auth:passwd")
	if err != nil {
		t.Fatalf("command not started\n%v", err)
	}
	fmt.Println("current password:"******"current password: "******"expect password failed\n%v", err)
	}
	child.SendLine(params.Password)
	fmt.Println("new password:"******"new password: "******"expect password failed\n%v", err)
	}
	child.SendLine(password)
	fmt.Println("new password (confirm):")
	err = child.Expect("new password (confirm): ")
	if err != nil {
		t.Fatalf("expect password failed\n%v", err)
	}
	child.SendLine(password)
	err = child.Expect("Password change succeeded")
	if err != nil {
		t.Fatalf("command executiuon failed\n%v", err)
	}
	child.Close()
}
Exemple #2
0
func RemoteExecute(user string, password string, remoteIp string, cmd string) (string, error) {
	str := fmt.Sprintf("ssh %s@%s", user, remoteIp)
	ssh, err := gexpect.Spawn(str)
	if err != nil {
		fmt.Println("Spawn", str)
		fmt.Println("Could not connect to ", remoteIp, err)
		return "", err
	}
	ssh.Expect("sword")
	ssh.SendLine(password)
	err = ssh.ExpectTimeout("#", 10*time.Second)
	if err != nil {
		fmt.Println("Spawn", str)
		fmt.Println("password:"******"Login failed to", remoteIp, "(", err, ")", "Please check password")
		return "", err
	}
	ssh.Capture()
	ssh.SendLine(cmd)
	ssh.Expect("#")
	bytes := ssh.Collect()
	ssh.SendLine("exit")
	ssh.Expect("#")
	outStr := fmt.Sprintf("Executed on %s: ", remoteIp) + string(bytes[:])
	return outStr, err
}
Exemple #3
0
// AuthCancel tests whether `deis auth:cancel` destroys a user's account.
func AuthCancel(t *testing.T, params *DeisTestConfig) {
	fmt.Println("deis auth:cancel")
	child, err := gexpect.Spawn(Deis + " auth:cancel")
	if err != nil {
		t.Fatalf("command not started\n%v", err)
	}
	fmt.Println("username:"******"username:"******"expect username failed\n%v", err)
	}
	child.SendLine(params.UserName)
	fmt.Print("password:"******"password:"******"expect password failed\n%v", err)
	}
	child.SendLine(params.Password)
	err = child.ExpectRegex("(y/n)")
	if err != nil {
		t.Fatalf("expect cancel \n%v", err)
	}
	child.SendLine("y")
	err = child.Expect("Account cancelled")
	if err != nil {
		t.Fatalf("command executiuon failed\n%v", err)
	}
	child.Close()
}
Exemple #4
0
func main() {
	log.Printf("Testing Ping interact... \n")

	child, err := gexpect.Spawn("ping -c8 127.0.0.1")
	if err != nil {
		panic(err)
	}
	child.Interact()
	log.Printf("Success\n")
}
Exemple #5
0
func PlayCmdLine(id string) (success bool) {
	success = false
	log.Printf("Running stream via youtube-dl and gexpect\n")
	log.Printf("Command: \"" + "/bin/sh -c 'youtube-dl -o - " + id + " | ffmpeg -i - -f mp3 pipe:1 | mpg123 - '" + "\"")
	child, err := gexpect.Spawn("/bin/sh -c 'youtube-dl -o - " + id + " | ffmpeg -i - -f mp3 pipe:1 | mpg123 - '")
	if err != nil {
		return false
	}
	child.Interact()
	return
}
Exemple #6
0
func TestUcatListen(t *testing.T) {
	child, err := gexpect.Spawn("libutp/ucat-static -l -p 8000")
	if err != nil {
		t.Fatal(err)
	}

	time.Sleep(500 * time.Millisecond)
	addr, err := utp.ResolveAddr("utp", "127.0.0.1:8000")
	if err != nil {
		t.Fatal(err)
	}
	c, err := utp.DialUTPTimeout("utp", nil, addr, 1000*time.Millisecond)
	if err != nil {
		t.Fatal(err)
	}

	var payload [128]byte
	_, err = rand.Read(payload[:])
	if err != nil {
		t.Fatal(err)
	}

	msg := hex.EncodeToString(payload[:])
	_, err = c.Write([]byte(msg + "\n"))
	if err != nil {
		t.Fatal(err)
	}

	err = child.ExpectTimeout(msg, 1000*time.Millisecond)
	if err != nil {
		t.Fatal(err)
	}

	child.SendLine(msg + "\n")

	err = c.SetDeadline(time.Now().Add(1000 * time.Millisecond))
	if err != nil {
		t.Fatal(err)
	}

	var buf [1024]byte
	l, err := c.Read(buf[:])
	if err != nil {
		t.Fatal(err)
	}

	if string(buf[:l]) != msg+"\n" {
		t.Errorf("expected payload of %s; got %s", msg, string(buf[:l]))
	}

	c.Close()
	child.Wait()
}
Exemple #7
0
// newExpectCmd creates a new Expect command out of the given argument
// strings.  We can then interact with the command as per normal expect,
// but one difference is that any failures become fatal on the supplied
// testing.T object.
func (u user) newExpectCmd(t *testing.T, args ...string) *expectCmd {
	cmd := []string{
		keybaseBinaryPath(),
		"--standalone",
		"-H",
		u.makeHome(t),
	}
	cmd = append(cmd, args...)
	es, err := gexpect.Spawn(strings.Join(cmd, " "))
	if err != nil {
		t.Fatalf("Error spwaning %v: %v", cmd, err)
	}
	return &expectCmd{es}
}
Exemple #8
0
func main() {
	waitChan := make(chan string)

	fmt.Printf("Starting screen.. \n")

	child, err := gexpect.Spawn("screen")
	if err != nil {
		panic(err)
	}

	sender, reciever := child.AsyncInteractChannels()
	go func() {
		waitString := ""
		count := 0
		for {
			select {
			case waitString = <-waitChan:
				count++
			case msg, open := <-reciever:
				if !open {
					return
				}
				fmt.Printf("Recieved: %s\n", msg)

				if strings.Contains(msg, waitString) {
					if count >= 1 {
						waitChan <- msg
						count -= 1
					}
				}
			}
		}
	}()
	wait := func(str string) {
		waitChan <- str
		<-waitChan
	}
	fmt.Printf("Waiting until started.. \n")
	wait(" ")
	fmt.Printf("Sending Enter.. \n")
	sender <- "\n"
	wait("$")
	fmt.Printf("Sending echo.. \n")
	sender <- "echo Hello World\n"
	wait("Hello World")
	fmt.Printf("Received echo. \n")
}
Exemple #9
0
func main() {
	fmt.Printf("Starting python.. \n")
	child, err := gexpect.Spawn("python")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Expecting >>>.. \n")
	child.Expect(">>>")
	fmt.Printf("print 'Hello World'..\n")
	child.SendLine("print 'Hello World'")
	child.Expect(">>>")

	fmt.Printf("Interacting.. \n")
	child.Interact()
	fmt.Printf("Done \n")
	child.Close()
}
Exemple #10
0
func main() {
	log.Printf("Testing Ftp... ")

	child, err := gexpect.Spawn("ftp ftp.openbsd.org")
	if err != nil {
		panic(err)
	}
	child.Expect("Name")
	child.SendLine("anonymous")
	child.Expect("Password")
	child.SendLine("*****@*****.**")
	child.Expect("ftp> ")
	child.SendLine("cd /pub/OpenBSD/3.7/packages/i386")
	child.Expect("ftp> ")
	child.SendLine("bin")
	child.Expect("ftp> ")
	child.SendLine("prompt")
	child.Expect("ftp> ")
	child.SendLine("pwd")
	child.Expect("ftp> ")
	log.Printf("Success\n")
}