Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release-v0.24.1' of github.com:matrix-org/synapse
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Oct 24, 2017
2 parents ffba978 + 6ba4fab commit f009df2
Show file tree
Hide file tree
Showing 64 changed files with 219 additions and 159 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Changes in synapse v0.24.1 (2017-10-24)
=======================================

Bug fixes:

* Fix updating group profiles over federation (PR #2567)


Changes in synapse v0.24.0 (2017-10-23)
=======================================

Expand Down
2 changes: 1 addition & 1 deletion synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
""" This is a reference implementation of a Matrix home server.
"""

__version__ = "0.24.0"
__version__ = "0.24.1"
2 changes: 1 addition & 1 deletion synapse/app/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

try:
import affinity
except:
except Exception:
affinity = None

from daemonize import Daemonize
Expand Down
2 changes: 1 addition & 1 deletion synapse/appservice/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _send_request(self, service):
with Measure(self.clock, "servicequeuer.send"):
try:
yield self.txn_ctrl.send(service, events)
except:
except Exception:
logger.exception("AS request failed")
finally:
self.requests_in_flight.discard(service.id)
Expand Down
2 changes: 1 addition & 1 deletion synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def read_gc_thresholds(thresholds):
return (
int(thresholds[0]), int(thresholds[1]), int(thresholds[2]),
)
except:
except Exception:
raise ConfigError(
"Value of `gc_threshold` must be a list of three integers if set"
)
2 changes: 1 addition & 1 deletion synapse/crypto/context_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def configure_context(context, config):
try:
_ecCurve = _OpenSSLECCurve(_defaultCurveName)
_ecCurve.addECKeyToContext(context)
except:
except Exception:
logger.exception("Failed to enable elliptic curve for TLS")
context.set_options(SSL.OP_NO_SSLv2 | SSL.OP_NO_SSLv3)
context.use_certificate_chain_file(config.tls_certificate_file)
Expand Down
2 changes: 1 addition & 1 deletion synapse/crypto/event_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def check_event_content_hash(event, hash_algorithm=hashlib.sha256):
message_hash_base64 = event.hashes[name]
try:
message_hash_bytes = decode_base64(message_hash_base64)
except:
except Exception:
raise SynapseError(
400,
"Invalid base64: %s" % (message_hash_base64,),
Expand Down
2 changes: 1 addition & 1 deletion synapse/crypto/keyring.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ def _handle_key_deferred(verify_request):
))
try:
verify_signed_json(json_object, server_name, verify_key)
except:
except Exception:
raise SynapseError(
401,
"Invalid signature for server %s with key %s:%s" % (
Expand Down
4 changes: 2 additions & 2 deletions synapse/event_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,12 @@ def _check_power_levels(event, auth_events):
for k, v in user_list.items():
try:
UserID.from_string(k)
except:
except Exception:
raise SynapseError(400, "Not a valid user_id: %s" % (k,))

try:
int(v)
except:
except Exception:
raise SynapseError(400, "Not a valid power level: %s" % (v,))

key = (event.type, event.state_key, )
Expand Down
2 changes: 1 addition & 1 deletion synapse/events/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create_event_id(self):

local_part = str(int(self.clock.time())) + i + random_string(5)

e_id = EventID.create(local_part, self.hostname)
e_id = EventID(local_part, self.hostname)

return e_id.to_string()

Expand Down
2 changes: 1 addition & 1 deletion synapse/events/spamcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, hs):
config = None
try:
module, config = hs.config.spam_checker
except:
except Exception:
pass

if module is not None:
Expand Down
20 changes: 20 additions & 0 deletions synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,26 @@ def get_group_profile(self, destination, group_id, requester_user_id):
ignore_backoff=True,
)

@log_function
def update_group_profile(self, destination, group_id, requester_user_id, content):
"""Update a remote group profile
Args:
destination (str)
group_id (str)
requester_user_id (str)
content (dict): The new profile of the group
"""
path = PREFIX + "/groups/%s/profile" % (group_id,)

