summaryrefslogtreecommitdiff
diff options
authorMichael Vogt <mvo@ubuntu.com>2016-06-01 17:47:49 +0200
committerMichael Vogt <mvo@ubuntu.com>2016-06-01 17:47:49 +0200
commit758e630ec5530234a1e8996d1a186857b16f56cf (patch)
treee60ec4b2e6f67803c0a3131375893a12189a3a45
parent7a6ea691b103c79ddfcae6bbc317c86fda7e3624 (diff)
do try mode server side validationbugfix/snap-try-relative
-rw-r--r--daemon/api.go3
-rw-r--r--daemon/api_test.go18
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()