@@ -457,8 +457,12 @@ void main() {
457
457
// Mock the rootBundle to return valid JSON
458
458
const validJson = '''
459
459
{
460
- "admin": ["read", "write", "delete"],
461
- "user": ["read"]
460
+ "admin": {
461
+ "allowedContent": ["read", "write", "delete"]
462
+ },
463
+ "user": {
464
+ "allowedContent": ["read"]
465
+ }
462
466
}
463
467
''' ;
464
468
@@ -471,6 +475,7 @@ void main() {
471
475
await policyManager
472
476
.initializeFromJsonAssets ('assets/policies/test.json' );
473
477
478
+ // The method should initialize successfully with valid JSON
474
479
expect (policyManager.isInitialized, isTrue);
475
480
expect (policyManager.roles.length, equals (2 ));
476
481
expect (policyManager.roles['admin' ], isA <Role >());
@@ -528,9 +533,16 @@ void main() {
528
533
// Mock the rootBundle to return JSON with malformed policy data
529
534
const malformedJson = '''
530
535
{
531
- "admin": "not_a_list",
536
+ "admin": {
537
+ "allowedContent": "not_a_list"
538
+ },
532
539
"user": null,
533
- "guest": ["read"]
540
+ "guest": {
541
+ "allowedContent": ["read"]
542
+ },
543
+ "invalid_role": {
544
+ "allowedContent": [123, "read"]
545
+ }
534
546
}
535
547
''' ;
536
548
@@ -547,8 +559,11 @@ void main() {
547
559
expect (policyManager.isInitialized, isTrue);
548
560
expect (policyManager.roles.length, equals (1 ));
549
561
expect (policyManager.roles['guest' ], isNotNull);
562
+ expect (policyManager.roles['guest' ]! .name, equals ('guest' ));
563
+ expect (policyManager.roles['guest' ]! .allowedContent, contains ('read' ));
550
564
expect (policyManager.roles['admin' ], isNull);
551
565
expect (policyManager.roles['user' ], isNull);
566
+ expect (policyManager.roles['invalid_role' ], isNull);
552
567
553
568
// Clean up mock message handler
554
569
TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger
@@ -580,7 +595,9 @@ void main() {
580
595
// Mock the rootBundle to return JSON with single policy
581
596
const singlePolicyJson = '''
582
597
{
583
- "admin": ["read", "write"]
598
+ "admin": {
599
+ "allowedContent": ["read", "write"]
600
+ }
584
601
}
585
602
''' ;
586
603
@@ -608,7 +625,9 @@ void main() {
608
625
// Create a large JSON with many policies
609
626
final largeJson = < String , dynamic > {};
610
627
for (int i = 0 ; i < 100 ; i++ ) {
611
- largeJson['role_$i ' ] = ['read' , 'write' ];
628
+ largeJson['role_$i ' ] = {
629
+ 'allowedContent' : ['read' , 'write' ]
630
+ };
612
631
}
613
632
614
633
TestDefaultBinaryMessengerBinding .instance.defaultBinaryMessenger
@@ -632,8 +651,12 @@ void main() {
632
651
// Mock the rootBundle to return JSON with empty content arrays
633
652
const emptyContentJson = '''
634
653
{
635
- "admin": [],
636
- "user": ["read"]
654
+ "admin": {
655
+ "allowedContent": []
656
+ },
657
+ "user": {
658
+ "allowedContent": ["read"]
659
+ }
637
660
}
638
661
''' ;
639
662
@@ -661,7 +684,9 @@ void main() {
661
684
// Mock the rootBundle to return JSON with duplicate content
662
685
const duplicateContentJson = '''
663
686
{
664
- "admin": ["read", "read", "write", "write"]
687
+ "admin": {
688
+ "allowedContent": ["read", "read", "write", "write"]
689
+ }
665
690
}
666
691
''' ;
667
692
@@ -698,8 +723,12 @@ void main() {
698
723
// Mock the rootBundle to return valid JSON
699
724
const validJson = '''
700
725
{
701
- "admin": ["read", "write"],
702
- "user": ["read"]
726
+ "admin": {
727
+ "allowedContent": ["read", "write"]
728
+ },
729
+ "user": {
730
+ "allowedContent": ["read"]
731
+ }
703
732
}
704
733
''' ;
705
734
@@ -732,7 +761,9 @@ void main() {
732
761
// Mock the rootBundle to return valid JSON
733
762
const validJson = '''
734
763
{
735
- "admin": ["read", "write"]
764
+ "admin": {
765
+ "allowedContent": ["read", "write"]
766
+ }
736
767
}
737
768
''' ;
738
769
@@ -772,7 +803,9 @@ void main() {
772
803
// Mock the rootBundle to return valid JSON
773
804
const validJson = '''
774
805
{
775
- "admin": ["read", "write"]
806
+ "admin": {
807
+ "allowedContent": ["read", "write"]
808
+ }
776
809
}
777
810
''' ;
778
811
@@ -786,6 +819,7 @@ void main() {
786
819
.initializeFromJsonAssets ('assets/policies/test.json' );
787
820
788
821
// Check that the expected policy is present in storage
822
+ expect (freshPolicyManager.isInitialized, isTrue);
789
823
expect (freshStorage.storedPolicies['admin' ], isA <Role >());
790
824
expect (
791
825
(freshStorage.storedPolicies['admin' ] as Role ).allowedContent,
@@ -805,7 +839,9 @@ void main() {
805
839
// Mock the rootBundle to return valid JSON
806
840
const validJson = '''
807
841
{
808
- "admin": ["read", "write"]
842
+ "admin": {
843
+ "allowedContent": ["read", "write"]
844
+ }
809
845
}
810
846
''' ;
811
847
0 commit comments