func (s *SSHCommandSuite) TestCopy(c *gc.C) { var opts ssh.Options opts.EnablePTY() opts.AllowPasswordAuthentication() opts.SetIdentities("x", "y") opts.SetPort(2022) err := s.client.Copy([]string{"/tmp/blah", "[email protected]:baz"}, &opts) c.Assert(err, gc.IsNil) out, err := ioutil.ReadFile(s.fakescp + ".args") c.Assert(err, gc.IsNil) // EnablePTY has no effect for Copy c.Assert(string(out), gc.Equals, s.fakescp+" -o StrictHostKeyChecking no -i x -i y -P 2022 /tmp/blah [email protected]:baz\n") // Try passing extra args err = s.client.Copy([]string{"/tmp/blah", "[email protected]:baz", "-r", "-v"}, &opts) c.Assert(err, gc.IsNil) out, err = ioutil.ReadFile(s.fakescp + ".args") c.Assert(err, gc.IsNil) c.Assert(string(out), gc.Equals, s.fakescp+" -o StrictHostKeyChecking no -i x -i y -P 2022 /tmp/blah [email protected]:baz -r -v\n") // Try interspersing extra args err = s.client.Copy([]string{"-r", "/tmp/blah", "-v", "[email protected]:baz"}, &opts) c.Assert(err, gc.IsNil) out, err = ioutil.ReadFile(s.fakescp + ".args") c.Assert(err, gc.IsNil) c.Assert(string(out), gc.Equals, s.fakescp+" -o StrictHostKeyChecking no -i x -i y -P 2022 -r /tmp/blah -v [email protected]:baz\n") }
func (s *SSHCommandSuite) TestCommandIdentities(c *gc.C) { var opts ssh.Options opts.SetIdentities("x", "y") s.assertCommandArgs(c, s.commandOptions([]string{"echo", "123"}, &opts), s.fakessh+" -o StrictHostKeyChecking no -o PasswordAuthentication no -i x -i y localhost echo 123", ) }
func (s *SSHCommandSuite) TestCommandClientKeys(c *gc.C) { defer overrideGenerateKey(c).Restore() clientKeysDir := c.MkDir() defer ssh.ClearClientKeys() err := ssh.LoadClientKeys(clientKeysDir) c.Assert(err, gc.IsNil) ck := filepath.Join(clientKeysDir, "juju_id_rsa") var opts ssh.Options opts.SetIdentities("x", "y") s.assertCommandArgs(c, s.commandOptions([]string{"echo", "123"}, &opts), s.fakessh+" -o StrictHostKeyChecking no -o PasswordAuthentication no -i x -i y -i "+ck+" localhost echo 123", ) }
func (s *SSHCommandSuite) TestCommandDefaultIdentities(c *gc.C) { var opts ssh.Options tempdir := c.MkDir() def1 := filepath.Join(tempdir, "def1") def2 := filepath.Join(tempdir, "def2") s.PatchValue(ssh.DefaultIdentities, []string{def1, def2}) // If no identities are specified, then the defaults aren't added. s.assertCommandArgs(c, s.commandOptions([]string{"echo", "123"}, &opts), s.fakessh+" -o StrictHostKeyChecking no -o PasswordAuthentication no localhost echo 123", ) // If identities are specified, then the defaults are must added. // Only the defaults that exist on disk will be added. err := ioutil.WriteFile(def2, nil, 0644) c.Assert(err, gc.IsNil) opts.SetIdentities("x", "y") s.assertCommandArgs(c, s.commandOptions([]string{"echo", "123"}, &opts), s.fakessh+" -o StrictHostKeyChecking no -o PasswordAuthentication no -i x -i y -i "+def2+" localhost echo 123", ) }