return self.client.post_json(
destination=destination,
path=path,
args={"requester_user_id": requester_user_id},
data=content,
ignore_backoff=True,
)

@log_function
def get_group_summary(self, destination, group_id, requester_user_id):
"""Get a group summary
Expand Down
28 changes: 14 additions & 14 deletions synapse/federation/transport/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def strip_quotes(value):
key = strip_quotes(param_dict["key"])
sig = strip_quotes(param_dict["sig"])
return (origin, key, sig)
except:
except Exception:
raise AuthenticationError(
400, "Malformed Authorization header", Codes.UNAUTHORIZED
)
Expand Down Expand Up @@ -177,7 +177,7 @@ def new_func(request, *args, **kwargs):
if self.REQUIRE_AUTH:
logger.exception("authenticate_request failed")
raise
except:
except Exception:
logger.exception("authenticate_request failed")
raise

Expand Down Expand Up @@ -270,7 +270,7 @@ def on_PUT(self, origin, content, query, transaction_id):
code, response = yield self.handler.on_incoming_transaction(
transaction_data
)
except:
except Exception:
logger.exception("on_incoming_transaction failed")
raise

Expand Down Expand Up @@ -610,7 +610,7 @@ def on_GET(self, origin, content, query):


class FederationGroupsProfileServlet(BaseFederationServlet):
"""Get the basic profile of a group on behalf of a user
"""Get/set the basic profile of a group on behalf of a user
"""
PATH = "/groups/(?P<group_id>[^/]*)/profile$"

Expand All @@ -626,30 +626,30 @@ def on_GET(self, origin, content, query, group_id):

defer.returnValue((200, new_content))


class FederationGroupsSummaryServlet(BaseFederationServlet):
PATH = "/groups/(?P<group_id>[^/]*)/summary$"

@defer.inlineCallbacks
def on_GET(self, origin, content, query, group_id):
def on_POST(self, origin, content, query, group_id):
requester_user_id = parse_string_from_args(query, "requester_user_id")
if get_domain_from_id(requester_user_id) != origin:
raise SynapseError(403, "requester_user_id doesn't match origin")

