Allow the site owner to modify banned users file
This commit is contained in:
parent
f241a9aef3
commit
cd2aa033b4
3 changed files with 41 additions and 7 deletions
|
@ -249,7 +249,7 @@ class ContentManager(object):
|
||||||
try:
|
try:
|
||||||
if not content:
|
if not content:
|
||||||
content = self.site.storage.loadJson(inner_path) # Read the file if no content specified
|
content = self.site.storage.loadJson(inner_path) # Read the file if no content specified
|
||||||
except (Exception, ): # Content.json not exist
|
except Exception: # Content.json not exist
|
||||||
return {"signers": [user_address], "user_address": user_address} # Return information that we know for sure
|
return {"signers": [user_address], "user_address": user_address} # Return information that we know for sure
|
||||||
|
|
||||||
"""if not "cert_user_name" in content: # New file, unknown user
|
"""if not "cert_user_name" in content: # New file, unknown user
|
||||||
|
@ -260,7 +260,10 @@ class ContentManager(object):
|
||||||
|
|
||||||
rules = copy.copy(user_contents["permissions"].get(content["cert_user_id"], {})) # Default rules by username
|
rules = copy.copy(user_contents["permissions"].get(content["cert_user_id"], {})) # Default rules by username
|
||||||
if rules is False:
|
if rules is False:
|
||||||
return False # User banned
|
banned = True
|
||||||
|
rules = {}
|
||||||
|
else:
|
||||||
|
banned = False
|
||||||
if "signers" in rules:
|
if "signers" in rules:
|
||||||
rules["signers"] = rules["signers"][:] # Make copy of the signers
|
rules["signers"] = rules["signers"][:] # Make copy of the signers
|
||||||
for permission_pattern, permission_rules in user_contents["permission_rules"].items(): # Regexp rules
|
for permission_pattern, permission_rules in user_contents["permission_rules"].items(): # Regexp rules
|
||||||
|
@ -285,7 +288,9 @@ class ContentManager(object):
|
||||||
rules["cert_signers"] = user_contents["cert_signers"] # Add valid cert signers
|
rules["cert_signers"] = user_contents["cert_signers"] # Add valid cert signers
|
||||||
if "signers" not in rules:
|
if "signers" not in rules:
|
||||||
rules["signers"] = []
|
rules["signers"] = []
|
||||||
rules["signers"].append(user_address) # Add user as valid signer
|
|
||||||
|
if not banned:
|
||||||
|
rules["signers"].append(user_address) # Add user as valid signer
|
||||||
rules["user_address"] = user_address
|
rules["user_address"] = user_address
|
||||||
rules["includes_allowed"] = False
|
rules["includes_allowed"] = False
|
||||||
|
|
||||||
|
|
|
@ -218,9 +218,6 @@ class Site(object):
|
||||||
content = self.content_manager.contents.get(inner_path)
|
content = self.content_manager.contents.get(inner_path)
|
||||||
if (not content or modified > content["modified"]) and inner_path not in self.bad_files:
|
if (not content or modified > content["modified"]) and inner_path not in self.bad_files:
|
||||||
self.log.debug("New modified file from %s: %s" % (peer, inner_path))
|
self.log.debug("New modified file from %s: %s" % (peer, inner_path))
|
||||||
if inner_path != "content.json" and self.content_manager.getRules(inner_path) == False:
|
|
||||||
self.log.debug("Banned user %s: %s, skipping." % (peer, inner_path))
|
|
||||||
continue
|
|
||||||
# We dont have this file or we have older
|
# We dont have this file or we have older
|
||||||
self.bad_files[inner_path] = self.bad_files.get(inner_path, 0) + 1 # Mark as bad file
|
self.bad_files[inner_path] = self.bad_files.get(inner_path, 0) + 1 # Mark as bad file
|
||||||
gevent.spawn(self.downloadContent, inner_path) # Download the content.json + the changed files
|
gevent.spawn(self.downloadContent, inner_path) # Download the content.json + the changed files
|
||||||
|
|
|
@ -22,6 +22,16 @@ class TestUserContent:
|
||||||
assert '1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C' in valid_signers # The user itself
|
assert '1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C' in valid_signers # The user itself
|
||||||
assert len(valid_signers) == 3 # No more valid signers
|
assert len(valid_signers) == 3 # No more valid signers
|
||||||
|
|
||||||
|
# Valid signer for banned user
|
||||||
|
user_content = site.storage.loadJson("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json")
|
||||||
|
user_content["cert_user_id"] = "bad@zeroid.bit"
|
||||||
|
|
||||||
|
valid_signers = site.content_manager.getValidSigners("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
||||||
|
assert '1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT' in valid_signers # The site address
|
||||||
|
assert '14wgQ4VDDZNoRMFF4yCDuTrBSHmYhL3bet' in valid_signers # Admin user definied in data/users/content.json
|
||||||
|
assert not '1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C' in valid_signers # The user itself
|
||||||
|
|
||||||
|
|
||||||
def testRules(self, site):
|
def testRules(self, site):
|
||||||
# We going to manipulate it this test rules based on data/users/content.json
|
# We going to manipulate it this test rules based on data/users/content.json
|
||||||
user_content = site.storage.loadJson("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json")
|
user_content = site.storage.loadJson("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json")
|
||||||
|
@ -31,24 +41,27 @@ class TestUserContent:
|
||||||
user_content["cert_user_id"] = "nofish@zeroid.bit"
|
user_content["cert_user_id"] = "nofish@zeroid.bit"
|
||||||
rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
||||||
assert rules["max_size"] == 100000
|
assert rules["max_size"] == 100000
|
||||||
|
assert "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C" in rules["signers"]
|
||||||
|
|
||||||
# Unknown user
|
# Unknown user
|
||||||
user_content["cert_auth_type"] = "web"
|
user_content["cert_auth_type"] = "web"
|
||||||
user_content["cert_user_id"] = "noone@zeroid.bit"
|
user_content["cert_user_id"] = "noone@zeroid.bit"
|
||||||
rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
||||||
assert rules["max_size"] == 10000
|
assert rules["max_size"] == 10000
|
||||||
|
assert "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C" in rules["signers"]
|
||||||
|
|
||||||
# User with more size limit based on auth type
|
# User with more size limit based on auth type
|
||||||
user_content["cert_auth_type"] = "bitmsg"
|
user_content["cert_auth_type"] = "bitmsg"
|
||||||
user_content["cert_user_id"] = "noone@zeroid.bit"
|
user_content["cert_user_id"] = "noone@zeroid.bit"
|
||||||
rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
||||||
assert rules["max_size"] == 15000
|
assert rules["max_size"] == 15000
|
||||||
|
assert "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C" in rules["signers"]
|
||||||
|
|
||||||
# Banned user
|
# Banned user
|
||||||
user_content["cert_auth_type"] = "web"
|
user_content["cert_auth_type"] = "web"
|
||||||
user_content["cert_user_id"] = "bad@zeroid.bit"
|
user_content["cert_user_id"] = "bad@zeroid.bit"
|
||||||
rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
rules = site.content_manager.getRules("data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json", user_content)
|
||||||
assert rules is False
|
assert "1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C" not in rules["signers"]
|
||||||
|
|
||||||
def testVerify(self, site):
|
def testVerify(self, site):
|
||||||
privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT
|
privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT
|
||||||
|
@ -176,3 +189,22 @@ class TestUserContent:
|
||||||
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
|
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
|
||||||
StringIO(json.dumps(signed_content)), ignore_same=False
|
StringIO(json.dumps(signed_content)), ignore_same=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Test banned user, signed by the site owner
|
||||||
|
user_content["cert_sign"] = CryptBitcoin.sign("1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C#%s/%s" % (
|
||||||
|
user_content["cert_auth_type"],
|
||||||
|
user_content["cert_user_id"].split("@")[0]
|
||||||
|
), cert_priv)
|
||||||
|
cert_user_id = user_content["cert_user_id"] # My username
|
||||||
|
site.content_manager.contents["data/users/content.json"]["user_contents"]["permissions"][cert_user_id] = False
|
||||||
|
|
||||||
|
site_privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv" # For 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT
|
||||||
|
del user_content["signs"] # Remove signs before signing
|
||||||
|
user_content["signs"] = {
|
||||||
|
"1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT": CryptBitcoin.sign(json.dumps(user_content, sort_keys=True), site_privatekey)
|
||||||
|
}
|
||||||
|
print user_content
|
||||||
|
assert site.content_manager.verifyFile(
|
||||||
|
"data/users/1J6UrZMkarjVg5ax9W4qThir3BFUikbW6C/content.json",
|
||||||
|
StringIO(json.dumps(user_content)), ignore_same=False
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue