mirror of https://github.com/watcha-fr/synapse
commit
3b97797c8d
@ -0,0 +1,22 @@ |
||||
#!/bin/bash |
||||
|
||||
set -eux |
||||
|
||||
: ${WORKSPACE:="$(pwd)"} |
||||
|
||||
export PYTHONDONTWRITEBYTECODE=yep |
||||
export SYNAPSE_CACHE_FACTOR=1 |
||||
|
||||
# Output test results as junit xml |
||||
export TRIAL_FLAGS="--reporter=subunit" |
||||
export TOXSUFFIX="| subunit-1to2 | subunit2junitxml --no-passthrough --output-to=results.xml" |
||||
# Write coverage reports to a separate file for each process |
||||
export COVERAGE_OPTS="-p" |
||||
export DUMP_COVERAGE_COMMAND="coverage help" |
||||
|
||||
# Output flake8 violations to violations.flake8.log |
||||
export PEP8SUFFIX="--output-file=violations.flake8.log" |
||||
|
||||
rm .coverage* || echo "No coverage files to remove" |
||||
|
||||
tox -e packaging -e pep8 |
@ -0,0 +1,92 @@ |
||||
#!/bin/bash |
||||
|
||||
set -eux |
||||
|
||||
: ${WORKSPACE:="$(pwd)"} |
||||
|
||||
export PYTHONDONTWRITEBYTECODE=yep |
||||
export SYNAPSE_CACHE_FACTOR=1 |
||||
|
||||
# Output test results as junit xml |
||||
export TRIAL_FLAGS="--reporter=subunit" |
||||
export TOXSUFFIX="| subunit-1to2 | subunit2junitxml --no-passthrough --output-to=results.xml" |
||||
# Write coverage reports to a separate file for each process |
||||
export COVERAGE_OPTS="-p" |
||||
export DUMP_COVERAGE_COMMAND="coverage help" |
||||
|
||||
# Output flake8 violations to violations.flake8.log |
||||
# Don't exit with non-0 status code on Jenkins, |
||||
# so that the build steps continue and a later step can decided whether to |
||||
# UNSTABLE or FAILURE this build. |
||||
export PEP8SUFFIX="--output-file=violations.flake8.log || echo flake8 finished with status code \$?" |
||||
|
||||
rm .coverage* || echo "No coverage files to remove" |
||||
|
||||
tox --notest |
||||
|
||||
: ${GIT_BRANCH:="origin/$(git rev-parse --abbrev-ref HEAD)"} |
||||
|
||||
TOX_BIN=$WORKSPACE/.tox/py27/bin |
||||
|
||||
if [[ ! -e .sytest-base ]]; then |
||||
git clone https://github.com/matrix-org/sytest.git .sytest-base --mirror |
||||
else |
||||
(cd .sytest-base; git fetch -p) |
||||
fi |
||||
|
||||
rm -rf sytest |
||||
git clone .sytest-base sytest --shared |
||||
cd sytest |
||||
|
||||
git checkout "${GIT_BRANCH}" || (echo >&2 "No ref ${GIT_BRANCH} found, falling back to develop" ; git checkout develop) |
||||
|
||||
: ${PERL5LIB:=$WORKSPACE/perl5/lib/perl5} |
||||
: ${PERL_MB_OPT:=--install_base=$WORKSPACE/perl5} |
||||
: ${PERL_MM_OPT:=INSTALL_BASE=$WORKSPACE/perl5} |
||||
export PERL5LIB PERL_MB_OPT PERL_MM_OPT |
||||
|
||||
./install-deps.pl |
||||
|
||||
: ${PORT_BASE:=8000} |
||||
|
||||
|
||||
if [[ -z "$POSTGRES_DB_1" ]]; then |
||||
echo >&2 "Variable POSTGRES_DB_1 not set" |
||||
exit 1 |
||||
fi |
||||
|
||||
if [[ -z "$POSTGRES_DB_2" ]]; then |
||||
echo >&2 "Variable POSTGRES_DB_2 not set" |
||||
exit 1 |
||||
fi |
||||
|
||||
mkdir -p "localhost-$(($PORT_BASE + 1))" |
||||
mkdir -p "localhost-$(($PORT_BASE + 2))" |
||||
|
||||
cat > localhost-$(($PORT_BASE + 1))/database.yaml << EOF |
||||
name: psycopg2 |
||||
args: |
||||
database: $POSTGRES_DB_1 |
||||
EOF |
||||
|
||||
cat > localhost-$(($PORT_BASE + 2))/database.yaml << EOF |
||||
name: psycopg2 |
||||
args: |
||||
database: $POSTGRES_DB_2 |
||||
EOF |
||||
|
||||
|
||||
# Run if both postgresql databases exist |
||||
echo >&2 "Running sytest with PostgreSQL"; |
||||
$TOX_BIN/pip install psycopg2 |
||||
./run-tests.pl --coverage -O tap --synapse-directory $WORKSPACE \ |
||||
--python $TOX_BIN/python --all --port-base $PORT_BASE > results-postgresql.tap |
||||
|
||||
cd .. |
||||
cp sytest/.coverage.* . |
||||
|
||||
# Combine the coverage reports |
||||
echo "Combining:" .coverage.* |
||||
$TOX_BIN/python -m coverage combine |
||||
# Output coverage to coverage.xml |
||||
$TOX_BIN/coverage xml -o coverage.xml |
@ -0,0 +1,63 @@ |
||||
#!/bin/bash |
||||
|
||||
set -eux |
||||
|
||||
: ${WORKSPACE:="$(pwd)"} |
||||
|
||||
export PYTHONDONTWRITEBYTECODE=yep |
||||
export SYNAPSE_CACHE_FACTOR=1 |
||||
|
||||
# Output test results as junit xml |
||||
export TRIAL_FLAGS="--reporter=subunit" |
||||
export TOXSUFFIX="| subunit-1to2 | subunit2junitxml --no-passthrough --output-to=results.xml" |
||||
# Write coverage reports to a separate file for each process |
||||
export COVERAGE_OPTS="-p" |
||||
export DUMP_COVERAGE_COMMAND="coverage help" |
||||
|
||||
# Output flake8 violations to violations.flake8.log |
||||
# Don't exit with non-0 status code on Jenkins, |
||||
# so that the build steps continue and a later step can decided whether to |
||||
# UNSTABLE or FAILURE this build. |
||||
export PEP8SUFFIX="--output-file=violations.flake8.log || echo flake8 finished with status code \$?" |
||||
|
||||
rm .coverage* || echo "No coverage files to remove" |
||||
|
||||
tox --notest |
||||
|
||||
: ${GIT_BRANCH:="origin/$(git rev-parse --abbrev-ref HEAD)"} |
||||
|
||||
TOX_BIN=$WORKSPACE/.tox/py27/bin |
||||
|
||||
if [[ ! -e .sytest-base ]]; then |
||||
git clone https://github.com/matrix-org/sytest.git .sytest-base --mirror |
||||
else |
||||
(cd .sytest-base; git fetch -p) |
||||
fi |
||||
|
||||
rm -rf sytest |
||||
git clone .sytest-base sytest --shared |
||||
cd sytest |
||||
|
||||
git checkout "${GIT_BRANCH}" || (echo >&2 "No ref ${GIT_BRANCH} found, falling back to develop" ; git checkout develop) |
||||
|
||||
: ${PERL5LIB:=$WORKSPACE/perl5/lib/perl5} |
||||
: ${PERL_MB_OPT:=--install_base=$WORKSPACE/perl5} |
||||
: ${PERL_MM_OPT:=INSTALL_BASE=$WORKSPACE/perl5} |
||||
export PERL5LIB PERL_MB_OPT PERL_MM_OPT |
||||
|
||||
./install-deps.pl |
||||
|
||||
: ${PORT_BASE:=8500} |
||||
|
||||
echo >&2 "Running sytest with SQLite3"; |
||||
./run-tests.pl --coverage -O tap --synapse-directory $WORKSPACE \ |
||||
--python $TOX_BIN/python --all --port-base $PORT_BASE > results-sqlite3.tap |
||||
|
||||
cd .. |
||||
cp sytest/.coverage.* . |
||||
|
||||
# Combine the coverage reports |
||||
echo "Combining:" .coverage.* |
||||
$TOX_BIN/python -m coverage combine |
||||
# Output coverage to coverage.xml |
||||
$TOX_BIN/coverage xml -o coverage.xml |
@ -0,0 +1,25 @@ |
||||
#!/bin/bash |
||||
|
||||
set -eux |
||||
|
||||
: ${WORKSPACE:="$(pwd)"} |
||||
|
||||
export PYTHONDONTWRITEBYTECODE=yep |
||||
export SYNAPSE_CACHE_FACTOR=1 |
||||
|
||||
# Output test results as junit xml |
||||
export TRIAL_FLAGS="--reporter=subunit" |
||||
export TOXSUFFIX="| subunit-1to2 | subunit2junitxml --no-passthrough --output-to=results.xml" |
||||
# Write coverage reports to a separate file for each process |
||||
export COVERAGE_OPTS="-p" |
||||
export DUMP_COVERAGE_COMMAND="coverage help" |
||||
|
||||
# Output flake8 violations to violations.flake8.log |
||||
# Don't exit with non-0 status code on Jenkins, |
||||
# so that the build steps continue and a later step can decided whether to |
||||
# UNSTABLE or FAILURE this build. |
||||
export PEP8SUFFIX="--output-file=violations.flake8.log || echo flake8 finished with status code \$?" |
||||
|
||||
rm .coverage* || echo "No coverage files to remove" |
||||
|
||||
tox -e py27 |
@ -0,0 +1,40 @@ |
||||
# Copyright 2015, 2016 OpenMarket Ltd |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
from ._base import Config |
||||
|
||||
from synapse.api.constants import EventTypes |
||||
|
||||
|
||||
class ApiConfig(Config): |
||||
|
||||
def read_config(self, config): |
||||
self.room_invite_state_types = config.get("room_invite_state_types", [ |
||||
EventTypes.JoinRules, |
||||
EventTypes.CanonicalAlias, |
||||
EventTypes.RoomAvatar, |
||||
EventTypes.Name, |
||||
]) |
||||
|
||||
def default_config(cls, **kwargs): |
||||
return """\ |
||||
## API Configuration ## |
||||
|
||||
# A list of event types that will be included in the room_invite_state |
||||
room_invite_state_types: |
||||
- "{JoinRules}" |
||||
- "{CanonicalAlias}" |
||||
- "{RoomAvatar}" |
||||
- "{Name}" |
||||
""".format(**vars(EventTypes)) |
@ -0,0 +1,112 @@ |
||||
# -*- coding: utf-8 -*- |
||||
# Copyright 2016 OpenMarket Ltd |
||||
# |
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
# |
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
# |
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
from synapse.push.baserules import list_with_base_rules |
||||
|
||||
from synapse.push.rulekinds import ( |
||||
PRIORITY_CLASS_MAP, PRIORITY_CLASS_INVERSE_MAP |
||||
) |
||||
|
||||
import copy |
||||
import simplejson as json |
||||
|
||||
|
||||
def format_push_rules_for_user(user, rawrules, enabled_map): |
||||
"""Converts a list of rawrules and a enabled map into nested dictionaries |
||||
to match the Matrix client-server format for push rules""" |
||||
|
||||
ruleslist = [] |
||||
for rawrule in rawrules: |
||||
rule = dict(rawrule) |
||||
rule["conditions"] = json.loads(rawrule["conditions"]) |
||||
rule["actions"] = json.loads(rawrule["actions"]) |
||||
ruleslist.append(rule) |
||||
|
||||
# We're going to be mutating this a lot, so do a deep copy |
||||
ruleslist = copy.deepcopy(list_with_base_rules(ruleslist)) |
||||
|
||||
rules = {'global': {}, 'device': {}} |
||||
|
||||
rules['global'] = _add_empty_priority_class_arrays(rules['global']) |
||||
|
||||
for r in ruleslist: |
||||
rulearray = None |
||||
|
||||
template_name = _priority_class_to_template_name(r['priority_class']) |
||||
|
||||
# Remove internal stuff. |
||||
for c in r["conditions"]: |
||||
c.pop("_id", None) |
||||
|
||||
pattern_type = c.pop("pattern_type", None) |
||||
if pattern_type == "user_id": |
||||
c["pattern"] = user.to_string() |
||||
elif pattern_type == "user_localpart": |
||||
c["pattern"] = user.localpart |
||||
|
||||
rulearray = rules['global'][template_name] |
||||
|
||||
template_rule = _rule_to_template(r) |
||||
if template_rule: |
||||
if r['rule_id'] in enabled_map: |
||||
template_rule['enabled'] = enabled_map[r['rule_id']] |
||||
elif 'enabled' in r: |
||||
template_rule['enabled'] = r['enabled'] |
||||
else: |
||||
template_rule['enabled'] = True |
||||
rulearray.append(template_rule) |
||||
|
||||
return rules |
||||
|
||||
|
||||
def _add_empty_priority_class_arrays(d): |
||||
for pc in PRIORITY_CLASS_MAP.keys(): |
||||
d[pc] = [] |
||||
return d |
||||
|
||||
|
||||
def _rule_to_template(rule): |
||||
unscoped_rule_id = None |
||||
if 'rule_id' in rule: |
||||
unscoped_rule_id = _rule_id_from_namespaced(rule['rule_id']) |
||||
|
||||
template_name = _priority_class_to_template_name(rule['priority_class']) |
||||
if template_name in ['override', 'underride']: |
||||
templaterule = {k: rule[k] for k in ["conditions", "actions"]} |
||||
elif template_name in ["sender", "room"]: |
||||
templaterule = {'actions': rule['actions']} |
||||
unscoped_rule_id = rule['conditions'][0]['pattern'] |
||||
elif template_name == 'content': |
||||
if len(rule["conditions"]) != 1: |
||||
return None |
||||
thecond = rule["conditions"][0] |
||||
if "pattern" not in thecond: |
||||
return None |
||||
templaterule = {'actions': rule['actions']} |
||||
templaterule["pattern"] = thecond["pattern"] |
||||
|
||||
if unscoped_rule_id: |
||||
templaterule['rule_id'] = unscoped_rule_id |
||||
if 'default' in rule: |
||||
templaterule['default'] = rule['default'] |
||||
return templaterule |
||||
|
||||
|
||||
def _rule_id_from_namespaced(in_rule_id): |
||||
return in_rule_id.split('/')[-1] |
||||
|
||||
|
||||
def _priority_class_to_template_name(pc): |
||||
return PRIORITY_CLASS_INVERSE_MAP[pc] |
@ -0,0 +1,16 @@ |
||||
/* Copyright 2016 OpenMarket Ltd |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
ALTER TABLE room_aliases ADD COLUMN creator TEXT; |
@ -0,0 +1,38 @@ |
||||
/* Copyright 2016 OpenMarket Ltd |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
|
||||
|
||||
CREATE TABLE push_rules_stream( |
||||
stream_id BIGINT NOT NULL, |
||||
event_stream_ordering BIGINT NOT NULL, |
||||
user_id TEXT NOT NULL, |
||||
rule_id TEXT NOT NULL, |
||||
op TEXT NOT NULL, -- One of "ENABLE", "DISABLE", "ACTIONS", "ADD", "DELETE" |
||||
priority_class SMALLINT, |
||||
priority INTEGER, |
||||
conditions TEXT, |
||||
actions TEXT |
||||
); |
||||
|
||||
-- The extra data for each operation is: |
||||
-- * ENABLE, DISABLE, DELETE: [] |
||||
-- * ACTIONS: ["actions"] |
||||
-- * ADD: ["priority_class", "priority", "actions", "conditions"] |
||||
|
||||
-- Index for replication queries. |
||||
CREATE INDEX push_rules_stream_id ON push_rules_stream(stream_id); |
||||
-- Index for /sync queries. |
||||
CREATE INDEX push_rules_stream_user_stream_id on push_rules_stream(user_id, stream_id); |
Loading…
Reference in new issue