diff options
| -rw-r--r-- | daemon/api.go | 3 | ||||
| -rw-r--r-- | daemon/api_test.go | 18 |
2 files changed, 21 insertions, 0 deletions
diff --git a/daemon/api.go b/daemon/api.go index 5cbe8f2ed9..13298d60dd 100644 --- a/daemon/api.go +++ b/daemon/api.go @@ -681,6 +681,9 @@ func trySnap(c *Command, r *http.Request, user *auth.UserState, trydir string, f st.Lock() defer st.Unlock() + if !filepath.IsAbs(trydir) { + return BadRequest("cannot try %q: need an absolute path", trydir) + } if !osutil.IsDirectory(trydir) { return BadRequest("cannot try %q: not a snap directory", trydir) } diff --git a/daemon/api_test.go b/daemon/api_test.go index 395a11929e..de69e81dc9 100644 --- a/daemon/api_test.go +++ b/daemon/api_test.go @@ -1170,6 +1170,24 @@ func (s *apiSuite) TestTrySnap(c *check.C) { } +func (s *apiSuite) TestTrySnapRelative(c *check.C) { + req, err := http.NewRequest("POST", "/v2/snaps", nil) + c.Assert(err, check.IsNil) + + rsp := trySnap(snapsCmd, req, nil, "relative-path", 0).(*resp) + c.Assert(rsp.Type, check.Equals, ResponseTypeError) + c.Check(rsp.Result.(*errorResult).Message, testutil.Contains, "need an absolute path") +} + +func (s *apiSuite) TestTrySnapNotDir(c *check.C) { + req, err := http.NewRequest("POST", "/v2/snaps", nil) + c.Assert(err, check.IsNil) + + rsp := trySnap(snapsCmd, req, nil, "/does/not/exist", 0).(*resp) + c.Assert(rsp.Type, check.Equals, ResponseTypeError) + c.Check(rsp.Result.(*errorResult).Message, testutil.Contains, "not a snap directory") +} + func (s *apiSuite) sideloadCheck(c *check.C, content string, head map[string]string, expectedFlags snappy.InstallFlags, hasUbuntuCore bool) string { d := newTestDaemon(c) d.overlord.Loop() |
