Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

matrix-org / synapse / 4532

23 Sep 2019 - 19:39 coverage decreased (-49.7%) to 17.596%
4532

Pull #6079

buildkite

Richard van der Hoff
update changelog
Pull Request #6079: Add submit_url response parameter to msisdn /requestToken

359 of 12986 branches covered (2.76%)

Branch coverage included in aggregate %.

0 of 7 new or added lines in 1 file covered. (0.0%)

18869 existing lines in 281 files now uncovered.

8809 of 39116 relevant lines covered (22.52%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.1
/synapse/storage/signatures.py
1
# -*- coding: utf-8 -*-
2
# Copyright 2014-2016 OpenMarket Ltd
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15

16
import six
1×
17

18
from unpaddedbase64 import encode_base64
1×
19

20
from twisted.internet import defer
1×
21

22
from synapse.crypto.event_signing import compute_event_reference_hash
1×
23
from synapse.util.caches.descriptors import cached, cachedList
1×
24

25
from ._base import SQLBaseStore
1×
26

27
# py2 sqlite has buffer hardcoded as only binary type, so we must use it,
28
# despite being deprecated and removed in favor of memoryview
29
if six.PY2:
Branches [[0, 30]] missed. 1×
30
    db_binary_type = six.moves.builtins.buffer
!
31
else:
32
    db_binary_type = memoryview
1×
33

34

35
class SignatureWorkerStore(SQLBaseStore):
1×
36
    @cached()
1×
37
    def get_event_reference_hash(self, event_id):
38
        # This is a dummy function to allow get_event_reference_hashes
39
        # to use its cache
40
        raise NotImplementedError()
!
41

42
    @cachedList(
1×
43
        cached_method_name="get_event_reference_hash", list_name="event_ids", num_args=1
44
    )
45
    def get_event_reference_hashes(self, event_ids):
UNCOV
46
        def f(txn):
!
UNCOV
47
            return {
Branches [[0, 47], [0, 46]] missed. !
48
                event_id: self._get_event_reference_hashes_txn(txn, event_id)
49
                for event_id in event_ids
50
            }
51

UNCOV
52
        return self.runInteraction("get_event_reference_hashes", f)
!
53

54
    @defer.inlineCallbacks
1×
55
    def add_event_hashes(self, event_ids):
UNCOV
56
        hashes = yield self.get_event_reference_hashes(event_ids)
!
UNCOV
57
        hashes = {
Branches [[0, 58], [0, 57], [0, 62]] missed. !
58
            e_id: {k: encode_base64(v) for k, v in h.items() if k == "sha256"}
59
            for e_id, h in hashes.items()
60
        }
61

UNCOV
62
        return list(hashes.items())
!
63

64
    def _get_event_reference_hashes_txn(self, txn, event_id):
1×
65
        """Get all the hashes for a given PDU.
66
        Args:
67
            txn (cursor):
68
            event_id (str): Id for the Event.
69
        Returns:
70
            A dict[unicode, bytes] of algorithm -> hash.
71
        """
UNCOV
72
        query = (
!
73
            "SELECT algorithm, hash"
74
            " FROM event_reference_hashes"
75
            " WHERE event_id = ?"
76
        )
UNCOV
77
        txn.execute(query, (event_id,))
!
UNCOV
78
        return {k: v for k, v in txn}
Branches [[0, 78], [0, 64]] missed. !
79

80

81
class SignatureStore(SignatureWorkerStore):
1×
82
    """Persistence for event signatures and hashes"""
83

84
    def _store_event_reference_hashes_txn(self, txn, events):
1×
85
        """Store a hash for a PDU
86
        Args:
87
            txn (cursor):
88
            events (list): list of Events.
89
        """
90

UNCOV
91
        vals = []
!
UNCOV
92
        for event in events:
Branches [[0, 93], [0, 102]] missed. !
UNCOV
93
            ref_alg, ref_hash_bytes = compute_event_reference_hash(event)
!
UNCOV
94
            vals.append(
!
95
                {
96
                    "event_id": event.event_id,
97
                    "algorithm": ref_alg,
98
                    "hash": db_binary_type(ref_hash_bytes),
99
                }
100
            )
101

UNCOV
102
        self._simple_insert_many_txn(txn, table="event_reference_hashes", values=vals)
!
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2019 Coveralls, LLC