From be04655e05a07817bd1c275ebe1e9d2d4731ee3c Mon Sep 17 00:00:00 2001 From: Stephen Mwangi Date: Fri, 15 Nov 2024 12:46:47 +0300 Subject: [PATCH] o/devicestate: add sign device assertion failure test --- overlord/devicestate/devicestate_test.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/overlord/devicestate/devicestate_test.go b/overlord/devicestate/devicestate_test.go index c2b79b73ffc..7f4b62919ca 100644 --- a/overlord/devicestate/devicestate_test.go +++ b/overlord/devicestate/devicestate_test.go @@ -1,7 +1,7 @@ // -*- Mode: Go; indent-tabs-mode: t -*- /* - * Copyright (C) 2016-2022 Canonical Ltd + * Copyright (C) 2016-2024 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -2754,3 +2754,24 @@ func (s *deviceMgrSuite) TestDefaultRecoverySystem(c *C) { c.Assert(err, IsNil) c.Check(*system, Equals, expectedSystem) } + +func (s *deviceMgrSuite) TestSignDeviceAssertionFail(c *C) { + s.state.Lock() + defer s.state.Unlock() + + s.makeModelAssertionInState(c, "canonical", "pc", map[string]interface{}{ + "architecture": "amd64", + "kernel": "pc-kernel", + "gadget": "pc", + }) + + devicestatetest.SetDevice(s.state, &auth.DeviceState{ + Brand: "canonical", + Model: "pc", + Serial: "serialserialserial", + KeyID: "not-in-key-pair-manager", + }) + + _, err := s.mgr.SignDeviceAssertion(asserts.DeviceSessionRequestType, nil, nil) + c.Assert(err, ErrorMatches, "cannot read device key pair: cannot find key pair") +}