Skip to main content

kanidmd_lib/server/
assert.rs

1use crate::{prelude::*, server::batch_modify::ModSetValid};
2use crypto_glue::s256::Sha256Output;
3use std::collections::{BTreeMap, BTreeSet};
4
5#[derive(Debug)]
6pub enum AttributeAssertion {
7    // The ValueSet must look exactly like this.
8    Set(ValueSet),
9    // The ValueSet must not be present.
10    Absent,
11    // TODO: We could in future add a "merge" style statement to this.
12}
13
14impl From<ValueSet> for AttributeAssertion {
15    fn from(vs: ValueSet) -> Self {
16        AttributeAssertion::Set(vs)
17    }
18}
19
20#[derive(Debug)]
21pub enum EntryAssertion {
22    // Could do an assert variant to make an entry look *exactly* like this, but that
23    // has a lot of potential risks with internal attributes.
24    Present {
25        target: Uuid,
26        // Option ValueSet represents a removal.
27        attrs: BTreeMap<Attribute, Option<ValueSet>>,
28    },
29    Absent {
30        target: Uuid,
31    },
32}
33
34#[derive(Debug, Default)]
35pub enum AssertOnce {
36    #[default]
37    No,
38    Yes {
39        id: Uuid,
40        nonce: Sha256Output,
41    },
42}
43
44#[derive(Debug)]
45pub struct AssertEvent {
46    pub ident: Identity,
47    pub asserts: Vec<EntryAssertion>,
48    pub once: AssertOnce,
49}
50
51#[derive(Debug)]
52struct Assertion {
53    target: Uuid,
54    attrs: BTreeMap<Attribute, Option<ValueSet>>,
55}
56
57#[derive(Debug)]
58enum AssertionInner {
59    None,
60    Create { asserts: Vec<Assertion> },
61    Modify { asserts: Vec<Assertion> },
62    Remove { targets: Vec<Uuid> },
63}
64
65impl QueryServerWriteTransaction<'_> {
66    #[instrument(level = "debug", skip_all)]
67    /// Document me please senpai.
68    pub fn assert(&mut self, ae: AssertEvent) -> Result<(), OperationError> {
69        let AssertEvent {
70            ident,
71            asserts,
72            once,
73        } = ae;
74
75        if let AssertOnce::Yes { id, nonce } = once {
76            // This should only be run once, provided that the valid tag is the same
77            // on the existing migration record.
78
79            let filter = filter!(f_and(vec![
80                f_eq(Attribute::Uuid, PartialValue::Uuid(id)),
81                f_eq(Attribute::Class, EntryClass::AssertionNonce.into())
82            ]));
83
84            let search_result = self.internal_search(filter).or_else(|err| {
85                if err == OperationError::NoMatchingEntries {
86                    Ok(Vec::with_capacity(0))
87                } else {
88                    Err(err)
89                }
90            })?;
91
92            if let Some(record) = search_result.first() {
93                if record
94                    .get_ava_as_s256_set(Attribute::S256)
95                    .map(|set| set.contains(&nonce))
96                    .unwrap_or_default()
97                {
98                    // Nonce present - return we are done.
99                    info!(?id, "Assertion already applied, skipping.");
100                    return Ok(());
101                } else {
102                    // Need to update the nonce and proceed.
103                    let ml = ModifyList::new_list(vec![Modify::Set(
104                        Attribute::S256,
105                        ValueSetSha256::new(nonce) as ValueSet,
106                    )]);
107
108                    self.internal_batch_modify([(id, ml)].into_iter())?;
109                }
110            } else {
111                // No record - create one.
112
113                let entry = EntryInitNew::from_iter([
114                    (
115                        Attribute::Class,
116                        ValueSetIutf8N::new(EntryClass::AssertionNonce.into()) as ValueSet,
117                    ),
118                    (Attribute::Uuid, ValueSetUuid::new(id) as ValueSet),
119                    (Attribute::S256, ValueSetSha256::new(nonce) as ValueSet),
120                ]);
121
122                self.internal_create(vec![entry]).inspect_err(|err| {
123                    error!(?err, "Failed to creation assertion nonce.");
124                })?;
125            }
126
127            // Good to go.
128        };
129
130        // Optimise => If there is nothing to do, bail.
131        if asserts.is_empty() {
132            error!("assert: empty request");
133            return Err(OperationError::EmptyRequest);
134        }
135
136        // Yes, we could collect() here, but that makes the error/analysis messages
137        // worse because it's harder to detect which uuid is duplicate.
138
139        let mut duplicates: BTreeSet<_> = Default::default();
140        let mut present_uuids: BTreeSet<Uuid> = Default::default();
141        let mut absent_uuids: BTreeSet<Uuid> = Default::default();
142
143        for assert in &asserts {
144            match assert {
145                EntryAssertion::Present { target, .. } => {
146                    // BTreeSet returns true if the value is unique. False if already present
147                    if !present_uuids.insert(*target) {
148                        duplicates.insert(*target);
149                    }
150                }
151                EntryAssertion::Absent { target } => {
152                    if !absent_uuids.insert(*target) {
153                        duplicates.insert(*target);
154                    }
155                }
156            }
157        }
158
159        // Check the intersection of the sets, and extend duplicates if there are any.
160        duplicates.extend(present_uuids.intersection(&absent_uuids));
161
162        // If present_uuids + absent_uuids len is not the same as asserts len, it means a uuid
163        // was duplicated in the set.
164        if !duplicates.is_empty() {
165            // error
166            error!(?duplicates, "entry uuids in SCIM Assertion must be unique.");
167            return Err(OperationError::SC0033AssertionContainsDuplicateUuids);
168        }
169
170        // Determine which exist.
171        // TODO: Make an optimised uuid search in the BE to just get an IDL.
172        let filter = filter!(f_or(
173            present_uuids
174                .iter()
175                .copied()
176                .chain(absent_uuids.iter().copied())
177                .map(|u| f_eq(Attribute::Uuid, PartialValue::Uuid(u)))
178                .collect()
179        ));
180
181        // While we do load then discard these, it doesn't really matter as it means
182        // all the entries we are about to modify/delete are now "cache hot".
183        let existing_entries = self.internal_search(filter).or_else(|err| {
184            if err == OperationError::NoMatchingEntries {
185                Ok(Vec::with_capacity(0))
186            } else {
187                Err(err)
188            }
189        })?;
190
191        // Which uuids need to be created?
192        let existing_uuids: BTreeSet<Uuid> = existing_entries
193            .iter()
194            .map(|entry| entry.get_uuid())
195            .collect();
196
197        let create_uuids: BTreeSet<Uuid> =
198            present_uuids.difference(&existing_uuids).copied().collect();
199
200        // Only delete uuids that currently actually exist.
201        let delete_uuids: BTreeSet<Uuid> = absent_uuids
202            .intersection(&existing_uuids)
203            .copied()
204            .collect();
205
206        // Break up the asserts then into sets of creates, mods and deletes. We can
207        // do this because all three sets of uuids now exist.
208        //
209        // We apply the assertions *in order* from this point.
210        //
211        // We also want to ensure as much *batching* as possible to optimise our write paths.
212        // To do this effectively we need to use a vecDeque to allow front poping, else we would
213        // need to reverse the list.
214
215        let mut working_assert = AssertionInner::None;
216
217        let mut assert_batches = Vec::with_capacity(asserts.len());
218
219        for entry_assert in asserts.into_iter() {
220            match entry_assert {
221                EntryAssertion::Absent { target } => {
222                    if !delete_uuids.contains(&target) {
223                        // The requested uuid to removed already does not exist. We
224                        // can skip it as a result.
225                        continue;
226                    }
227
228                    if let AssertionInner::Remove { targets } = &mut working_assert {
229                        // Push the next remove.
230                        targets.push(target)
231                    } else {
232                        let mut new_assert = AssertionInner::Remove {
233                            targets: vec![target],
234                        };
235
236                        std::mem::swap(&mut new_assert, &mut working_assert);
237
238                        assert_batches.push(new_assert);
239                    }
240                }
241
242                EntryAssertion::Present { target, attrs } if create_uuids.contains(&target) => {
243                    if let AssertionInner::Create { asserts } = &mut working_assert {
244                        // Push the next create
245                        asserts.push(Assertion { target, attrs })
246                    } else {
247                        let mut new_assert = AssertionInner::Create {
248                            asserts: vec![Assertion { target, attrs }],
249                        };
250
251                        std::mem::swap(&mut new_assert, &mut working_assert);
252
253                        assert_batches.push(new_assert);
254                    }
255                }
256
257                EntryAssertion::Present { target, attrs } => {
258                    if let AssertionInner::Modify { asserts } = &mut working_assert {
259                        // Push the next modify
260                        asserts.push(Assertion { target, attrs })
261                    } else {
262                        let mut new_assert = AssertionInner::Modify {
263                            asserts: vec![Assertion { target, attrs }],
264                        };
265
266                        std::mem::swap(&mut new_assert, &mut working_assert);
267
268                        assert_batches.push(new_assert);
269                    }
270                }
271            }
272        }
273
274        // Finally push the last working assert
275        assert_batches.push(working_assert);
276        trace!("{:#?}", assert_batches);
277
278        // Now we can finally actually do the work.
279        // Loop and apply!
280        for assertion in assert_batches.into_iter() {
281            match assertion {
282                AssertionInner::Create { asserts } => {
283                    let entries = asserts
284                        .into_iter()
285                        .map(|Assertion { target, attrs }| {
286                            // Convert the attributes so that EntryInitNew understands them.
287                            let mut attrs: crate::entry::Eattrs = attrs
288                                .into_iter()
289                                .filter_map(|(attr, assert_valueset)| {
290                                    // This removes anything that is set to absent, we don't need it
291                                    // during a create since they are none values.
292                                    assert_valueset.map(|vs| (attr, vs))
293                                })
294                                .collect();
295
296                            attrs.insert(Attribute::Uuid, ValueSetUuid::new(target));
297
298                            EntryInitNew::from_iter(attrs.into_iter())
299                        })
300                        .collect();
301
302                    let create_event = CreateEvent {
303                        ident: ident.clone(),
304                        entries,
305                        return_created_uuids: false,
306                    };
307
308                    self.create(&create_event)?;
309                }
310                AssertionInner::Modify { asserts } => {
311                    let modset = asserts
312                        .into_iter()
313                        .map(|Assertion { target, attrs }| {
314                            let ml = attrs
315                                .into_iter()
316                                .map(|(attr, assert)| match assert {
317                                    Some(vs) => Modify::Set(attr, vs),
318                                    None => Modify::Purged(attr),
319                                })
320                                .collect();
321
322                            let ml = ModifyList::new_list(ml);
323
324                            (target, ml)
325                        })
326                        .map(|(target, ml)| {
327                            ml.validate(self.get_schema())
328                                .map(|modlist| (target, modlist))
329                                .map_err(OperationError::SchemaViolation)
330                        })
331                        .collect::<Result<ModSetValid, _>>()?;
332
333                    let batch_modify_event = BatchModifyEvent {
334                        ident: ident.clone(),
335                        modset,
336                    };
337
338                    self.batch_modify(&batch_modify_event)?;
339                }
340                AssertionInner::Remove { targets } => {
341                    let filter = Filter::new(f_or(
342                        targets
343                            .into_iter()
344                            .map(|u| f_eq(Attribute::Uuid, PartialValue::Uuid(u)))
345                            .collect(),
346                    ));
347
348                    let filter_orig = filter
349                        .validate(self.get_schema())
350                        .map_err(OperationError::SchemaViolation)?;
351                    let filter = filter_orig.clone().into_ignore_hidden();
352
353                    let delete_event = DeleteEvent {
354                        ident: ident.clone(),
355                        filter,
356                        filter_orig,
357                    };
358
359                    self.delete(&delete_event)?;
360                }
361                AssertionInner::None => {}
362            }
363        }
364
365        // Complete!
366        Ok(())
367    }
368}
369
370#[cfg(test)]
371mod tests {
372    use super::{AssertEvent, AssertOnce, EntryAssertion};
373    use crate::prelude::*;
374    use crypto_glue::{s256::Sha256, traits::*};
375    use std::collections::BTreeMap;
376    // use std::sync::Arc;
377
378    #[qs_test]
379    async fn test_entry_asserts_basic(server: &QueryServer) {
380        let mut server_txn = server.write(duration_from_epoch_now()).await.unwrap();
381
382        let assert_event = AssertEvent {
383            ident: Identity::from_internal(),
384            asserts: vec![],
385            once: AssertOnce::No,
386        };
387
388        let err = server_txn.assert(assert_event).expect_err("Should Fail!");
389        assert_eq!(err, OperationError::EmptyRequest);
390
391        // ======
392        // Test duplicate uuids in both delete / assert
393
394        let uuid_a = Uuid::new_v4();
395
396        let assert_event = AssertEvent {
397            ident: Identity::from_internal(),
398            asserts: vec![
399                EntryAssertion::Absent { target: uuid_a },
400                EntryAssertion::Absent { target: uuid_a },
401            ],
402            once: AssertOnce::No,
403        };
404
405        let err = server_txn.assert(assert_event).expect_err("Should Fail!");
406        assert_eq!(err, OperationError::SC0033AssertionContainsDuplicateUuids);
407
408        // ======
409        let assert_event = AssertEvent {
410            ident: Identity::from_internal(),
411            asserts: vec![
412                EntryAssertion::Absent { target: uuid_a },
413                EntryAssertion::Present {
414                    target: uuid_a,
415                    attrs: BTreeMap::default(),
416                },
417            ],
418            once: AssertOnce::No,
419        };
420
421        let err = server_txn.assert(assert_event).expect_err("Should Fail!");
422        assert_eq!(err, OperationError::SC0033AssertionContainsDuplicateUuids);
423
424        // ======
425        let assert_event = AssertEvent {
426            ident: Identity::from_internal(),
427            asserts: vec![
428                EntryAssertion::Present {
429                    target: uuid_a,
430                    attrs: BTreeMap::default(),
431                },
432                EntryAssertion::Present {
433                    target: uuid_a,
434                    attrs: BTreeMap::default(),
435                },
436            ],
437            once: AssertOnce::No,
438        };
439
440        let err = server_txn.assert(assert_event).expect_err("Should Fail!");
441        assert_eq!(err, OperationError::SC0033AssertionContainsDuplicateUuids);
442
443        // ======
444        // Create
445        let assert_event = AssertEvent {
446            ident: Identity::from_internal(),
447            asserts: vec![EntryAssertion::Present {
448                target: uuid_a,
449                attrs: BTreeMap::from([
450                    (
451                        Attribute::Class,
452                        ValueSetIutf8N::from_iter([
453                            EntryClass::Person.into(),
454                            EntryClass::Account.into(),
455                        ]) as Option<ValueSet>,
456                    ),
457                    (Attribute::Name, Some(ValueSetIname::new("test_entry_a"))),
458                    (
459                        Attribute::DisplayName,
460                        vs_utf8!("Test Entry A".into()).into(),
461                    ),
462                ]),
463            }],
464            once: AssertOnce::No,
465        };
466
467        server_txn.assert(assert_event).expect("Must Succeed");
468
469        let entry_a = server_txn
470            .internal_search_uuid(uuid_a)
471            .expect("Must succeed");
472        assert_eq!(
473            entry_a.get_ava_single_utf8(Attribute::DisplayName),
474            Some("Test Entry A")
475        );
476
477        // ======
478        // Modify
479        let assert_event = AssertEvent {
480            ident: Identity::from_internal(),
481            asserts: vec![EntryAssertion::Present {
482                target: uuid_a,
483                attrs: BTreeMap::from([(
484                    Attribute::DisplayName,
485                    vs_utf8!("Test Entry A Updated".into()).into(),
486                )]),
487            }],
488            once: AssertOnce::No,
489        };
490
491        server_txn.assert(assert_event).expect("Must Succeed");
492
493        let entry_a = server_txn
494            .internal_search_uuid(uuid_a)
495            .expect("Must succeed");
496        assert_eq!(
497            entry_a.get_ava_single_utf8(Attribute::DisplayName),
498            Some("Test Entry A Updated")
499        );
500
501        // ======
502        // Remove
503        let assert_event = AssertEvent {
504            ident: Identity::from_internal(),
505            asserts: vec![EntryAssertion::Absent { target: uuid_a }],
506            once: AssertOnce::No,
507        };
508
509        server_txn.assert(assert_event).expect("Must Succeed");
510
511        let err = server_txn
512            .internal_search_uuid(uuid_a)
513            .expect_err("Must fail");
514
515        // Now absent.
516        assert_eq!(err, OperationError::NoMatchingEntries);
517
518        // Now mix and match things. We want to ensure there are at least two operations
519        // per assertion, so that they both occur.
520
521        let uuid_b = Uuid::new_v4();
522        let uuid_c = Uuid::new_v4();
523        let uuid_d = Uuid::new_v4();
524
525        // Create B and D
526        let assert_event = AssertEvent {
527            ident: Identity::from_internal(),
528            asserts: vec![
529                EntryAssertion::Present {
530                    target: uuid_b,
531                    attrs: BTreeMap::from([
532                        (
533                            Attribute::Class,
534                            ValueSetIutf8N::from_iter([
535                                EntryClass::Person.into(),
536                                EntryClass::Account.into(),
537                            ]) as Option<ValueSet>,
538                        ),
539                        (Attribute::Name, Some(ValueSetIname::new("test_entry_b"))),
540                        (
541                            Attribute::DisplayName,
542                            vs_utf8!("Test Entry B".into()).into(),
543                        ),
544                    ]),
545                },
546                EntryAssertion::Present {
547                    target: uuid_d,
548                    attrs: BTreeMap::from([
549                        (
550                            Attribute::Class,
551                            ValueSetIutf8N::from_iter([
552                                EntryClass::Person.into(),
553                                EntryClass::Account.into(),
554                            ]) as Option<ValueSet>,
555                        ),
556                        (Attribute::Name, Some(ValueSetIname::new("test_entry_d"))),
557                        (
558                            Attribute::DisplayName,
559                            vs_utf8!("Test Entry D".into()).into(),
560                        ),
561                    ]),
562                },
563            ],
564            once: AssertOnce::No,
565        };
566
567        server_txn.assert(assert_event).expect("Must Succeed");
568        assert!(server_txn
569            .internal_exists_uuid(uuid_b)
570            .expect("Failed to check existance"));
571        assert!(server_txn
572            .internal_exists_uuid(uuid_d)
573            .expect("Failed to check existance"));
574
575        // ====
576        // Create C in between modifies to B and D
577        let assert_event = AssertEvent {
578            ident: Identity::from_internal(),
579            asserts: vec![
580                EntryAssertion::Present {
581                    target: uuid_b,
582                    attrs: BTreeMap::from([
583                        (
584                            Attribute::Class,
585                            ValueSetIutf8N::from_iter([
586                                EntryClass::Person.into(),
587                                EntryClass::Account.into(),
588                            ]) as Option<ValueSet>,
589                        ),
590                        (Attribute::Name, Some(ValueSetIname::new("test_entry_b"))),
591                        (
592                            Attribute::DisplayName,
593                            vs_utf8!("Test Entry B".into()).into(),
594                        ),
595                    ]),
596                },
597                EntryAssertion::Present {
598                    target: uuid_c,
599                    attrs: BTreeMap::from([
600                        (
601                            Attribute::Class,
602                            ValueSetIutf8N::from_iter([
603                                EntryClass::Person.into(),
604                                EntryClass::Account.into(),
605                            ]) as Option<ValueSet>,
606                        ),
607                        (Attribute::Name, Some(ValueSetIname::new("test_entry_c"))),
608                        (
609                            Attribute::DisplayName,
610                            vs_utf8!("Test Entry C".into()).into(),
611                        ),
612                    ]),
613                },
614                EntryAssertion::Present {
615                    target: uuid_d,
616                    attrs: BTreeMap::from([
617                        (
618                            Attribute::Class,
619                            ValueSetIutf8N::from_iter([
620                                EntryClass::Person.into(),
621                                EntryClass::Account.into(),
622                            ]) as Option<ValueSet>,
623                        ),
624                        (Attribute::Name, Some(ValueSetIname::new("test_entry_d"))),
625                        (
626                            Attribute::DisplayName,
627                            vs_utf8!("Test Entry D".into()).into(),
628                        ),
629                    ]),
630                },
631            ],
632            once: AssertOnce::No,
633        };
634
635        server_txn.assert(assert_event).expect("Must Succeed");
636        assert!(server_txn
637            .internal_exists_uuid(uuid_b)
638            .expect("Failed to check existance"));
639        assert!(server_txn
640            .internal_exists_uuid(uuid_c)
641            .expect("Failed to check existance"));
642        assert!(server_txn
643            .internal_exists_uuid(uuid_d)
644            .expect("Failed to check existance"));
645
646        // ====
647        // Modify C in between deletes of B and D
648        let assert_event = AssertEvent {
649            ident: Identity::from_internal(),
650            asserts: vec![
651                EntryAssertion::Absent { target: uuid_b },
652                EntryAssertion::Present {
653                    target: uuid_c,
654                    attrs: BTreeMap::from([
655                        (
656                            Attribute::Class,
657                            ValueSetIutf8N::from_iter([
658                                EntryClass::Person.into(),
659                                EntryClass::Account.into(),
660                            ]) as Option<ValueSet>,
661                        ),
662                        (Attribute::Name, Some(ValueSetIname::new("test_entry_c"))),
663                        (
664                            Attribute::DisplayName,
665                            vs_utf8!("Test Entry C".into()).into(),
666                        ),
667                    ]),
668                },
669                EntryAssertion::Absent { target: uuid_d },
670            ],
671            once: AssertOnce::No,
672        };
673
674        server_txn.assert(assert_event).expect("Must Succeed");
675
676        assert!(!server_txn
677            .internal_exists_uuid(uuid_b)
678            .expect("Failed to check existance"));
679        assert!(server_txn
680            .internal_exists_uuid(uuid_c)
681            .expect("Failed to check existance"));
682        assert!(!server_txn
683            .internal_exists_uuid(uuid_d)
684            .expect("Failed to check existance"));
685    }
686
687    #[qs_test]
688    async fn test_entry_asserts_nonce(server: &QueryServer) {
689        // This will test that assertions run only once. The full breadth of assertion
690        // feature testing is done above. The majority of this logic is applying to
691        // modifications due to how this is written.
692
693        let mut server_txn = server.write(duration_from_epoch_now()).await.unwrap();
694
695        let uuid_a = Uuid::new_v4();
696        let assert_id = Uuid::new_v4();
697        let nonce_1 = {
698            let mut hasher = Sha256::new();
699            hasher.update([1]);
700            hasher.finalize()
701        };
702
703        let nonce_2 = {
704            let mut hasher = Sha256::new();
705            hasher.update([2]);
706            hasher.finalize()
707        };
708
709        let assert_event = AssertEvent {
710            ident: Identity::from_internal(),
711            asserts: vec![EntryAssertion::Present {
712                target: uuid_a,
713                attrs: BTreeMap::from([
714                    (
715                        Attribute::Class,
716                        ValueSetIutf8N::from_iter([
717                            EntryClass::Person.into(),
718                            EntryClass::Account.into(),
719                        ]) as Option<ValueSet>,
720                    ),
721                    (Attribute::Name, Some(ValueSetIname::new("test_entry_a"))),
722                    (
723                        Attribute::DisplayName,
724                        vs_utf8!("Test Entry A".into()).into(),
725                    ),
726                ]),
727            }],
728            once: AssertOnce::Yes {
729                id: assert_id,
730                nonce: nonce_1,
731            },
732        };
733
734        server_txn.assert(assert_event).expect("Must Succeed");
735
736        let entry_a = server_txn
737            .internal_search_uuid(uuid_a)
738            .expect("Must succeed");
739        assert_eq!(
740            entry_a.get_ava_single_utf8(Attribute::DisplayName),
741            Some("Test Entry A")
742        );
743
744        // =========================================
745        let assert_event = AssertEvent {
746            ident: Identity::from_internal(),
747            asserts: vec![EntryAssertion::Present {
748                target: uuid_a,
749                attrs: BTreeMap::from([
750                    (
751                        Attribute::Class,
752                        ValueSetIutf8N::from_iter([
753                            EntryClass::Person.into(),
754                            EntryClass::Account.into(),
755                        ]) as Option<ValueSet>,
756                    ),
757                    (Attribute::Name, Some(ValueSetIname::new("test_entry_a"))),
758                    (
759                        Attribute::DisplayName,
760                        // =============================
761                        // We update the display name
762                        vs_utf8!("Test Entry A Updated".into()).into(),
763                    ),
764                ]),
765            }],
766            once: AssertOnce::Yes {
767                id: assert_id,
768                // But we don't update the nonce. This will cause the change to be skipped.
769                nonce: nonce_1,
770            },
771        };
772
773        server_txn.assert(assert_event).expect("Must Succeed");
774
775        let entry_a = server_txn
776            .internal_search_uuid(uuid_a)
777            .expect("Must succeed");
778        assert_eq!(
779            entry_a.get_ava_single_utf8(Attribute::DisplayName),
780            Some("Test Entry A")
781        );
782
783        // ===========================================
784
785        let assert_event = AssertEvent {
786            ident: Identity::from_internal(),
787            asserts: vec![EntryAssertion::Present {
788                target: uuid_a,
789                attrs: BTreeMap::from([
790                    (
791                        Attribute::Class,
792                        ValueSetIutf8N::from_iter([
793                            EntryClass::Person.into(),
794                            EntryClass::Account.into(),
795                        ]),
796                    ),
797                    (Attribute::Name, Some(ValueSetIname::new("test_entry_a"))),
798                    (
799                        Attribute::DisplayName,
800                        // =============================
801                        // We update the display name
802                        vs_utf8!("Test Entry A Updated".into()).into(),
803                    ),
804                ]),
805            }],
806            once: AssertOnce::Yes {
807                id: assert_id,
808                // But because we update the nonce it now WILL apply.
809                nonce: nonce_2,
810            },
811        };
812
813        server_txn.assert(assert_event).expect("Must Succeed");
814
815        let entry_a = server_txn
816            .internal_search_uuid(uuid_a)
817            .expect("Must succeed");
818        assert_eq!(
819            entry_a.get_ava_single_utf8(Attribute::DisplayName),
820            Some("Test Entry A Updated")
821        );
822    }
823}