88
99
1010@pytest .mark .usefixtures ("resetSettings" )
11- class TestUserContent :
11+ class TestContentUser :
1212 def testSigners (self , site ):
1313 # File info for not existing user file
1414 file_info = site .content_manager .getFileInfo ("data/users/notexist/data.json" )
@@ -66,6 +66,55 @@ def testRules(self, site):
6666 rules = site .content_manager .getRules ("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json" , user_content )
6767 assert "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C" not in rules ["signers" ]
6868
69+ def testRulesAddress (self , site ):
70+ user_inner_path = "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json"
71+ user_content = site .storage .loadJson (user_inner_path )
72+
73+ rules = site .content_manager .getRules (user_inner_path , user_content )
74+ assert rules ["max_size" ] == 10000
75+ assert "1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9" in rules ["signers" ]
76+
77+ users_content = site .content_manager .contents ["data/users/content.json" ]
78+
79+ # Ban user based on address
80+ users_content ["user_contents" ]["permissions" ]["1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9" ] = False
81+ rules = site .content_manager .getRules (user_inner_path , user_content )
82+ assert "1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9" not in rules ["signers" ]
83+
84+ # Change max allowed size
85+ users_content ["user_contents" ]["permissions" ]["1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9" ] = {"max_size" : 20000 }
86+ rules = site .content_manager .getRules (user_inner_path , user_content )
87+ assert rules ["max_size" ] == 20000
88+
89+ def testVerifyAddress (self , site ):
90+ privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT
91+ user_inner_path = "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json"
92+ data_dict = site .storage .loadJson (user_inner_path )
93+ users_content = site .content_manager .contents ["data/users/content.json" ]
94+
95+ data = StringIO (json .dumps (data_dict ))
96+ assert site .content_manager .verifyFile (user_inner_path , data , ignore_same = False )
97+
98+ # Test error on 15k data.json
99+ data_dict ["files" ]["data.json" ]["size" ] = 1024 * 15
100+ del data_dict ["signs" ] # Remove signs before signing
101+ data_dict ["signs" ] = {
102+ "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT" : CryptBitcoin .sign (json .dumps (data_dict , sort_keys = True ), privatekey )
103+ }
104+ data = StringIO (json .dumps (data_dict ))
105+ with pytest .raises (VerifyError ) as err :
106+ site .content_manager .verifyFile (user_inner_path , data , ignore_same = False )
107+ assert "Content too large" in str (err )
108+
109+ # Give more space based on address
110+ users_content ["user_contents" ]["permissions" ]["1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9" ] = {"max_size" : 20000 }
111+ del data_dict ["signs" ] # Remove signs before signing
112+ data_dict ["signs" ] = {
113+ "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT" : CryptBitcoin .sign (json .dumps (data_dict , sort_keys = True ), privatekey )
114+ }
115+ data = StringIO (json .dumps (data_dict ))
116+ assert site .content_manager .verifyFile (user_inner_path , data , ignore_same = False )
117+
69118 def testVerify (self , site ):
70119 privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT
71120 user_inner_path = "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json"
@@ -125,7 +174,7 @@ def testVerify(self, site):
125174 del data_dict ["files_optional" ]["hello.exe" ] # Reset
126175
127176 # Includes not allowed in user content
128- data_dict ["includes" ] = { "other.json" : { } }
177+ data_dict ["includes" ] = {"other.json" : {} }
129178 del data_dict ["signs" ] # Remove signs before signing
130179 data_dict ["signs" ] = {
131180 "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT" : CryptBitcoin .sign (json .dumps (data_dict , sort_keys = True ), privatekey )
@@ -135,7 +184,6 @@ def testVerify(self, site):
135184 site .content_manager .verifyFile (user_inner_path , data , ignore_same = False )
136185 assert "Includes not allowed" in err
137186
138-
139187 def testCert (self , site ):
140188 # user_addr = "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C"
141189 user_priv = "5Kk7FSA63FC2ViKmKLuBxk9gQkaQ5713hKq8LmFAf4cVeXh6K6A"
0 commit comments