@@ -33,16 +33,20 @@ import (
3333 "gopkg.in/check.v1"
3434
3535 "github.com/snapcore/snapd/arch"
36+ "github.com/snapcore/snapd/asserts"
3637 "github.com/snapcore/snapd/boot"
3738 "github.com/snapcore/snapd/daemon"
3839 "github.com/snapcore/snapd/dirs"
3940 "github.com/snapcore/snapd/dirs/dirstest"
4041 "github.com/snapcore/snapd/features"
4142 "github.com/snapcore/snapd/interfaces"
4243 "github.com/snapcore/snapd/interfaces/ifacetest"
44+ "github.com/snapcore/snapd/overlord/assertstate/assertstatetest"
4345 "github.com/snapcore/snapd/overlord/auth"
4446 "github.com/snapcore/snapd/overlord/configstate/config"
47+ "github.com/snapcore/snapd/overlord/devicestate"
4548 "github.com/snapcore/snapd/overlord/fdestate"
49+ "github.com/snapcore/snapd/overlord/hookstate"
4650 "github.com/snapcore/snapd/overlord/state"
4751 "github.com/snapcore/snapd/release"
4852 "github.com/snapcore/snapd/sandbox"
@@ -1232,10 +1236,84 @@ func (s *generalSuite) TestAckWarnings(c *check.C) {
12321236 c .Check (result , check .DeepEquals , 0 )
12331237}
12341238
1235- func (s * generalSuite ) TestSysInfoStorageEncHappy (c * check.C ) {
1239+ func (s * generalSuite ) TestSysInfoStorageEncHappyWithoutModel (c * check.C ) {
12361240 s .daemon (c )
1241+
1242+ expectedStatus := ""
1243+ expectedResponse := map [string ]any {}
1244+
1245+ setExpectedStatus := func (status string ) {
1246+ expectedStatus = status
1247+ expectedResponse ["status" ] = status
1248+ expectedResponse ["auto-repair-result" ] = "not-initialized"
1249+ }
1250+
1251+ defer daemon .MockFdestateSystemState (func (s * state.State , model * asserts.Model ) (* fdestate.FDESystemState , error ) {
1252+ switch expectedStatus {
1253+ case "active" :
1254+ return & fdestate.FDESystemState {
1255+ Status : fdestate .FDEStatusActive ,
1256+ AutoRepairResult : fdestate .AutoRepairNotInitialized ,
1257+ }, nil
1258+
1259+ case "inactive" :
1260+ return & fdestate.FDESystemState {
1261+ Status : fdestate .FDEStatusInactive ,
1262+ AutoRepairResult : fdestate .AutoRepairNotInitialized ,
1263+ }, nil
1264+ }
1265+
1266+ c .Check (model , check .IsNil )
1267+
1268+ return nil , errors .New ("cannot set unsupported expected status" )
1269+ })()
1270+
1271+ req , err := http .NewRequest ("GET" , "/v2/system-info/storage-encrypted" , nil )
1272+ c .Assert (err , check .IsNil )
1273+
1274+ setExpectedStatus ("active" )
1275+ rsp := s .syncReq (c , req , nil , actionIsExpected )
1276+ c .Check (rsp .Status , check .Equals , 200 )
1277+ c .Check (rsp .Type , check .Equals , daemon .ResponseTypeSync )
1278+ resultBytes , err := json .Marshal (rsp .Result )
1279+ c .Assert (err , check .IsNil )
1280+ var resultAbstract any
1281+ err = json .Unmarshal (resultBytes , & resultAbstract )
1282+ c .Assert (err , check .IsNil )
1283+ c .Check (resultAbstract , check .DeepEquals , expectedResponse )
1284+
1285+ setExpectedStatus ("inactive" )
1286+ rsp = s .syncReq (c , req , nil , actionIsExpected )
1287+ c .Assert (err , check .IsNil )
1288+ resultBytes , err = json .Marshal (rsp .Result )
1289+ c .Assert (err , check .IsNil )
1290+ err = json .Unmarshal (resultBytes , & resultAbstract )
1291+ c .Assert (err , check .IsNil )
1292+ c .Check (resultAbstract , check .DeepEquals , expectedResponse )
1293+ }
1294+
1295+ func (s * generalSuite ) TestSysInfoStorageEncHappyWithModel (c * check.C ) {
1296+ d := s .daemonWithOverlordMockAndStore ()
12371297 s .expectSystemInfoStorageEncReadAccess ()
12381298
1299+ hookMgr , err := hookstate .Manager (d .Overlord ().State (), d .Overlord ().TaskRunner ())
1300+ c .Assert (err , check .IsNil )
1301+ deviceMgr , err := devicestate .Manager (d .Overlord ().State (), hookMgr , d .Overlord ().TaskRunner (), nil )
1302+ c .Assert (err , check .IsNil )
1303+ d .Overlord ().AddManager (deviceMgr )
1304+ func () {
1305+ st := d .Overlord ().State ()
1306+ st .Lock ()
1307+ defer st .Unlock ()
1308+ assertstatetest .AddMany (st , s .StoreSigning .StoreAccountKey ("" ))
1309+ assertstatetest .AddMany (st , s .Brands .AccountsAndKeys ("my-brand" )... )
1310+ s .mockModel (st , s .Brands .Model ("my-brand" , "my-model" , map [string ]any {
1311+ "architecture" : "amd64" ,
1312+ "gadget" : "gadget" ,
1313+ "kernel" : "kernel" ,
1314+ }))
1315+ }()
1316+
12391317 expectedStatus := ""
12401318 expectedResponse := map [string ]any {}
12411319
@@ -1245,7 +1323,7 @@ func (s *generalSuite) TestSysInfoStorageEncHappy(c *check.C) {
12451323 expectedResponse ["auto-repair-result" ] = "not-initialized"
12461324 }
12471325
1248- defer daemon .MockFdestateSystemState (func (* state.State ) (* fdestate.FDESystemState , error ) {
1326+ defer daemon .MockFdestateSystemState (func (s * state.State , model * asserts. Model ) (* fdestate.FDESystemState , error ) {
12491327 switch expectedStatus {
12501328 case "active" :
12511329 return & fdestate.FDESystemState {
@@ -1260,6 +1338,8 @@ func (s *generalSuite) TestSysInfoStorageEncHappy(c *check.C) {
12601338 }, nil
12611339 }
12621340
1341+ c .Check (model , check .NotNil )
1342+
12631343 return nil , errors .New ("cannot set unsupported expected status" )
12641344 })()
12651345
@@ -1290,7 +1370,7 @@ func (s *generalSuite) TestSysInfoStorageEncHappy(c *check.C) {
12901370func (s * generalSuite ) TestSysInfoStorageEncErrorImpl (c * check.C ) {
12911371 s .daemon (c )
12921372
1293- defer daemon .MockFdestateSystemState (func (* state.State ) (* fdestate.FDESystemState , error ) {
1373+ defer daemon .MockFdestateSystemState (func (* state.State , * asserts. Model ) (* fdestate.FDESystemState , error ) {
12941374 return nil , errors .New ("cannot calculate status" )
12951375 })()
12961376
0 commit comments