@ -99,9 +99,9 @@ class _NoMetrics:
pass
def _login ( client : TestClient , username : str ) :
def _login ( client : TestClient , email : str ) :
response = client . post ( " /api/v1/login " , json = {
" username" : username , " password " : PASSWORD ,
" email" : email , " password " : PASSWORD ,
} )
assert response . status_code == 200
return { " X-CSRF-Token " : response . json ( ) [ " csrf_token " ] }
@ -151,9 +151,27 @@ def test_registration_smtp_approval_and_per_user_vm_isolation(monkeypatch, tmp_p
admin_headers = { " X-CSRF-Token " : initial . json ( ) [ " csrf_token " ] }
assert admin . get ( " /api/v1/session " ) . json ( ) [ " admin " ] is False
assert admin . get ( " /api/v1/smtp/settings " ) . status_code == 403
# The operator promotes the initial account manually in MariaDB.
# The operator promotes the initial account and adds its email in MariaDB.
store . users . promote ( " firstuser " )
assert admin . get ( " /api/v1/session " ) . json ( ) [ " admin " ] is True
initial_account = store . users . get_by_username ( " firstuser " )
assert initial_account [ " email " ] is None
with TestClient ( app , base_url = ORIGIN ) as missing_email :
assert missing_email . post ( " /api/v1/login " , json = {
" email " : " first@example.test " , " password " : PASSWORD ,
} ) . status_code == 401
store . set ( " test_user " , " firstuser " , json . dumps ( {
* * initial_account , " email " : " first@example.test " ,
} ) )
with TestClient ( app , base_url = ORIGIN ) as fresh_admin :
assert fresh_admin . post ( " /api/v1/login " , json = {
" username " : " firstuser " , " password " : PASSWORD ,
} ) . status_code == 422
assert fresh_admin . post ( " /api/v1/login " , json = {
" email " : " firstuser " , " password " : PASSWORD ,
} ) . status_code == 401
assert _login ( fresh_admin , " FIRST@EXAMPLE.TEST " )
assert fresh_admin . get ( " /api/v1/session " ) . json ( ) [ " admin " ] is True
smtp = admin . put ( " /api/v1/smtp/settings " , json = {
" host " : " smtp.example.test " , " port " : 587 , " tls_mode " : " starttls " ,
" from_address " : " panel@example.test " , " username " : " mailer " ,
@ -190,7 +208,7 @@ def test_registration_smtp_approval_and_per_user_vm_isolation(monkeypatch, tmp_p
with TestClient ( app , base_url = ORIGIN ) as first :
_register ( first , " one@example.test " , " tenantone " )
assert sent == [ ( " smtp.example.test " , " one@example.test " , " 123456 " ) ]
first_headers = _login ( first , " tenantone " )
first_headers = _login ( first , " ONE@EXAMPLE.TEST " )
assert first . get ( " /api/v1/session " ) . json ( ) [ " approved " ] is False
assert first . post ( " /api/v1/vms " , json = CREATE_VM ,
headers = first_headers ) . status_code == 403
@ -214,7 +232,7 @@ def test_registration_smtp_approval_and_per_user_vm_isolation(monkeypatch, tmp_p
with TestClient ( app , base_url = ORIGIN ) as second :
_register ( second , " two@example.test " , " tenanttwo " )
second_headers = _login ( second , " t enanttwo " )
second_headers = _login ( second , " t wo@example.test " )
second_id = store . users . get_by_username ( " tenanttwo " ) [ " id " ]
assert admin . post ( f " /api/v1/users/ { second_id } /approve " ,
headers = admin_headers ) . status_code == 200
@ -281,7 +299,7 @@ def test_registration_smtp_approval_and_per_user_vm_isolation(monkeypatch, tmp_p
console . receive_text ( )
assert revoked . value . code == 4403
first_headers = _login ( first , " tenantone " )
first_headers = _login ( first , " one@example.test " )
own_cookie = first . cookies . get ( " virsh_panel_session " )
with first . websocket_connect ( own_console , headers = {
" host " : " panel.example.test " , " origin " : ORIGIN ,