scim-server 0.4.0

A comprehensive SCIM 2.0 server library for Rust with multi-tenant support and type-safe operations
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
//! Resource model and provider trait for SCIM resources.
//!
//! This module defines the core resource abstractions that users implement
//! to provide data access for SCIM operations. The design emphasizes
//! type safety and async patterns while keeping the interface simple.
//!
//! # Module Organization
//!
//! * [`core`] - Core types like `Resource`, `RequestContext`, `ScimOperation`, and `ListQuery`
//! * [`types`] - Domain-specific data structures like `EmailAddress`
//! * [`mapper`] - Schema mapping functionality for converting between formats
//! * [`handlers`] - Dynamic handler infrastructure for runtime resource operations
//! * [`provider`] - The main `ResourceProvider` trait for data access

pub mod builder;
pub mod conditional_provider;
pub mod context;
pub mod core;
pub mod handlers;
pub mod mapper;
pub mod provider;
pub mod resource;
pub mod serialization;
pub mod tenant;
pub mod types;
pub mod value_objects;
pub mod version;

// Re-export all public types to maintain API compatibility
pub use builder::ResourceBuilder;
pub use context::{ListQuery, RequestContext};
pub use resource::Resource;
pub use tenant::{IsolationLevel, TenantContext, TenantPermissions};
// Re-export ScimOperation from multi_tenant module for backward compatibility
pub use crate::multi_tenant::ScimOperation;
pub use handlers::{AttributeHandler, DynamicResource, ResourceHandler, SchemaResourceBuilder};
pub use mapper::{DatabaseMapper, SchemaMapper};
pub use provider::{ResourceProvider, ResourceProviderExt};
pub use types::EmailAddress;
pub use value_objects::{
    Address, EmailAddress as EmailAddressValue, ExternalId, Meta, Name, PhoneNumber, ResourceId,
    SchemaUri, UserName,
};

#[cfg(test)]
mod tests {
    use super::*;
    use serde_json::json;

    #[test]
    fn test_resource_creation() {
        let data = json!({
            "userName": "testuser",
            "displayName": "Test User"
        });
        let resource = Resource::from_json("User".to_string(), data).unwrap();

        assert_eq!(resource.resource_type, "User");
        assert_eq!(resource.get_username(), Some("testuser"));
    }

    #[test]
    fn test_resource_id_extraction() {
        let data = json!({
            "id": "12345",
            "userName": "testuser"
        });
        let resource = Resource::from_json("User".to_string(), data).unwrap();

        assert_eq!(resource.get_id(), Some("12345"));
    }

    #[test]
    fn test_resource_schemas() {
        let data = json!({
            "userName": "testuser"
        });
        let resource = Resource::from_json("User".to_string(), data).unwrap();

        let schemas = resource.get_schemas();
        assert_eq!(schemas.len(), 1);
        assert_eq!(schemas[0], "urn:ietf:params:scim:schemas:core:2.0:User");
    }

    #[test]
    fn test_email_extraction() {
        let data = json!({
            "userName": "testuser",
            "emails": [
                {
                    "value": "test@example.com",
                    "type": "work",
                    "primary": true
                }
            ]
        });
        let resource = Resource::from_json("User".to_string(), data).unwrap();

        let emails = resource.get_emails().expect("Should have emails");
        assert_eq!(emails.len(), 1);
        let email = emails.get(0).expect("Should have first email");
        assert_eq!(email.value(), "test@example.com");
    }

    #[test]
    fn test_request_context_creation() {
        let context = RequestContext::new("test-request".to_string());
        assert!(!context.request_id.is_empty());

        let context_with_id = RequestContext::new("test-123".to_string());
        assert_eq!(context_with_id.request_id, "test-123");
    }

    #[test]
    fn test_resource_active_status() {
        let active_data = json!({
            "userName": "testuser",
            "active": true
        });
        let active_resource = Resource::from_json("User".to_string(), active_data).unwrap();
        assert!(active_resource.is_active());

        let inactive_data = json!({
            "userName": "testuser",
            "active": false
        });
        let inactive_resource = Resource::from_json("User".to_string(), inactive_data).unwrap();
        assert!(!inactive_resource.is_active());

        let no_active_data = json!({
            "userName": "testuser"
        });
        let default_resource = Resource::from_json("User".to_string(), no_active_data).unwrap();
        assert!(default_resource.is_active()); // Default to true
    }

