1use crate::{
2 prelude::*,
3 schema::SchemaAttribute,
4 valueset::{
5 uuid_to_proto_string, DbValueSetV2, ScimResolveStatus, ScimValueIntermediate,
6 UnresolvedReferenceState, ValueSet, ValueSetIntermediate, ValueSetResolveStatus,
7 ValueSetScimPut,
8 },
9};
10use kanidm_proto::scim_v1::JsonValue;
11use std::collections::BTreeSet;
12
13#[derive(Debug, Clone)]
14pub struct ValueSetUuidN {
15 set: BTreeSet<Uuid>,
16}
17
18impl ValueSetUuidN {
19 pub fn new(u: Uuid) -> Box<Self> {
20 let mut set = BTreeSet::new();
21 set.insert(u);
22 Box::new(ValueSetUuidN { set })
23 }
24
25 pub fn from_dbvs2(data: Vec<Uuid>) -> Result<ValueSet, OperationError> {
26 let set = data.into_iter().collect();
27 Ok(Box::new(ValueSetUuidN { set }))
28 }
29
30 #[allow(clippy::should_implement_trait)]
33 pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
34 where
35 T: IntoIterator<Item = Uuid>,
36 {
37 let set = iter.into_iter().collect();
38 Some(Box::new(ValueSetUuidN { set }))
39 }
40}
41
42impl ValueSetScimPut for ValueSetUuidN {
43 fn from_scim_json_put(value: JsonValue) -> Result<ValueSetResolveStatus, OperationError> {
44 let set: BTreeSet<Uuid> = serde_json::from_value(value).map_err(|err| {
45 warn!(?err, "Invalid SCIM Uuid syntax");
46 OperationError::SC0004UuidSyntaxInvalid
47 })?;
48
49 Ok(ValueSetResolveStatus::Resolved(Box::new(ValueSetUuidN {
50 set,
51 })))
52 }
53}
54
55impl ValueSetT for ValueSetUuidN {
56 fn migrate(&self) -> Result<Option<ValueSet>, OperationError> {
57 Ok(self
58 .to_uuid_single()
59 .map(|uuid| Box::new(ValueSetUuid { uuid }) as ValueSet))
60 }
61
62 fn insert_checked(&mut self, value: Value) -> Result<bool, OperationError> {
63 match value {
64 Value::UuidN(u) => Ok(self.set.insert(u)),
65 _ => {
66 debug_assert!(false);
67 Err(OperationError::InvalidValueState)
68 }
69 }
70 }
71
72 fn clear(&mut self) {
73 self.set.clear();
74 }
75
76 fn remove(&mut self, pv: &PartialValue, _cid: &Cid) -> bool {
77 match pv {
78 PartialValue::Uuid(u) => {
79 self.set.remove(u);
80 }
81 _ => {
82 debug_assert!(false);
83 }
84 };
85 self.set.is_empty()
86 }
87
88 fn contains(&self, pv: &PartialValue) -> bool {
89 match pv {
90 PartialValue::Uuid(u) => self.set.contains(u),
91 _ => false,
92 }
93 }
94
95 fn substring(&self, _pv: &PartialValue) -> bool {
96 false
97 }
98
99 fn startswith(&self, _pv: &PartialValue) -> bool {
100 false
101 }
102
103 fn endswith(&self, _pv: &PartialValue) -> bool {
104 false
105 }
106
107 fn lessthan(&self, pv: &PartialValue) -> bool {
108 match pv {
109 PartialValue::Uuid(u) => self.set.iter().any(|v| v < u),
110 _ => false,
111 }
112 }
113
114 fn len(&self) -> usize {
115 self.set.len()
116 }
117
118 fn generate_idx_eq_keys(&self) -> Vec<String> {
119 self.set
120 .iter()
121 .map(|u| u.as_hyphenated().to_string())
122 .collect()
123 }
124
125 fn syntax(&self) -> SyntaxType {
126 SyntaxType::UuidN
127 }
128
129 fn validate(&self, _schema_attr: &SchemaAttribute) -> bool {
130 true
131 }
132
133 fn to_proto_string_clone_iter(&self) -> Box<dyn Iterator<Item = String> + '_> {
134 Box::new(self.set.iter().copied().map(uuid_to_proto_string))
135 }
136
137 fn to_scim_value(&self) -> Option<ScimResolveStatus> {
138 Some(ScimResolveStatus::Resolved(ScimValueKanidm::ArrayUuid(
139 self.set.iter().copied().collect::<Vec<_>>(),
140 )))
141 }
142
143 fn to_db_valueset_v2(&self) -> DbValueSetV2 {
144 DbValueSetV2::Uuid(self.set.iter().cloned().collect())
145 }
146
147 fn to_partialvalue_iter(&self) -> Box<dyn Iterator<Item = PartialValue> + '_> {
148 Box::new(self.set.iter().copied().map(PartialValue::Uuid))
149 }
150
151 fn to_value_iter(&self) -> Box<dyn Iterator<Item = Value> + '_> {
152 Box::new(self.set.iter().copied().map(Value::UuidN))
153 }
154
155 fn equal(&self, other: &ValueSet) -> bool {
156 if let Some(other) = other.as_uuid_set() {
157 &self.set == other
158 } else {
159 debug_assert!(false);
160 false
161 }
162 }
163
164 fn merge(&mut self, other: &ValueSet) -> Result<(), OperationError> {
165 if let Some(b) = other.as_uuid_set() {
166 mergesets!(self.set, b)
167 } else {
168 debug_assert!(false);
169 Err(OperationError::InvalidValueState)
170 }
171 }
172
173 fn to_uuid_single(&self) -> Option<Uuid> {
174 if self.set.len() == 1 {
175 self.set.iter().copied().take(1).next()
176 } else {
177 None
178 }
179 }
180
181 fn as_uuid_set(&self) -> Option<&BTreeSet<Uuid>> {
182 Some(&self.set)
183 }
184
185 }
191
192#[derive(Debug, Clone)]
193pub struct ValueSetUuid {
194 uuid: Uuid,
195}
196
197impl ValueSetUuid {
198 pub fn new(uuid: Uuid) -> Box<Self> {
199 Box::new(ValueSetUuid { uuid })
200 }
201
202 pub fn from_dbvs2(uuid: Uuid) -> Result<ValueSet, OperationError> {
203 Ok(Box::new(ValueSetUuid { uuid }))
204 }
205}
206
207impl ValueSetScimPut for ValueSetUuid {
208 fn from_scim_json_put(value: JsonValue) -> Result<ValueSetResolveStatus, OperationError> {
209 let uuid: Uuid = serde_json::from_value(value).map_err(|err| {
210 warn!(?err, "Invalid SCIM Uuid syntax");
211 OperationError::SC0034UuidSyntaxInvalid
212 })?;
213
214 Ok(ValueSetResolveStatus::Resolved(Box::new(ValueSetUuid {
215 uuid,
216 })))
217 }
218}
219
220impl ValueSetT for ValueSetUuid {
221 fn insert_checked(&mut self, value: Value) -> Result<bool, OperationError> {
222 match value {
223 Value::Uuid(u) => {
224 if self.uuid != u {
225 self.uuid = u;
226 Ok(true)
227 } else {
228 Ok(false)
229 }
230 }
231 _ => {
232 debug_assert!(false);
233 Err(OperationError::InvalidValueState)
234 }
235 }
236 }
237
238 fn clear(&mut self) {
239 debug_assert!(false);
240 }
243
244 fn remove(&mut self, pv: &PartialValue, _cid: &Cid) -> bool {
245 match pv {
246 PartialValue::Uuid(u) => *u == self.uuid,
248 _ => {
249 debug_assert!(false);
250 true
251 }
252 }
253 }
254
255 fn contains(&self, pv: &PartialValue) -> bool {
256 match pv {
257 PartialValue::Uuid(u) => *u == self.uuid,
258 _ => false,
259 }
260 }
261
262 fn substring(&self, _pv: &PartialValue) -> bool {
263 false
264 }
265
266 fn startswith(&self, _pv: &PartialValue) -> bool {
267 false
268 }
269
270 fn endswith(&self, _pv: &PartialValue) -> bool {
271 false
272 }
273
274 fn lessthan(&self, pv: &PartialValue) -> bool {
275 match pv {
276 PartialValue::Uuid(u) => self.uuid < *u,
277 _ => false,
278 }
279 }
280
281 fn len(&self) -> usize {
282 1
283 }
284
285 fn generate_idx_eq_keys(&self) -> Vec<String> {
286 std::iter::once(self.uuid.as_hyphenated().to_string()).collect()
287 }
288
289 fn syntax(&self) -> SyntaxType {
290 SyntaxType::Uuid
291 }
292
293 fn validate(&self, _schema_attr: &SchemaAttribute) -> bool {
294 true
295 }
296
297 fn to_proto_string_clone_iter(&self) -> Box<dyn Iterator<Item = String> + '_> {
298 Box::new(std::iter::once(self.uuid).map(uuid_to_proto_string))
299 }
300
301 fn to_scim_value(&self) -> Option<ScimResolveStatus> {
302 Some(ScimResolveStatus::Resolved(ScimValueKanidm::Uuid(
303 self.uuid,
304 )))
305 }
306
307 fn to_db_valueset_v2(&self) -> DbValueSetV2 {
308 DbValueSetV2::UuidSingle(self.uuid)
309 }
310
311 fn to_partialvalue_iter(&self) -> Box<dyn Iterator<Item = PartialValue> + '_> {
312 Box::new(std::iter::once(self.uuid).map(PartialValue::Uuid))
313 }
314
315 fn to_value_iter(&self) -> Box<dyn Iterator<Item = Value> + '_> {
316 Box::new(std::iter::once(self.uuid).map(Value::Uuid))
317 }
318
319 fn equal(&self, other: &ValueSet) -> bool {
320 if let Some(other) = other.to_uuid_single() {
321 self.uuid == other
322 } else {
323 debug_assert!(false);
324 false
325 }
326 }
327
328 fn merge(&mut self, _other: &ValueSet) -> Result<(), OperationError> {
329 debug_assert!(false);
330 Err(OperationError::InvalidValueState)
331 }
332
333 fn to_uuid_single(&self) -> Option<Uuid> {
334 Some(self.uuid)
335 }
336}
337
338#[derive(Debug, Clone)]
339pub struct ValueSetReferN {
340 set: BTreeSet<Uuid>,
341}
342
343impl ValueSetReferN {
344 pub fn new(u: Uuid) -> Box<Self> {
345 let mut set = BTreeSet::new();
346 set.insert(u);
347 Box::new(ValueSetReferN { set })
348 }
349
350 pub fn push(&mut self, u: Uuid) -> bool {
351 self.set.insert(u)
352 }
353
354 pub fn from_dbvs2(data: Vec<Uuid>) -> Result<ValueSet, OperationError> {
355 let set = data.into_iter().collect();
356 Ok(Box::new(ValueSetReferN { set }))
357 }
358
359 pub fn from_repl_v1(data: &[Uuid]) -> Result<ValueSet, OperationError> {
360 let set = data.iter().copied().collect();
361 Ok(Box::new(ValueSetReferN { set }))
362 }
363
364 #[allow(clippy::should_implement_trait)]
367 pub fn from_iter<T>(iter: T) -> Option<Box<Self>>
368 where
369 T: IntoIterator<Item = Uuid>,
370 {
371 let set: BTreeSet<_> = iter.into_iter().collect();
372 if set.is_empty() {
373 None
374 } else {
375 Some(Box::new(ValueSetReferN { set }))
376 }
377 }
378
379 pub(crate) fn from_set(set: BTreeSet<Uuid>) -> ValueSet {
380 Box::new(ValueSetReferN { set })
381 }
382}
383
384impl ValueSetScimPut for ValueSetReferN {
385 fn from_scim_json_put(value: JsonValue) -> Result<ValueSetResolveStatus, OperationError> {
386 use kanidm_proto::scim_v1::client::{ScimReference, ScimReferences};
387
388 let value = if !value.is_array() && value.is_object() {
390 JsonValue::Array(vec![value])
391 } else {
392 value
393 };
394
395 let scim_refs: ScimReferences = serde_json::from_value(value).map_err(|err| {
396 warn!(?err, "Invalid SCIM reference set syntax");
397 OperationError::SC0002ReferenceSyntaxInvalid
398 })?;
399
400 let unresolved = scim_refs
401 .into_iter()
402 .map(|scim_ref| match scim_ref {
403 ScimReference {
404 uuid: None,
405 value: None,
406 } => {
407 warn!("Invalid SCIM reference set syntax, uuid and value are both unset.");
408 Err(OperationError::SC0002ReferenceSyntaxInvalid)
409 }
410 ScimReference {
411 uuid: Some(uuid),
412 value: Some(value),
413 } => Ok(UnresolvedReferenceState::Complete { uuid, value }),
414 ScimReference {
415 uuid: Some(uuid),
416 value: None,
417 } => Ok(UnresolvedReferenceState::Uuid(uuid)),
418 ScimReference {
419 uuid: None,
420 value: Some(value),
421 } => Ok(UnresolvedReferenceState::Value(value)),
422 })
423 .collect::<Result<Vec<_>, _>>()?;
424
425 Ok(ValueSetResolveStatus::NeedsResolution(
428 ValueSetIntermediate::References { unresolved },
429 ))
430 }
431}
432
433impl ValueSetT for ValueSetReferN {
434 fn migrate(&self) -> Result<Option<ValueSet>, OperationError> {
435 Ok(self
436 .to_refer_single()
437 .map(|uuid| Box::new(ValueSetRefer { uuid }) as ValueSet))
438 }
439
440 fn insert_checked(&mut self, value: Value) -> Result<bool, OperationError> {
441 match value {
442 Value::Refer(u) | Value::ReferN(u) => Ok(self.set.insert(u)),
443 _ => {
444 debug_assert!(false);
445 Err(OperationError::InvalidValueState)
446 }
447 }
448 }
449
450 fn clear(&mut self) {
451 self.set.clear();
452 }
453
454 fn remove(&mut self, pv: &PartialValue, _cid: &Cid) -> bool {
455 match pv {
456 PartialValue::Refer(u) => {
457 self.set.remove(u);
458 }
459 _ => {
460 debug_assert!(false);
461 }
462 };
463 self.set.is_empty()
464 }
465
466 fn contains(&self, pv: &PartialValue) -> bool {
467 match pv {
468 PartialValue::Refer(u) => self.set.contains(u),
469 _ => false,
470 }
471 }
472
473 fn substring(&self, _pv: &PartialValue) -> bool {
474 false
475 }
476
477 fn startswith(&self, _pv: &PartialValue) -> bool {
478 false
479 }
480
481 fn endswith(&self, _pv: &PartialValue) -> bool {
482 false
483 }
484
485 fn lessthan(&self, pv: &PartialValue) -> bool {
486 match pv {
487 PartialValue::Refer(u) => self.set.iter().any(|v| v < u),
488 _ => false,
489 }
490 }
491
492 fn len(&self) -> usize {
493 self.set.len()
494 }
495
496 fn generate_idx_eq_keys(&self) -> Vec<String> {
497 self.set
498 .iter()
499 .map(|u| u.as_hyphenated().to_string())
500 .collect()
501 }
502
503 fn syntax(&self) -> SyntaxType {
504 SyntaxType::ReferenceUuidN
505 }
506
507 fn validate(&self, _schema_attr: &SchemaAttribute) -> bool {
508 true
509 }
510
511 fn to_proto_string_clone_iter(&self) -> Box<dyn Iterator<Item = String> + '_> {
512 Box::new(self.set.iter().copied().map(uuid_to_proto_string))
513 }
514
515 fn to_scim_value(&self) -> Option<ScimResolveStatus> {
516 let uuids = self.set.iter().copied().collect::<Vec<_>>();
517 Some(ScimResolveStatus::NeedsResolution(
518 ScimValueIntermediate::References(uuids),
519 ))
520 }
521
522 fn to_db_valueset_v2(&self) -> DbValueSetV2 {
523 DbValueSetV2::Reference(self.set.iter().cloned().collect())
524 }
525
526 fn to_partialvalue_iter(&self) -> Box<dyn Iterator<Item = PartialValue> + '_> {
527 Box::new(self.set.iter().copied().map(PartialValue::Refer))
528 }
529
530 fn to_value_iter(&self) -> Box<dyn Iterator<Item = Value> + '_> {
531 Box::new(self.set.iter().copied().map(Value::ReferN))
532 }
533
534 fn equal(&self, other: &ValueSet) -> bool {
535 if let Some(other) = other.as_refer_set() {
536 &self.set == other
537 } else {
538 debug_assert!(false);
539 false
540 }
541 }
542
543 fn merge(&mut self, other: &ValueSet) -> Result<(), OperationError> {
544 if let Some(b) = other.as_refer_set() {
545 mergesets!(self.set, b)
546 } else if let Some(u) = other.to_refer_single() {
547 self.set.insert(u);
548 Ok(())
549 } else {
550 debug_assert!(false);
551 Err(OperationError::InvalidValueState)
552 }
553 }
554
555 fn to_refer_single(&self) -> Option<Uuid> {
556 if self.set.len() == 1 {
557 self.set.iter().copied().take(1).next()
558 } else {
559 None
560 }
561 }
562
563 fn as_refer_set(&self) -> Option<&BTreeSet<Uuid>> {
564 Some(&self.set)
565 }
566
567 fn as_refer_set_mut(&mut self) -> Option<&mut BTreeSet<Uuid>> {
568 Some(&mut self.set)
569 }
570
571 fn as_ref_uuid_iter(&self) -> Option<Box<dyn Iterator<Item = Uuid> + '_>> {
572 Some(Box::new(self.set.iter().copied()))
573 }
574}
575
576#[derive(Debug, Clone)]
577pub struct ValueSetRefer {
578 uuid: Uuid,
579}
580
581impl ValueSetRefer {
582 pub fn new(uuid: Uuid) -> Box<Self> {
583 Box::new(ValueSetRefer { uuid })
584 }
585
586 pub fn from_dbvs2(uuid: Uuid) -> Result<ValueSet, OperationError> {
587 Ok(Box::new(ValueSetRefer { uuid }))
588 }
589}
590
591impl ValueSetScimPut for ValueSetRefer {
592 fn from_scim_json_put(value: JsonValue) -> Result<ValueSetResolveStatus, OperationError> {
593 use kanidm_proto::scim_v1::client::ScimReference;
594
595 let scim_ref: ScimReference = serde_json::from_value(value).map_err(|err| {
596 warn!(?err, "Invalid SCIM reference set syntax");
597 OperationError::SC0002ReferenceSyntaxInvalid
598 })?;
599
600 match scim_ref {
601 ScimReference {
602 uuid: None,
603 value: None,
604 } => {
605 warn!("Invalid SCIM reference set syntax, uuid and value are both unset.");
606 Err(OperationError::SC0002ReferenceSyntaxInvalid)
607 }
608 ScimReference {
609 uuid: Some(uuid),
610 value: Some(value),
611 } => Ok(ValueSetResolveStatus::NeedsResolution(
612 ValueSetIntermediate::Reference(UnresolvedReferenceState::Complete { uuid, value }),
613 )),
614
615 ScimReference {
616 uuid: Some(uuid),
617 value: None,
618 } => Ok(ValueSetResolveStatus::NeedsResolution(
619 ValueSetIntermediate::Reference(UnresolvedReferenceState::Uuid(uuid)),
620 )),
621 ScimReference {
622 uuid: None,
623 value: Some(value),
624 } => Ok(ValueSetResolveStatus::NeedsResolution(
625 ValueSetIntermediate::Reference(UnresolvedReferenceState::Value(value)),
626 )),
627 }
628 }
629}
630
631impl ValueSetT for ValueSetRefer {
632 fn insert_checked(&mut self, value: Value) -> Result<bool, OperationError> {
633 match value {
634 Value::Refer(u) => {
635 if self.uuid != u {
636 self.uuid = u;
637 Ok(true)
638 } else {
639 Ok(false)
640 }
641 }
642 _ => {
643 debug_assert!(false);
644 Err(OperationError::InvalidValueState)
645 }
646 }
647 }
648
649 fn clear(&mut self) {
650 debug_assert!(false);
651 }
654
655 fn remove(&mut self, pv: &PartialValue, _cid: &Cid) -> bool {
656 match pv {
657 PartialValue::Refer(u) => *u == self.uuid,
659 _ => {
660 debug_assert!(false);
661 true
662 }
663 }
664 }
665
666 fn contains(&self, pv: &PartialValue) -> bool {
667 match pv {
668 PartialValue::Refer(u) => *u == self.uuid,
669 _ => false,
670 }
671 }
672
673 fn substring(&self, _pv: &PartialValue) -> bool {
674 false
675 }
676
677 fn startswith(&self, _pv: &PartialValue) -> bool {
678 false
679 }
680
681 fn endswith(&self, _pv: &PartialValue) -> bool {
682 false
683 }
684
685 fn lessthan(&self, pv: &PartialValue) -> bool {
686 match pv {
687 PartialValue::Refer(u) => self.uuid < *u,
688 _ => false,
689 }
690 }
691
692 fn len(&self) -> usize {
693 1
694 }
695
696 fn generate_idx_eq_keys(&self) -> Vec<String> {
697 std::iter::once(self.uuid.as_hyphenated().to_string()).collect()
698 }
699
700 fn syntax(&self) -> SyntaxType {
701 SyntaxType::ReferenceUuid
702 }
703
704 fn validate(&self, _schema_attr: &SchemaAttribute) -> bool {
705 true
706 }
707
708 fn to_proto_string_clone_iter(&self) -> Box<dyn Iterator<Item = String> + '_> {
709 Box::new(std::iter::once(self.uuid).map(uuid_to_proto_string))
710 }
711
712 fn to_scim_value(&self) -> Option<ScimResolveStatus> {
713 Some(ScimResolveStatus::NeedsResolution(
714 ScimValueIntermediate::Reference(self.uuid),
715 ))
716 }
717
718 fn to_db_valueset_v2(&self) -> DbValueSetV2 {
719 DbValueSetV2::ReferenceSingle(self.uuid)
720 }
721
722 fn to_partialvalue_iter(&self) -> Box<dyn Iterator<Item = PartialValue> + '_> {
723 Box::new(std::iter::once(self.uuid).map(PartialValue::Refer))
724 }
725
726 fn to_value_iter(&self) -> Box<dyn Iterator<Item = Value> + '_> {
727 Box::new(std::iter::once(self.uuid).map(Value::Refer))
728 }
729
730 fn equal(&self, other: &ValueSet) -> bool {
731 if let Some(other) = other.to_refer_single() {
732 self.uuid == other
733 } else {
734 debug_assert!(false);
735 false
736 }
737 }
738
739 fn merge(&mut self, other: &ValueSet) -> Result<(), OperationError> {
740 if let Some(other) = other.to_refer_single() {
741 self.uuid = other;
742 Ok(())
743 } else {
744 debug_assert!(false);
745 Err(OperationError::InvalidValueState)
746 }
747 }
748
749 fn to_refer_single(&self) -> Option<Uuid> {
750 Some(self.uuid)
751 }
752
753 fn as_ref_uuid_iter(&self) -> Option<Box<dyn Iterator<Item = Uuid> + '_>> {
754 Some(Box::new(std::iter::once(self.uuid)))
755 }
756}
757
758#[cfg(test)]
759mod tests {
760 use super::{ValueSetRefer, ValueSetReferN, ValueSetUuid, ValueSetUuidN};
761 use crate::prelude::*;
762
763 #[test]
764 fn test_scim_uuid_single() {
765 let vs: ValueSet = ValueSetUuid::new(uuid::uuid!("4d21d04a-dc0e-42eb-b850-34dd180b107f"));
766
767 let data = r#""4d21d04a-dc0e-42eb-b850-34dd180b107f""#;
768
769 crate::valueset::scim_json_reflexive(&vs, data);
770
771 crate::valueset::scim_json_put_reflexive::<ValueSetUuid>(&vs, &[])
772 }
773
774 #[test]
775 fn test_scim_uuid_multi() {
776 let vs: ValueSet = ValueSetUuidN::new(uuid::uuid!("4d21d04a-dc0e-42eb-b850-34dd180b107f"));
777
778 let data = r#"["4d21d04a-dc0e-42eb-b850-34dd180b107f"]"#;
779
780 crate::valueset::scim_json_reflexive(&vs, data);
781
782 crate::valueset::scim_json_put_reflexive::<ValueSetUuidN>(&vs, &[])
784 }
785
786 #[qs_test]
787 async fn test_scim_refer_multi(server: &QueryServer) {
788 let mut write_txn = server.write(duration_from_epoch_now()).await.unwrap();
789
790 let t_uuid = uuid::uuid!("4d21d04a-dc0e-42eb-b850-34dd180b107f");
791 assert!(write_txn
792 .internal_create(vec![entry_init!(
793 (Attribute::Class, EntryClass::Object.to_value()),
794 (Attribute::Class, EntryClass::Account.to_value()),
795 (Attribute::Class, EntryClass::Person.to_value()),
796 (Attribute::Name, Value::new_iname("testperson1")),
797 (Attribute::Uuid, Value::Uuid(t_uuid)),
798 (Attribute::Description, Value::new_utf8s("testperson1")),
799 (Attribute::DisplayName, Value::new_utf8s("testperson1"))
800 ),])
801 .is_ok());
802
803 let vs: ValueSet = ValueSetReferN::new(t_uuid);
804
805 let data = r#"[{"uuid": "4d21d04a-dc0e-42eb-b850-34dd180b107f", "value": "testperson1@example.com"}]"#;
806
807 crate::valueset::scim_json_reflexive_unresolved(&mut write_txn, &vs, data);
808
809 crate::valueset::scim_json_put_reflexive_unresolved::<ValueSetReferN>(
811 &mut write_txn,
812 &vs,
813 &[],
814 );
815
816 assert!(write_txn.commit().is_ok());
817 }
818
819 #[qs_test]
820 async fn test_scim_refer_single(server: &QueryServer) {
821 let mut write_txn = server.write(duration_from_epoch_now()).await.unwrap();
822
823 let t_uuid = uuid::uuid!("4d21d04a-dc0e-42eb-b850-34dd180b107f");
824 assert!(write_txn
825 .internal_create(vec![entry_init!(
826 (Attribute::Class, EntryClass::Object.to_value()),
827 (Attribute::Class, EntryClass::Account.to_value()),
828 (Attribute::Class, EntryClass::Person.to_value()),
829 (Attribute::Name, Value::new_iname("testperson1")),
830 (Attribute::Uuid, Value::Uuid(t_uuid)),
831 (Attribute::Description, Value::new_utf8s("testperson1")),
832 (Attribute::DisplayName, Value::new_utf8s("testperson1"))
833 ),])
834 .is_ok());
835
836 let vs: ValueSet = ValueSetRefer::new(t_uuid);
837
838 let data = r#"{"uuid": "4d21d04a-dc0e-42eb-b850-34dd180b107f", "value": "testperson1@example.com"}"#;
839
840 crate::valueset::scim_json_reflexive_unresolved(&mut write_txn, &vs, data);
841
842 crate::valueset::scim_json_put_reflexive_unresolved::<ValueSetRefer>(
844 &mut write_txn,
845 &vs,
846 &[],
847 );
848
849 assert!(write_txn.commit().is_ok());
850 }
851}