@@ -754,3 +754,161 @@ def test_permissions_config_options():
754
754
assert len (opts ) == 2
755
755
assert "mode" in opts
756
756
assert "friendship" in opts
757
+
758
+
759
+ @pytest .mark .parametrize (
760
+ "json_str,ok" ,
761
+ [
762
+ pytest .param ("{}" , False , id = "empty-json" ),
763
+ pytest .param ('{"samba-container-config":"v0"}' , True , id = "minimal" ),
764
+ pytest .param (
765
+ """
766
+ {
767
+ "samba-container-config": "v0",
768
+ "configs": {
769
+ "foobar": {
770
+ "shares": [
771
+ "foobar"
772
+ ]
773
+ }
774
+ },
775
+ "shares": {
776
+ "foobar": {
777
+ "options": {
778
+ "a": "b"
779
+ }
780
+ }
781
+ }
782
+ }
783
+ """ ,
784
+ True ,
785
+ id = "one-share" ,
786
+ ),
787
+ pytest .param (
788
+ """
789
+ {
790
+ "samba-container-config": "v0",
791
+ "configs": {
792
+ "foobar": {
793
+ "shares": [
794
+ "foobar"
795
+ ]
796
+ }
797
+ },
798
+ "shares": {
799
+ "foobar": {
800
+ "options": {
801
+ "a": "b"
802
+ }
803
+ }
804
+ },
805
+ "chairs": {"maple": true}
806
+ }
807
+ """ ,
808
+ False ,
809
+ id = "invalid-section" ,
810
+ ),
811
+ pytest .param (
812
+ """
813
+ {
814
+ "samba-container-config": "v0",
815
+ "configs": {
816
+ "foobar": {
817
+ "shares": [
818
+ "foobar"
819
+ ]
820
+ }
821
+ },
822
+ "shares": {
823
+ "foobar": {
824
+ "options": {
825
+ "a": "b"
826
+ }
827
+ }
828
+ },
829
+ "_chairs": {"maple": true}
830
+ }
831
+ """ ,
832
+ True ,
833
+ id = "underscore-prefix" ,
834
+ ),
835
+ pytest .param (
836
+ """
837
+ {
838
+ "samba-container-config": "v0",
839
+ "configs": {
840
+ "foobar": {
841
+ "lazlo": "quux",
842
+ "shares": [
843
+ "foobar"
844
+ ]
845
+ }
846
+ },
847
+ "shares": {
848
+ "foobar": {
849
+ "options": {
850
+ "a": "b"
851
+ }
852
+ }
853
+ }
854
+ }
855
+ """ ,
856
+ False ,
857
+ id = "bad-config-param" ,
858
+ ),
859
+ pytest .param (
860
+ """
861
+ {
862
+ "samba-container-config": "v0",
863
+ "configs": {
864
+ "foobar": {
865
+ "shares": "foobar"
866
+ }
867
+ },
868
+ "shares": {
869
+ "foobar": {
870
+ "options": {
871
+ "a": "b"
872
+ }
873
+ }
874
+ }
875
+ }
876
+ """ ,
877
+ False ,
878
+ id = "bad-config-type" ,
879
+ ),
880
+ pytest .param (
881
+ """
882
+ {
883
+ "samba-container-config": "v0",
884
+ "configs": {
885
+ "foobar": {
886
+ "shares": [
887
+ "foobar"
888
+ ]
889
+ }
890
+ },
891
+ "shares": {
892
+ "foobar": {
893
+ "blooper": true,
894
+ "options": {
895
+ "a": "b"
896
+ }
897
+ }
898
+ }
899
+ }
900
+ """ ,
901
+ False ,
902
+ id = "bad-share-prop" ,
903
+ ),
904
+ ],
905
+ )
906
+ def test_jsonschema_validation (json_str , ok ):
907
+ jsonschema = pytest .importorskip ("jsonschema" )
908
+
909
+ cfg = sambacc .config .GlobalConfig ()
910
+ if ok :
911
+ cfg .load (io .StringIO (json_str ), require_validation = True )
912
+ else :
913
+ with pytest .raises ((ValueError , jsonschema .ValidationError )):
914
+ cfg .load (io .StringIO (json_str ), require_validation = True )
0 commit comments