-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_scenario_lifetime_user_change_password.py
213 lines (179 loc) · 7.63 KB
/
test_scenario_lifetime_user_change_password.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
from http import HTTPStatus
import pytest as pytest
import no_ssl_verification as SSL
import stubbing_utils as WireMockStubbing
from platform_api.facades.lifetime_facade import LifetimeFacade
from platform_api.facades.lifetime_model import LifetimeCredentials, LifetimeError, \
LifetimeChangeUserPassword
from wiremock_service import WireMockService, WIREMOCK_DEFAULT_URL
EXPECTED_USER_CHANGE_PASSWORD_REQUEST_TEMPLATE = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:out="http://www.outsystems.com">
<soapenv:Header/>
<soapenv:Body>
<out:User_ChangePassword>
<out:Authentication>
<out:Username>${{xmlunit.ignore}}</out:Username>
<out:Password>${{xmlunit.ignore}}</out:Password>
</out:Authentication>
<out:Username>{username}</out:Username>
<out:NewPassword>{new_password}</out:NewPassword>
<out:EncryptPassword>{encrypt_password}</out:EncryptPassword>
</out:User_ChangePassword>
</soapenv:Body>
</soapenv:Envelope>"""
EXPECTED_USER_CHANGE_PASSWORD_RESPONSE_TEMPLATE = """<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<User_ChangePasswordResponse xmlns="http://www.outsystems.com">
<Success>{success}</Success>
<Status>
<Id>{status_id}</Id>
<ResponseId>{response_id}</ResponseId>
<ResponseMessage>{response_message}</ResponseMessage>
<ResponseAdditionalInfo/>
</Status>
</User_ChangePasswordResponse>
</soap:Body>
</soap:Envelope>"""
USER_MANAGEMENT_SOAP_OPERATIONS_URL = "/LifeTimeServices/UserManagementService.asmx?wsdl"
wiremock = WireMockService(WIREMOCK_DEFAULT_URL)
def _setup_mappings_for_user_change_password(run_id: str):
happy_request = EXPECTED_USER_CHANGE_PASSWORD_REQUEST_TEMPLATE.format(
username="username",
new_password="new_password",
encrypt_password="true",
)
happy_response = EXPECTED_USER_CHANGE_PASSWORD_RESPONSE_TEMPLATE.format(
success="true",
status_id="1",
response_id="2",
response_message="smooth",
)
WireMockStubbing.register_soap_mapping(
wiremock=wiremock,
run_id=run_id,
soap_operations_url=USER_MANAGEMENT_SOAP_OPERATIONS_URL,
expected_request=happy_request,
expected_response=happy_response
)
expected_request_for_unsuccessful_operation = EXPECTED_USER_CHANGE_PASSWORD_REQUEST_TEMPLATE.format(
username="unsuccessful_user",
new_password="new_password",
encrypt_password="true",
)
expected_response_for_unsuccessful_operation = EXPECTED_USER_CHANGE_PASSWORD_RESPONSE_TEMPLATE.format(
success="false",
status_id="-1",
response_id="1000",
response_message="The password is the same as the old one",
)
WireMockStubbing.register_soap_mapping(
wiremock=wiremock,
run_id=run_id,
soap_operations_url=USER_MANAGEMENT_SOAP_OPERATIONS_URL,
expected_request=expected_request_for_unsuccessful_operation,
expected_response=expected_response_for_unsuccessful_operation
)
expected_request_for_internal_lifetime_error = EXPECTED_USER_CHANGE_PASSWORD_REQUEST_TEMPLATE.format(
username="unknown_user",
new_password="new_password",
encrypt_password="true",
)
expected_response_for_internal_lifetime_error = EXPECTED_USER_CHANGE_PASSWORD_RESPONSE_TEMPLATE.format(
success="false",
status_id="10",
response_id="999",
response_message="Lifetime internal error",
)
WireMockStubbing.register_soap_mapping(
wiremock=wiremock,
run_id=run_id,
soap_operations_url=USER_MANAGEMENT_SOAP_OPERATIONS_URL,
expected_request=expected_request_for_internal_lifetime_error,
expected_response=expected_response_for_internal_lifetime_error
)
expected_request_for_network_error = EXPECTED_USER_CHANGE_PASSWORD_REQUEST_TEMPLATE.format(
username="username_for_network_error",
new_password="new_password",
encrypt_password="true",
)
WireMockStubbing.register_soap_mapping(
wiremock=wiremock,
run_id=run_id,
soap_operations_url=USER_MANAGEMENT_SOAP_OPERATIONS_URL,
expected_request=expected_request_for_network_error,
expected_response=None,
http_status_code=HTTPStatus.INTERNAL_SERVER_ERROR
)
DEFAULT_DOMAIN = "localhost:8433"
@pytest.fixture(autouse=True, scope="session")
def boostrap():
run_id = WireMockStubbing.new_run_id()
with SSL.do_not_verify():
_setup_mappings_for_user_change_password(run_id)
yield run_id
with SSL.do_not_verify():
wiremock.delete_by_run_id(run_id)
def test_when_user_change_password_is_successful():
with SSL.do_not_verify():
lifetime = LifetimeFacade()
happy_response = lifetime.change_user_password(
domain=DEFAULT_DOMAIN,
authentication=LifetimeCredentials(username="admin_username", password="admin_password"),
user=LifetimeChangeUserPassword(
tenant_id="1122333",
username="username",
new_password="new_password",
),
encrypt_password=True
)
assert happy_response
def test_when_user_change_password_is_unsuccessful():
with SSL.do_not_verify():
lifetime = LifetimeFacade()
with pytest.raises(LifetimeError) as e:
_ = lifetime.change_user_password(
domain=DEFAULT_DOMAIN,
authentication=LifetimeCredentials(username="admin_username", password="admin_password"),
user=LifetimeChangeUserPassword(
tenant_id="1122333",
username="unsuccessful_user",
new_password="new_password",
),
encrypt_password=True
)
assert e.value.error_code == 1000
assert e.value.error_message == "The password is the same as the old one"
assert e.value.http_status_code == HTTPStatus.BAD_REQUEST
def test_when_user_change_password_with_internal_lifetime_error():
with SSL.do_not_verify():
lifetime = LifetimeFacade()
with pytest.raises(LifetimeError) as e:
_ = lifetime.change_user_password(
domain=DEFAULT_DOMAIN,
authentication=LifetimeCredentials(username="admin_username", password="admin_password"),
user=LifetimeChangeUserPassword(
tenant_id="1122333",
username="unknown_user",
new_password="new_password",
),
encrypt_password=True
)
assert e.value.error_code == 999
assert e.value.error_message == "Lifetime internal error"
def test_when_user_change_password_with_catastrophic_error():
with SSL.do_not_verify():
lifetime = LifetimeFacade()
with pytest.raises(LifetimeError) as e:
_ = lifetime.change_user_password(
domain=DEFAULT_DOMAIN,
authentication=LifetimeCredentials(username="admin_username", password="admin_password"),
user=LifetimeChangeUserPassword(
tenant_id="1122333",
username="username_for_network_error",
new_password="new_password",
),
encrypt_password=True
)
assert e.value.error_code == ""
assert e.value.error_message == "Server Error"
assert e.value.http_status_code == HTTPStatus.INTERNAL_SERVER_ERROR