Beispiel #1
0
func (s *NetrcSuite) TestSetPassword(c *C) {
	f, err := netrc.Parse("./examples/login.netrc")
	c.Assert(err, IsNil)
	heroku := f.Machine("api.heroku.com")
	heroku.Set("password", "foobar")
	c.Check(f.Render(), Equals, "# this is my login netrc\nmachine api.heroku.com\n  login [email protected] # this is my username\n  password foobar\n")
}
Beispiel #2
0
func (s *NetrcSuite) TestPassword(c *C) {
	f, err := netrc.Parse("./examples/password.netrc")
	c.Assert(err, IsNil)
	c.Check(f.Machine("m").Get("password"), Equals, "p")
	body, _ := ioutil.ReadFile(f.Path)
	c.Check(f.Render(), Equals, string(body))
}
Beispiel #3
0
func (s *NetrcSuite) TestAdd(c *C) {
	f, err := netrc.Parse("./examples/login.netrc")
	c.Assert(err, IsNil)
	f.AddMachine("m", "l", "p")
	c.Check(f.Render(), Equals, "# this is my login netrc\nmachine api.heroku.com\n  login [email protected] # this is my username\n  password foo\n"+
		"machine m\n  login l\n  password p\n")
}
Beispiel #4
0
func (s *NetrcSuite) TestDefaultOnly(c *C) {
	f, err := netrc.Parse("./examples/default_only.netrc")
	c.Assert(err, IsNil)
	c.Check(f.Machine("default").Get("login"), Equals, "ld")
	c.Check(f.Machine("default").Get("password"), Equals, "pd")
	body, _ := ioutil.ReadFile(f.Path)
	c.Check(f.Render(), Equals, string(body))
}
Beispiel #5
0
func (s *NetrcSuite) TestLogin(c *C) {
	f, err := netrc.Parse("./examples/login.netrc")
	c.Assert(err, IsNil)
	heroku := f.Machine("api.heroku.com")
	c.Check(heroku.Get("login"), Equals, "*****@*****.**")
	c.Check(heroku.Get("password"), Equals, "foo")
	body, _ := ioutil.ReadFile(f.Path)
	c.Check(f.Render(), Equals, string(body))
}
Beispiel #6
0
func (s *NetrcSuite) TestGood(c *C) {
	f, err := netrc.Parse("./examples/good.netrc")
	c.Assert(err, IsNil)
	c.Check(f.Machine("mail.google.com").Get("login"), Equals, "*****@*****.**")
	c.Check(f.Machine("mail.google.com").Get("account"), Equals, "justagmail")
	c.Check(f.Machine("mail.google.com").Get("password"), Equals, "somethingSecret")
	body, _ := ioutil.ReadFile(f.Path)
	c.Check(f.Render(), Equals, string(body))
}
Beispiel #7
0
func (s *NetrcSuite) TestSampleMultiWithDefault(c *C) {
	f, err := netrc.Parse("./examples/sample_multi_with_default.netrc")
	c.Assert(err, IsNil)
	c.Check(f.Machine("m").Get("login"), Equals, "lm")
	c.Check(f.Machine("m").Get("password"), Equals, "pm")
	c.Check(f.Machine("n").Get("login"), Equals, "ln")
	c.Check(f.Machine("n").Get("password"), Equals, "pn")
	body, _ := ioutil.ReadFile(f.Path)
	c.Check(f.Render(), Equals, string(body))
}
Beispiel #8
0
func (s *NetrcSuite) TestBadDefaultOrder(c *C) {
	f, err := netrc.Parse("./examples/bad_default_order.netrc")
	c.Assert(err, IsNil)
	c.Check(f.Machine("mail.google.com").Get("login"), Equals, "*****@*****.**")
	c.Check(f.Machine("mail.google.com").Get("password"), Equals, "somethingSecret")
	c.Check(f.Machine("ray").Get("login"), Equals, "demo")
	c.Check(f.Machine("ray").Get("password"), Equals, "mypassword")
	body, _ := ioutil.ReadFile(f.Path)
	c.Check(f.Render(), Equals, string(body))
}
Beispiel #9
0
func (s *NetrcSuite) TestSave(c *C) {
	f, err := netrc.Parse("./examples/login.netrc")
	c.Assert(err, IsNil)
	f.Path = "./examples/login-new.netrc"
	err = f.Save()
	c.Assert(err, IsNil)
	a, _ := ioutil.ReadFile("./examples/login-new.netrc")
	b, _ := ioutil.ReadFile("./examples/login.netrc")
	c.Check(string(a), Equals, string(b))
	os.Remove("./examples/login-new.netrc")
}
Beispiel #10
0
func getNetrc() *netrc.Netrc {
	n, err := netrc.Parse(netrcPath())
	if err != nil {
		if _, ok := err.(*os.PathError); ok {
			// File not found
			return &netrc.Netrc{Path: netrcPath()}
		}
		Errln("Error parsing netrc at " + netrcPath())
		Errln(err.Error())
		os.Exit(1)
	}
	return n
}
Beispiel #11
0
func (s *NetrcSuite) TestRemove(c *C) {
	f, err := netrc.Parse("./examples/sample_multi.netrc")
	c.Assert(err, IsNil)
	f.RemoveMachine("m")
	c.Check(f.Render(), Equals, "# this is my netrc with multiple machines\nmachine n\n  login ln # this is my n-username\n  password pn\n")
}
Beispiel #12
0
func (s *NetrcSuite) TestAddExisting(c *C) {
	f, err := netrc.Parse("./examples/login.netrc")
	c.Assert(err, IsNil)
	f.AddMachine("api.heroku.com", "l", "p")
	c.Check(f.Render(), Equals, "# this is my login netrc\nmachine api.heroku.com\n  login l\n  password p\n")
}
Beispiel #13
0
func (s *NetrcSuite) TestRemoveFromComplicated(c *C) {
	f, err := netrc.Parse("./examples/complicated.netrc")
	c.Assert(err, IsNil)
	f.RemoveMachine("git.heroku.com")
	c.Assert(f.Machine("git.heroku.com"), IsNil)
}