From b9c8127e4a9056d44b9b90155b3d4fa7cdebb74c Mon Sep 17 00:00:00 2001 From: Maciej Borzecki Date: Mon, 29 Oct 2018 09:43:20 +0100 Subject: [PATCH] tests/lib/fakestore: return confinement in snap details Signed-off-by: Maciej Borzecki --- tests/lib/fakestore/store/store.go | 11 ++++-- tests/lib/fakestore/store/store_test.go | 46 ++++++++++++++++++++----- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/tests/lib/fakestore/store/store.go b/tests/lib/fakestore/store/store.go index aca91854ebd..0914a9535f0 100644 --- a/tests/lib/fakestore/store/store.go +++ b/tests/lib/fakestore/store/store.go @@ -171,6 +171,7 @@ type essentialInfo struct { Version string Size uint64 Digest string + Confinement string } var errInfo = errors.New("cannot get info") @@ -226,6 +227,7 @@ func snapEssentialInfo(w http.ResponseWriter, fn, snapID string, bs asserts.Back Version: info.Version, Digest: snapDigest, Size: size, + Confinement: string(info.Confinement), }, nil } @@ -244,6 +246,7 @@ type detailsReplyJSON struct { Version string `json:"version"` Revision int `json:"revision"` DownloadDigest string `json:"download_sha3_384"` + Confinement string `json:"confinement"` } func (s *Store) searchEndpoint(w http.ResponseWriter, req *http.Request) { @@ -293,6 +296,7 @@ func (s *Store) detailsEndpoint(w http.ResponseWriter, req *http.Request) { Version: essInfo.Version, Revision: essInfo.Revision, DownloadDigest: hexify(essInfo.Digest), + Confinement: essInfo.Confinement, } // use indent because this is a development tool, output @@ -429,6 +433,7 @@ func (s *Store) bulkEndpoint(w http.ResponseWriter, req *http.Request) { Version: essInfo.Version, Revision: essInfo.Revision, DownloadDigest: hexify(essInfo.Digest), + Confinement: essInfo.Confinement, }) } } @@ -523,8 +528,9 @@ type detailsResultV2 struct { Sha3_384 string `json:"sha3-384"` Size uint64 `json:"size"` } `json:"download"` - Version string `json:"version"` - Revision int `json:"revision"` + Version string `json:"version"` + Revision int `json:"revision"` + Confinement string `json:"confinement"` } func (s *Store) snapActionEndpoint(w http.ResponseWriter, req *http.Request) { @@ -606,6 +612,7 @@ func (s *Store) snapActionEndpoint(w http.ResponseWriter, req *http.Request) { Name: essInfo.Name, Version: essInfo.Version, Revision: essInfo.Revision, + Confinement: essInfo.Confinement, }, } res.Snap.Publisher.ID = essInfo.DeveloperID diff --git a/tests/lib/fakestore/store/store_test.go b/tests/lib/fakestore/store/store_test.go index e4334f1e69e..7f057cb9394 100644 --- a/tests/lib/fakestore/store/store_test.go +++ b/tests/lib/fakestore/store/store_test.go @@ -139,6 +139,7 @@ func (s *storeTestSuite) TestDetailsEndpointWithAssertions(c *C) { "version": "7", "revision": float64(77), "download_sha3_384": sha3_384, + "confinement": "strict", }) } @@ -164,6 +165,29 @@ func (s *storeTestSuite) TestDetailsEndpoint(c *C) { "version": "1", "revision": float64(424242), "download_sha3_384": sha3_384, + "confinement": "strict", + }) + + snapFn = s.makeTestSnap(c, "name: foo-classic\nversion: 1\nconfinement: classic") + resp, err = s.StoreGet(`/api/v1/snaps/details/foo-classic`) + c.Assert(err, IsNil) + defer resp.Body.Close() + + c.Assert(resp.StatusCode, Equals, 200) + c.Assert(json.NewDecoder(resp.Body).Decode(&body), IsNil) + sha3_384, _ = getSha(snapFn) + c.Check(body, DeepEquals, map[string]interface{}{ + "architecture": []interface{}{"all"}, + "snap_id": "", + "package_name": "foo-classic", + "origin": "canonical", + "developer_id": "canonical", + "anon_download_url": s.store.URL() + "/download/foo-classic_1_all.snap", + "download_url": s.store.URL() + "/download/foo-classic_1_all.snap", + "version": "1", + "revision": float64(424242), + "download_sha3_384": sha3_384, + "confinement": "classic", }) } @@ -197,6 +221,7 @@ func (s *storeTestSuite) TestBulkEndpoint(c *C) { "version": "1", "revision": float64(424242), "download_sha3_384": sha3_384, + "confinement": "strict", }}) } @@ -229,6 +254,7 @@ func (s *storeTestSuite) TestBulkEndpointWithAssertions(c *C) { "version": "10", "revision": float64(99), "download_sha3_384": sha3_384, + "confinement": "strict", }}) } @@ -430,8 +456,9 @@ func (s *storeTestSuite) TestSnapActionEndpoint(c *C) { "sha3-384": sha3_384, "size": float64(size), }, - "version": "1", - "revision": float64(424242), + "version": "1", + "revision": float64(424242), + "confinement": "strict", }, }) } @@ -472,8 +499,9 @@ func (s *storeTestSuite) TestSnapActionEndpointWithAssertions(c *C) { "sha3-384": sha3_384, "size": float64(size), }, - "version": "10", - "revision": float64(99), + "version": "10", + "revision": float64(99), + "confinement": "strict", }, }) } @@ -513,8 +541,9 @@ func (s *storeTestSuite) TestSnapActionEndpointRefreshAll(c *C) { "sha3-384": sha3_384, "size": float64(size), }, - "version": "1", - "revision": float64(424242), + "version": "1", + "revision": float64(424242), + "confinement": "strict", }, }) } @@ -555,8 +584,9 @@ func (s *storeTestSuite) TestSnapActionEndpointWithAssertionsInstall(c *C) { "sha3-384": sha3_384, "size": float64(size), }, - "version": "10", - "revision": float64(99), + "version": "10", + "revision": float64(99), + "confinement": "strict", }, }) }