8
8
9
9
10
10
@pytest .mark .usefixtures ("resetSettings" )
11
- class TestUserContent :
11
+ class TestContentUser :
12
12
def testSigners (self , site ):
13
13
# File info for not existing user file
14
14
file_info = site .content_manager .getFileInfo ("data/users/notexist/data.json" )
@@ -66,6 +66,55 @@ def testRules(self, site):
66
66
rules = site .content_manager .getRules ("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json" , user_content )
67
67
assert "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C" not in rules ["signers" ]
68
68
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
+
69
118
def testVerify (self , site ):
70
119
privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT
71
120
user_inner_path = "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/content.json"
@@ -125,7 +174,7 @@ def testVerify(self, site):
125
174
del data_dict ["files_optional" ]["hello.exe" ] # Reset
126
175
127
176
# Includes not allowed in user content
128
- data_dict ["includes" ] = { "other.json" : { } }
177
+ data_dict ["includes" ] = {"other.json" : {} }
129
178
del data_dict ["signs" ] # Remove signs before signing
130
179
data_dict ["signs" ] = {
131
180
"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT" : CryptBitcoin .sign (json .dumps (data_dict , sort_keys = True ), privatekey )
@@ -135,7 +184,6 @@ def testVerify(self, site):
135
184
site .content_manager .verifyFile (user_inner_path , data , ignore_same = False )
136
185
assert "Includes not allowed" in err
137
186
138
-
139
187
def testCert (self , site ):
140
188
# user_addr = "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C"
141
189
user_priv = "5Kk7FSA63FC2ViKmKLuBxk9gQkaQ5713hKq8LmFAf4cVeXh6K6A"
0 commit comments