func (s *FirstBootTestSuite) TestImportAssertionsFromSeedNoModelAsserts(c *C) { st := s.overlord.State() st.Lock() defer st.Unlock() assertsChain := s.makeModelAssertionChain(c) for _, as := range assertsChain { if as.Type() != asserts.ModelType { fn := filepath.Join(dirs.SnapSeedDir, "assertions", "model") err := ioutil.WriteFile(fn, asserts.Encode(as), 0644) c.Assert(err, IsNil) break } } // try import and verify that its rejects because other assertions are // missing err := devicestate.ImportAssertionsFromSeed(st) c.Assert(err, ErrorMatches, "need a model assertion") }
func (s *FirstBootTestSuite) TestImportAssertionsFromSeedTwoModelAsserts(c *C) { st := s.overlord.State() st.Lock() defer st.Unlock() // write out two model assertions model := s.makeModelAssertion(c, "my-model") fn := filepath.Join(dirs.SnapSeedDir, "assertions", "model") err := ioutil.WriteFile(fn, asserts.Encode(model), 0644) c.Assert(err, IsNil) model2 := s.makeModelAssertion(c, "my-second-model") fn = filepath.Join(dirs.SnapSeedDir, "assertions", "model2") err = ioutil.WriteFile(fn, asserts.Encode(model2), 0644) c.Assert(err, IsNil) // try import and verify that its rejects because other assertions are // missing err = devicestate.ImportAssertionsFromSeed(st) c.Assert(err, ErrorMatches, "cannot add more than one model assertion") }
func (s *FirstBootTestSuite) TestImportAssertionsFromSeedHappy(c *C) { ovld, err := overlord.New() c.Assert(err, IsNil) st := ovld.State() // add a bunch of assert files assertsChain := s.makeModelAssertionChain(c) for i, as := range assertsChain { fn := filepath.Join(dirs.SnapSeedDir, "assertions", strconv.Itoa(i)) err := ioutil.WriteFile(fn, asserts.Encode(as), 0644) c.Assert(err, IsNil) } // import them st.Lock() defer st.Unlock() err = devicestate.ImportAssertionsFromSeed(st) c.Assert(err, IsNil) // verify that the model was added db := assertstate.DB(st) as, err := db.Find(asserts.ModelType, map[string]string{ "series": "16", "brand-id": "my-brand", "model": "my-model", }) c.Assert(err, IsNil) _, ok := as.(*asserts.Model) c.Check(ok, Equals, true) ds, err := auth.Device(st) c.Assert(err, IsNil) c.Check(ds.Brand, Equals, "my-brand") c.Check(ds.Model, Equals, "my-model") }