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

50.0
/synapse/replication/http/register.py
1
# -*- coding: utf-8 -*-
2
# Copyright 2019 New Vector 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 logging
1×
17

18
from twisted.internet import defer
1×
19

20
from synapse.http.servlet import parse_json_object_from_request
1×
21
from synapse.replication.http._base import ReplicationEndpoint
1×
22

23
logger = logging.getLogger(__name__)
1×
24

25

26
class ReplicationRegisterServlet(ReplicationEndpoint):
1×
27
    """Register a new user
28
    """
29

30
    NAME = "register_user"
1×
31
    PATH_ARGS = ("user_id",)
1×
32

33
    def __init__(self, hs):
1×
UNCOV
34
        super(ReplicationRegisterServlet, self).__init__(hs)
!
UNCOV
35
        self.store = hs.get_datastore()
!
UNCOV
36
        self.registration_handler = hs.get_registration_handler()
!
37

38
    @staticmethod
1×
39
    def _serialize_payload(
40
        user_id,
41
        password_hash,
42
        was_guest,
43
        make_guest,
44
        appservice_id,
45
        create_profile_with_displayname,
46
        admin,
47
        user_type,
48
        address,
49
    ):
50
        """
51
        Args:
52
            user_id (str): The desired user ID to register.
53
            password_hash (str|None): Optional. The password hash for this user.
54
            was_guest (bool): Optional. Whether this is a guest account being
55
                upgraded to a non-guest account.
56
            make_guest (boolean): True if the the new user should be guest,
57
                false to add a regular user account.
58
            appservice_id (str|None): The ID of the appservice registering the user.
59
            create_profile_with_displayname (unicode|None): Optionally create a
60
                profile for the user, setting their displayname to the given value
61
            admin (boolean): is an admin user?
62
            user_type (str|None): type of user. One of the values from
63
                api.constants.UserTypes, or None for a normal user.
64
            address (str|None): the IP address used to perform the regitration.
65
        """
66
        return {
!
67
            "password_hash": password_hash,
68
            "was_guest": was_guest,
69
            "make_guest": make_guest,
70
            "appservice_id": appservice_id,
71
            "create_profile_with_displayname": create_profile_with_displayname,
72
            "admin": admin,
73
            "user_type": user_type,
74
            "address": address,
75
        }
76

77
    @defer.inlineCallbacks
1×
78
    def _handle_request(self, request, user_id):
79
        content = parse_json_object_from_request(request)
!
80

81
        yield self.registration_handler.register_with_store(
!
82
            user_id=user_id,
83
            password_hash=content["password_hash"],
84
            was_guest=content["was_guest"],
85
            make_guest=content["make_guest"],
86
            appservice_id=content["appservice_id"],
87
            create_profile_with_displayname=content["create_profile_with_displayname"],
88
            admin=content["admin"],
89
            user_type=content["user_type"],
90
            address=content["address"],
91
        )
92

93
        return 200, {}
!
94

95

96
class ReplicationPostRegisterActionsServlet(ReplicationEndpoint):
1×
97
    """Run any post registration actions
98
    """
99

100
    NAME = "post_register"
1×
101
    PATH_ARGS = ("user_id",)
1×
102

103
    def __init__(self, hs):
1×
UNCOV
104
        super(ReplicationPostRegisterActionsServlet, self).__init__(hs)
!
UNCOV
105
        self.store = hs.get_datastore()
!
UNCOV
106
        self.registration_handler = hs.get_registration_handler()
!
107

108
    @staticmethod
1×
109
    def _serialize_payload(user_id, auth_result, access_token):
110
        """
111
        Args:
112
            user_id (str): The user ID that consented
113
            auth_result (dict): The authenticated credentials of the newly
114
                registered user.
115
            access_token (str|None): The access token of the newly logged in
116
                device, or None if `inhibit_login` enabled.
117
        """
118
        return {"auth_result": auth_result, "access_token": access_token}
!
119

120
    @defer.inlineCallbacks
1×
121
    def _handle_request(self, request, user_id):
122
        content = parse_json_object_from_request(request)
!
123

124
        auth_result = content["auth_result"]
!
125
        access_token = content["access_token"]
!
126

127
        yield self.registration_handler.post_registration_actions(
!
128
            user_id=user_id, auth_result=auth_result, access_token=access_token
129
        )
130

131
        return 200, {}
!
132

133

134
def register_servlets(hs, http_server):
1×
UNCOV
135
    ReplicationRegisterServlet(hs).register(http_server)
!
UNCOV
136
    ReplicationPostRegisterActionsServlet(hs).register(http_server)
!
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