This commit replaces the use of "sanity" with more inclusive
naming.
When `sanity` is used in a more general sense either `validity`
or `quick` is used.
Return an explicit error, which can be checked for, when a key with given
ID/name is not found by the keypair manager.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
* daemon,tests: support forgetting device serial via API
this is done by posting {"action":"forget"} to /v2/model/serial
a flag no-registration-until-reboot is also supported
* many: more consistent naming Delete => DeleteByName on keypair mgrs
we actually want to introduce a Delete by key id on some of them now
* asserts: implement KeypairManager.Delete
* devicestate: Unregister deletes the device key pair as well
* tests: test device key deletion in generic-unregister
* asserts: avoid skipping the GPGKeypairManager.Delete test
pair --yes to --batch in the test
if current system time is unreliable have a mode where Database checks
for key expiry just based on assuming that current time is >= known
earliest time
this is set up via Database.SetEarliestTime
internally a new predicate AccountKey.isKeyValidAbout(earliest,
latest) is used to support this
We occasionally get the following backtrace in the tests:
----------------------------------------------------------------------
PANIC: api_users_test.go:762: userSuite.TestPostCreateUserFromAssertionNoModel
... Panic: cannot add test assertions: model assertion timestamp outside of signing key validity (key valid since "2021-02-23 11:10:41 +0000 UTC") (PC=0x45CF4A)
/snap/go/2117/src/runtime/panic.go:491
in gopanic
/home/runner/work/snapd/snapd/src/github.com/snapcore/snapd/overlord/assertstate/assertstatetest/add_many.go:38
in AddMany
api_users_test.go:776
in userSuite.TestPostCreateUserFromAssertionNoModel
/snap/go/2117/src/reflect/value.go:302
in Value.Call
/snap/go/2117/src/runtime/asm_amd64.s:2337
in goexit
OOPS: 439 passed, 1 skipped, 1 PANICKED
--- FAIL: Test (9.62s)
FAIL
coverage: 86.4% of statements
FAIL github.com/snapcore/snapd/daemon 9.786s
Adding a timestamp of the assertion, will help it to debug the problem further.
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
FindSequence finds a sequence-forming assertion based the given
headers. Provided headers must contain a prefix of the primary key
for the assertion type except for the sequence header.
Th assertion is the first in the sequence under the prefix with
sequential number > after.
If after is -1 it returns instead the assertion with the largest
sequential number.
This converts the singleton asserts.ErrNotFound to a richer asserts.NotFoundError struct carrying Type and optionally PrimaryKey, similar to store.AssertionNotFoundError which then gets folded with this.
This means code doesn't have to worry anymore which is which or to convert between the two. And when possible there is more information around. Though Backstores can continue to return minimal information (Type but not Headers in the new error).
A helper asserts.IsNotFound is also added to cover the simple old ==/!= asserts.ErrNotFound needs.
This also fixes/adjust some error handling to usually not repeat the richer information twice.