예제 #1
0
func (cs *clientSuite) TestReadAuthData(c *check.C) {
	home := os.Getenv("HOME")
	tmpdir := c.MkDir()
	os.Setenv("HOME", tmpdir)
	defer os.Setenv("HOME", home)

	authData := client.User{
		Macaroon:   "macaroon",
		Discharges: []string{"discharge"},
	}
	err := client.TestWriteAuth(authData)
	c.Assert(err, check.IsNil)

	readUser, err := client.TestReadAuth()
	c.Assert(err, check.IsNil)
	c.Check(readUser, check.DeepEquals, &authData)
}
예제 #2
0
func (cs *clientSuite) TestClientSetsAuthorization(c *check.C) {
	home := os.Getenv("HOME")
	tmpdir := c.MkDir()
	os.Setenv("HOME", tmpdir)
	defer os.Setenv("HOME", home)

	mockUserData := client.User{
		Macaroon:   "macaroon",
		Discharges: []string{"discharge"},
	}
	err := client.TestWriteAuth(mockUserData)
	c.Assert(err, check.IsNil)

	var v string
	_ = cs.cli.Do("GET", "/this", nil, nil, &v)
	authorization := cs.req.Header.Get("Authorization")
	c.Check(authorization, check.Equals, `Macaroon root="macaroon", discharge="discharge"`)
}
예제 #3
0
func (cs *clientSuite) TestWriteAuthData(c *check.C) {
	home := os.Getenv("HOME")
	tmpdir := c.MkDir()
	os.Setenv("HOME", tmpdir)
	defer os.Setenv("HOME", home)

	authData := client.User{
		Macaroon:   "macaroon",
		Discharges: []string{"discharge"},
	}
	err := client.TestWriteAuth(authData)
	c.Assert(err, check.IsNil)

	outFile := filepath.Join(tmpdir, ".snap", "auth.json")
	c.Check(osutil.FileExists(outFile), check.Equals, true)
	content, err := ioutil.ReadFile(outFile)
	c.Check(err, check.IsNil)
	c.Check(string(content), check.Equals, `{"macaroon":"macaroon","discharges":["discharge"]}`)
}