    #[test]
    fn test_meta_extraction_from_json() {
        use chrono::{TimeZone, Utc};

        // Test resource with valid meta
        let data_with_meta = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "id": "12345",
            "userName": "testuser",
            "meta": {
                "resourceType": "User",
                "created": "2023-01-01T12:00:00Z",
                "lastModified": "2023-01-02T12:00:00Z",
                "location": "https://example.com/Users/12345",
                "version": "W/\"12345-1672574400000\""
            }
        });

        let resource = Resource::from_json("User".to_string(), data_with_meta).unwrap();
        let meta = resource.get_meta().unwrap();

        assert_eq!(meta.resource_type(), "User");
        assert_eq!(
            meta.created(),
            Utc.with_ymd_and_hms(2023, 1, 1, 12, 0, 0).unwrap()
        );
        assert_eq!(
            meta.last_modified(),
            Utc.with_ymd_and_hms(2023, 1, 2, 12, 0, 0).unwrap()
        );
        assert_eq!(meta.location(), Some("https://example.com/Users/12345"));
        assert_eq!(meta.version(), Some("W/\"12345-1672574400000\""));
    }

    #[test]
    fn test_meta_extraction_minimal() {
        // Test resource with minimal meta
        let data_minimal_meta = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "meta": {
                "resourceType": "User",
                "created": "2023-01-01T12:00:00Z",
                "lastModified": "2023-01-01T12:00:00Z"
            }
        });

        let resource = Resource::from_json("User".to_string(), data_minimal_meta).unwrap();
        let meta = resource.get_meta().unwrap();

        assert_eq!(meta.resource_type(), "User");
        assert_eq!(meta.location(), None);
        assert_eq!(meta.version(), None);
    }

    #[test]
    fn test_meta_extraction_invalid_datetime_returns_error() {
        // Test resource with invalid datetime format returns validation error
        let data_invalid_meta = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "meta": {
                "resourceType": "User",
                "created": "invalid-date",
                "lastModified": "2023-01-01T12:00:00Z"
            }
        });

        let result = Resource::from_json("User".to_string(), data_invalid_meta);
        assert!(result.is_err());
        match result.unwrap_err() {
            crate::error::ValidationError::InvalidCreatedDateTime => {
                // Expected error
            }
            other => panic!("Expected InvalidCreatedDateTime, got {:?}", other),
        }
    }

    #[test]
    fn test_meta_extraction_incomplete_is_ignored() {
        // Test resource with incomplete meta is ignored (for backward compatibility)
        let data_incomplete_meta = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "meta": {
                "resourceType": "User"
                // Missing created and lastModified
            }
        });

        let resource = Resource::from_json("User".to_string(), data_incomplete_meta).unwrap();
        assert!(resource.get_meta().is_none());
    }

    #[test]
    fn test_meta_extraction_missing() {
        // Test resource without meta
        let data_no_meta = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser"
        });

        let resource = Resource::from_json("User".to_string(), data_no_meta).unwrap();
        assert!(resource.get_meta().is_none());
    }

    #[test]
    fn test_set_meta() {
        use crate::resource::value_objects::Meta;
        use chrono::Utc;

        let mut resource = Resource::from_json(
            "User".to_string(),
            json!({
                "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
                "userName": "testuser"
            }),
        )
        .unwrap();

        let now = Utc::now();
        let meta = Meta::new_simple("User".to_string(), now, now).unwrap();
        resource.set_meta(meta.clone());

        assert!(resource.get_meta().is_some());
        assert_eq!(resource.get_meta().unwrap().resource_type(), "User");

        // Test that meta is also in JSON representation
        let json_output = resource.to_json().unwrap();
        assert!(json_output.get("meta").is_some());
    }

    #[test]
    fn test_create_meta() {
        let mut resource = Resource::from_json(
            "User".to_string(),
            json!({
                "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
                "id": "12345",
                "userName": "testuser"
            }),
        )
        .unwrap();

        resource.create_meta("https://example.com").unwrap();

        let meta = resource.get_meta().unwrap();
        assert_eq!(meta.resource_type(), "User");
        assert_eq!(meta.created(), meta.last_modified());
        assert_eq!(meta.location(), Some("https://example.com/Users/12345"));
    }

    #[test]
    fn test_update_meta() {
        use crate::resource::value_objects::Meta;
        use chrono::Utc;
        use std::thread;
        use std::time::Duration;

        let mut resource = Resource::from_json(
            "User".to_string(),
            json!({
                "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
                "userName": "testuser"
            }),
        )
        .unwrap();

        let now = Utc::now();
        let meta = Meta::new_simple("User".to_string(), now, now).unwrap();
        resource.set_meta(meta);

        let original_modified = resource.get_meta().unwrap().last_modified();

        // Wait a bit to ensure timestamp difference
        thread::sleep(Duration::from_millis(10));

        resource.update_meta();

        let updated_modified = resource.get_meta().unwrap().last_modified();
        assert!(updated_modified > original_modified);
        assert_eq!(resource.get_meta().unwrap().created(), now);
    }

    #[test]
    fn test_add_metadata_legacy_compatibility() {
        let mut resource = Resource::from_json(
            "User".to_string(),
            json!({
                "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
                "id": "12345",
                "userName": "testuser"
            }),
        )
        .unwrap();

        resource.add_metadata(
            "https://example.com",
            "2023-01-01T12:00:00Z",
            "2023-01-02T12:00:00Z",
        );

        // Should create Meta value object
        let meta = resource.get_meta().unwrap();
        assert_eq!(meta.resource_type(), "User");
        assert_eq!(meta.location(), Some("https://example.com/Users/12345"));

        // Should also be in JSON attributes for backward compatibility
        let json_output = resource.to_json().unwrap();
        assert!(json_output.get("meta").is_some());
    }

    #[test]
    fn test_meta_serialization_in_to_json() {
        use crate::resource::value_objects::Meta;
        use chrono::{TimeZone, Utc};

        let mut resource = Resource::from_json(
            "User".to_string(),
            json!({
                "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
                "userName": "testuser"
            }),
        )
        .unwrap();

        let created = Utc.with_ymd_and_hms(2023, 1, 1, 12, 0, 0).unwrap();
        let modified = Utc.with_ymd_and_hms(2023, 1, 2, 12, 0, 0).unwrap();
        let meta = Meta::new(
            "User".to_string(),
            created,
            modified,
            Some("https://example.com/Users/123".to_string()),
            Some("W/\"123-456\"".to_string()),
        )
        .unwrap();

        resource.set_meta(meta);

        let json_output = resource.to_json().unwrap();
        let meta_json = json_output.get("meta").unwrap();

        assert_eq!(
            meta_json.get("resourceType").unwrap().as_str().unwrap(),
            "User"
        );
        assert!(
            meta_json
                .get("created")
                .unwrap()
                .as_str()
                .unwrap()
                .starts_with("2023-01-01T12:00:00")
        );
        assert!(
            meta_json
                .get("lastModified")
                .unwrap()
                .as_str()
                .unwrap()
                .starts_with("2023-01-02T12:00:00")
        );
        assert_eq!(
            meta_json.get("location").unwrap().as_str().unwrap(),
            "https://example.com/Users/123"
        );
        assert_eq!(
            meta_json.get("version").unwrap().as_str().unwrap(),
            "W/\"123-456\""
        );
    }

    #[test]
    fn test_resource_with_name_extraction() {
        let data = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "name": {
                "formatted": "John Doe",
                "familyName": "Doe",
                "givenName": "John"
            }
        });

        let resource = Resource::from_json("User".to_string(), data).unwrap();

        assert!(resource.get_name().is_some());
        let name = resource.get_name().unwrap();
        assert_eq!(name.formatted(), Some("John Doe"));
        assert_eq!(name.family_name(), Some("Doe"));
        assert_eq!(name.given_name(), Some("John"));
    }

    #[test]
    fn test_resource_with_addresses_extraction() {
        let data = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "addresses": [
                {
                    "type": "work",
                    "streetAddress": "123 Main St",
                    "locality": "Anytown",
                    "region": "CA",
                    "postalCode": "12345",
                    "country": "US",
                    "primary": true
                }
            ]
        });

        let resource = Resource::from_json("User".to_string(), data).unwrap();

        let addresses = resource.get_addresses().expect("Should have addresses");
        assert_eq!(addresses.len(), 1);
        let address = addresses.get(0).expect("Should have first address");
        assert_eq!(address.address_type(), Some("work"));
        assert_eq!(address.street_address(), Some("123 Main St"));
        assert_eq!(address.locality(), Some("Anytown"));
        assert_eq!(address.region(), Some("CA"));
        assert_eq!(address.postal_code(), Some("12345"));
        assert_eq!(address.country(), Some("US"));
        assert_eq!(address.is_primary(), true);
    }

    #[test]
    fn test_resource_with_phone_numbers_extraction() {
        let data = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "phoneNumbers": [
                {
                    "value": "tel:+1-555-555-5555",
                    "type": "work",
                    "primary": true
                }
            ]
        });

        let resource = Resource::from_json("User".to_string(), data).unwrap();

        let phones = resource
            .get_phone_numbers()
            .expect("Should have phone numbers");
        assert_eq!(phones.len(), 1);
        let phone = phones.get(0).expect("Should have first phone");
        assert_eq!(phone.value(), "tel:+1-555-555-5555");
        assert_eq!(phone.phone_type(), Some("work"));
        assert_eq!(phone.is_primary(), true);
    }

    #[test]
    fn test_resource_builder_basic() {
        use crate::resource::value_objects::{ResourceId, UserName};

        let resource = ResourceBuilder::new("User".to_string())
            .with_id(ResourceId::new("123".to_string()).unwrap())
            .with_username(UserName::new("jdoe".to_string()).unwrap())
            .with_attribute("displayName", json!("John Doe"))
            .build()
            .unwrap();

        assert_eq!(resource.resource_type, "User");
        assert_eq!(resource.get_id(), Some("123"));
        assert_eq!(resource.get_username(), Some("jdoe"));
        assert_eq!(
            resource.get_attribute("displayName"),
            Some(&json!("John Doe"))
        );
        assert_eq!(resource.schemas.len(), 1);
        assert_eq!(
            resource.schemas[0].as_str(),
            "urn:ietf:params:scim:schemas:core:2.0:User"
        );
    }

    #[test]
    fn test_resource_builder_with_complex_attributes() {
        use crate::resource::value_objects::{Address, Name, PhoneNumber};

        let name = Name::new_simple("John".to_string(), "Doe".to_string()).unwrap();
        let address = Address::new_work(
            "123 Main St".to_string(),
            "Anytown".to_string(),
            "CA".to_string(),
            "12345".to_string(),
            "US".to_string(),
        )
        .unwrap();
        let phone = PhoneNumber::new_work("tel:+1-555-555-5555".to_string()).unwrap();

        let resource = ResourceBuilder::new("User".to_string())
            .with_name(name)
            .add_address(address)
            .add_phone_number(phone)
            .build()
            .unwrap();

        assert!(resource.get_name().is_some());
        assert_eq!(resource.get_addresses().unwrap().len(), 1);
        assert_eq!(resource.get_phone_numbers().unwrap().len(), 1);

        // Test serialization includes all fields
        let json_output = resource.to_json().unwrap();
        assert!(json_output.get("name").is_some());
        assert!(json_output.get("addresses").is_some());
        assert!(json_output.get("phoneNumbers").is_some());
    }

    #[test]
    fn test_resource_builder_with_meta() {
        use crate::resource::value_objects::ResourceId;

        let resource = ResourceBuilder::new("User".to_string())
            .with_id(ResourceId::new("123".to_string()).unwrap())
            .build_with_meta("https://example.com")
            .unwrap();

        assert!(resource.get_meta().is_some());
        let meta = resource.get_meta().unwrap();
        assert_eq!(meta.resource_type(), "User");
        assert_eq!(meta.location(), Some("https://example.com/Users/123"));
    }

    #[test]
    fn test_resource_builder_validation() {
        // Test that builder validates required fields
        let builder = ResourceBuilder::new("User".to_string());
        // Remove default schema to test validation
        let builder_no_schema = builder.with_schemas(vec![]);
        let result = builder_no_schema.build();
        assert!(result.is_err());
    }

    #[test]
    fn test_resource_setter_methods() {
        use crate::resource::value_objects::{Address, Name, PhoneNumber};

        let mut resource = Resource::from_json(
            "User".to_string(),
            json!({
                "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
                "userName": "testuser"
            }),
        )
        .unwrap();

        // Test name setter
        let name = Name::new_simple("Jane".to_string(), "Smith".to_string()).unwrap();
        resource.set_name(name);
        assert!(resource.get_name().is_some());
        assert_eq!(resource.get_name().unwrap().given_name(), Some("Jane"));

        // Test address setter
        let address = Address::new(
            None,
            Some("456 Oak Ave".to_string()),
            Some("Hometown".to_string()),
            Some("NY".to_string()),
            Some("67890".to_string()),
            Some("US".to_string()),
            Some("home".to_string()),
            Some(false),
        )
        .unwrap();
        resource.add_address(address).unwrap();
        let addresses = resource.get_addresses().expect("Should have addresses");
        assert_eq!(addresses.len(), 1);
        let address = addresses.get(0).expect("Should have first address");
        assert_eq!(address.address_type(), Some("home"));

        // Test phone number setter
        let phone = PhoneNumber::new_mobile("tel:+1-555-123-4567".to_string()).unwrap();
        resource.add_phone_number(phone).unwrap();
        let phones = resource
            .get_phone_numbers()
            .expect("Should have phone numbers");
        assert_eq!(phones.len(), 1);
        let phone = phones.get(0).expect("Should have first phone");
        assert_eq!(phone.phone_type(), Some("mobile"));
    }

    #[test]
    fn test_resource_json_round_trip_with_complex_attributes() {
        let data = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "id": "123",
            "userName": "jdoe",
            "name": {
                "formatted": "John Doe",
                "familyName": "Doe",
                "givenName": "John"
            },
            "addresses": [
                {
                    "type": "work",
                    "streetAddress": "123 Main St",
                    "locality": "Anytown",
                    "region": "CA",
                    "postalCode": "12345",
                    "country": "US",
                    "primary": true
                }
            ],
            "phoneNumbers": [
                {
                    "value": "tel:+1-555-555-5555",
                    "type": "work",
                    "primary": true
                }
            ]
        });

        let resource = Resource::from_json("User".to_string(), data).unwrap();
        let json_output = resource.to_json().unwrap();

        // Verify all complex attributes are preserved
        assert!(json_output.get("name").is_some());
        assert!(json_output.get("addresses").is_some());
        assert!(json_output.get("phoneNumbers").is_some());

        // Verify the structured data is correct
        let name_json = json_output.get("name").unwrap();
        assert_eq!(
            name_json.get("formatted").unwrap().as_str().unwrap(),
            "John Doe"
        );

        let addresses_json = json_output.get("addresses").unwrap().as_array().unwrap();
        assert_eq!(addresses_json.len(), 1);
        assert_eq!(
            addresses_json[0].get("type").unwrap().as_str().unwrap(),
            "work"
        );

        let phones_json = json_output.get("phoneNumbers").unwrap().as_array().unwrap();
        assert_eq!(phones_json.len(), 1);
        assert_eq!(
            phones_json[0].get("value").unwrap().as_str().unwrap(),
            "tel:+1-555-555-5555"
        );
    }

    #[test]
    fn test_resource_invalid_complex_attributes() {
        // Test invalid name structure
        let invalid_name_data = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "name": "should be object not string"
        });
        let result = Resource::from_json("User".to_string(), invalid_name_data);
        assert!(result.is_err());

        // Test invalid addresses structure
        let invalid_addresses_data = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "addresses": "should be array not string"
        });
        let result = Resource::from_json("User".to_string(), invalid_addresses_data);
        assert!(result.is_err());

        // Test invalid phone numbers structure
        let invalid_phones_data = json!({
            "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
            "userName": "testuser",
            "phoneNumbers": "should be array not string"
        });
        let result = Resource::from_json("User".to_string(), invalid_phones_data);
        assert!(result.is_err());
    }
}