new_content = yield self.handler.get_group_summary(
group_id, requester_user_id
new_content = yield self.handler.update_group_profile(
group_id, requester_user_id, content
)

defer.returnValue((200, new_content))


class FederationGroupsSummaryServlet(BaseFederationServlet):
PATH = "/groups/(?P<group_id>[^/]*)/summary$"

@defer.inlineCallbacks
def on_POST(self, origin, content, query, group_id):
def on_GET(self, origin, content, query, group_id):
requester_user_id = parse_string_from_args(query, "requester_user_id")
if get_domain_from_id(requester_user_id) != origin:
raise SynapseError(403, "requester_user_id doesn't match origin")

new_content = yield self.handler.update_group_profile(
group_id, requester_user_id, content
new_content = yield self.handler.get_group_summary(
group_id, requester_user_id
)

defer.returnValue((200, new_content))
Expand Down
32 changes: 8 additions & 24 deletions synapse/groups/groups_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from twisted.internet import defer
import logging

from synapse.api.errors import SynapseError
from synapse.types import UserID, get_domain_from_id, RoomID, GroupID


import logging
import urllib
from synapse.types import GroupID, RoomID, UserID, get_domain_from_id
from twisted.internet import defer

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -698,9 +695,11 @@ def remove_user_from_group(self, group_id, user_id, requester_user_id, content):
def create_group(self, group_id, user_id, content):
group = yield self.check_group_is_ours(group_id)

_validate_group_id(group_id)

logger.info("Attempting to create group with ID: %r", group_id)

# parsing the id into a GroupID validates it.
group_id_obj = GroupID.from_string(group_id)

if group:
raise SynapseError(400, "Group already exists")

Expand All @@ -710,7 +709,7 @@ def create_group(self, group_id, user_id, content):
raise SynapseError(
403, "Only server admin can create group on this server",
)
localpart = GroupID.from_string(group_id).localpart
localpart = group_id_obj.localpart
if not localpart.startswith(self.hs.config.group_creation_prefix):
raise SynapseError(
400,
Expand Down Expand Up @@ -786,18 +785,3 @@ def _parse_visibility_from_contents(content):
is_public = True

return is_public


def _validate_group_id(group_id):
"""Validates the group ID is valid for creation on this home server
"""
localpart = GroupID.from_string(group_id).localpart

if localpart.lower() != localpart:
raise SynapseError(400, "Group ID must be lower case")

if urllib.quote(localpart.encode('utf-8')) != localpart:
raise SynapseError(
400,
"Group ID can only contain characters a-z, 0-9, or '_-./'",
)
2 changes: 1 addition & 1 deletion synapse/handlers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _check_password_auth(self, authdict, _):
user_id = authdict["user"]
password = authdict["password"]
if not user_id.startswith('@'):
user_id = UserID.create(user_id, self.hs.hostname).to_string()
user_id = UserID(user_id, self.hs.hostname).to_string()

return self._check_password(user_id, password)

Expand Down
16 changes: 8 additions & 8 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def on_receive_pdu(self, origin, pdu, get_missing=True):
state, auth_chain = yield self.replication_layer.get_state_for_room(
origin, pdu.room_id, pdu.event_id,
)
except:
except Exception:
logger.exception("Failed to get state for event: %s", pdu.event_id)

yield self._process_received_pdu(
Expand Down Expand Up @@ -461,7 +461,7 @@ def _filter_events_for_server(self, server_name, room_id, events):
def check_match(id):
try:
return server_name == get_domain_from_id(id)
except:
except Exception:
return False

# Parses mapping `event_id -> (type, state_key) -> state event_id`
Expand Down Expand Up @@ -499,7 +499,7 @@ def redact_disallowed(event, state):
continue
try:
domain = get_domain_from_id(ev.state_key)
except:
except Exception:
continue

if domain != server_name:
Expand Down Expand Up @@ -738,7 +738,7 @@ def get_domains_from_state(state):
joined_domains[dom] = min(d, old_d)
else:
joined_domains[dom] = d
except:
except Exception:
pass

return sorted(joined_domains.items(), key=lambda d: d[1])
Expand Down Expand Up @@ -940,7 +940,7 @@ def do_invite_join(self, target_hosts, room_id, joinee, content):
room_creator_user_id="",
is_public=False
)
except:
except Exception:
# FIXME
pass

Expand Down Expand Up @@ -1775,7 +1775,7 @@ def do_auth(self, origin, event, context, auth_events):
[e_id for e_id, _ in event.auth_events]
)
seen_events = set(have_events.keys())
except:
except Exception:
# FIXME:
logger.exception("Failed to get auth chain")

Expand Down Expand Up @@ -1899,7 +1899,7 @@ def do_auth(self, origin, event, context, auth_events):
except AuthError:
pass

except:
except Exception:
# FIXME:
logger.exception("Failed to query auth chain")

Expand Down Expand Up @@ -1966,7 +1966,7 @@ def sort_fun(ev):
def get_next(it, opt=None):
try:
return it.next()
except:
except Exception:
return opt

current_local = get_next(local_iter)
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def handle_room(event):
})

d["account_data"] = account_data_events
except:
except Exception:
logger.exception("Failed to get snapshot")

yield concurrently_execute(handle_room, room_list, 10)
Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def handle_new_client_event(
try:
dump = ujson.dumps(unfreeze(event.content))
ujson.loads(dump)
except:
except Exception:
logger.exception("Failed to encode content: %r", event.content)
raise

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def _handle_timeouts(self):
)

preserve_fn(self._update_states)(changes)
except:
except Exception:
logger.exception("Exception in _handle_timeouts loop")

@defer.inlineCallbacks
Expand Down
Loading

0 comments on commit f009df2

Please sign in to comment.