cli: Add test for unknown field in identity doc

Add a test to confirm that the identity can still be deserialized when an
unknown field is added.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2024-05-06 13:13:05 +01:00 committed by cloudhead
parent 9b719d0cca
commit e8f2f88bf6
No known key found for this signature in database
2 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,47 @@
The payloads in the identity document are extensible and arbitrary fields can be
added. Here we will add an emoji alias for the heartwood project:
```
$ rad id update --title "Add emoji alias" --description "Adding alias field" --payload xyz.radicle.project alias '"❤️🪵"'
✓ Identity revision 05100d3f0a73b9373681677158615a53ba51940e created
╭────────────────────────────────────────────────────────────────────────╮
│ Title Add emoji alias │
│ Revision 05100d3f0a73b9373681677158615a53ba51940e │
│ Blob a0f421c928dcfc6eca129fc2ea1f50877de7dc20 │
│ Author did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi │
│ State accepted │
│ Quorum yes │
│ │
│ Adding alias field │
├────────────────────────────────────────────────────────────────────────┤
│ ✓ did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi alice (you) │
╰────────────────────────────────────────────────────────────────────────╯
@@ -1,13 +1,14 @@
{
"payload": {
"xyz.radicle.project": {
+ "alias": "❤️🪵",
"defaultBranch": "master",
"description": "Radicle Heartwood Protocol & Stack",
"name": "heartwood"
}
},
"delegates": [
"did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi"
],
"threshold": 1
}
```
We can see that the project payload still loads by using `rad ls` which will
attempt to deserialize the payload:
```
$ rad ls
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Name RID Visibility Head Description │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ heartwood rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji public f2de534 Radicle Heartwood Protocol & Stack │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```

View File

@ -627,6 +627,35 @@ fn rad_id_conflict() {
.unwrap(); .unwrap();
} }
#[test]
fn rad_id_unknown_field() {
let mut environment = Environment::new();
let alice = environment.node(config::node("alice"));
let working = tempfile::tempdir().unwrap();
let working = working.path();
// Setup a test repository.
fixtures::repository(working.join("alice"));
test(
"examples/rad-init.md",
working.join("alice"),
Some(&alice.home),
[],
)
.unwrap();
let alice = alice.spawn();
test(
"examples/rad-id-unknown-field.md",
working.join("alice"),
Some(&alice.home),
[],
)
.unwrap();
}
#[test] #[test]
fn rad_node_connect() { fn rad_node_connect() {
let mut environment = Environment::new(); let mut environment = Environment::new();