island: Remove UserCreds.from_cleartext()
This commit is contained in:
parent
f73b048169
commit
0f49a2c96a
|
@ -2,8 +2,6 @@ from __future__ import annotations
|
|||
|
||||
from typing import Dict
|
||||
|
||||
import bcrypt
|
||||
|
||||
from monkey_island.cc.resources.auth.auth_user import User
|
||||
|
||||
|
||||
|
@ -25,9 +23,3 @@ class UserCreds:
|
|||
|
||||
def to_auth_user(self) -> User:
|
||||
return User(1, self.username, self.password_hash)
|
||||
|
||||
@classmethod
|
||||
def from_cleartext(cls, username, cleartext_password):
|
||||
password_hash = bcrypt.hashpw(cleartext_password.encode("utf-8"), bcrypt.gensalt()).decode()
|
||||
|
||||
return cls(username, password_hash)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import json
|
||||
|
||||
import bcrypt
|
||||
import flask_restful
|
||||
from flask import make_response, request
|
||||
|
||||
|
@ -27,5 +28,6 @@ def _get_user_credentials_from_request(request):
|
|||
|
||||
username = cred_dict.get("user", "")
|
||||
password = cred_dict.get("password", "")
|
||||
password_hash = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode()
|
||||
|
||||
return UserCreds.from_cleartext(username, password)
|
||||
return UserCreds(username, password_hash)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import bcrypt
|
||||
|
||||
from monkey_island.cc.environment.user_creds import UserCreds
|
||||
|
||||
TEST_USER = "Test"
|
||||
|
@ -41,16 +39,7 @@ def test_to_auth_user_full_credentials():
|
|||
assert auth_user.secret == TEST_HASH
|
||||
|
||||
|
||||
def test_get_from_cleartext(monkeypatch):
|
||||
monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT)
|
||||
|
||||
creds = UserCreds.from_cleartext(TEST_USER, "Test_Password")
|
||||
assert creds.password_hash == "$2b$12$JA7GdT1iyfIsquF2cTZv2.NdGFuYbX1WGfQAOyHlpEsgDTNGZ0TXG"
|
||||
|
||||
|
||||
def test_member_values(monkeypatch):
|
||||
monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT)
|
||||
|
||||
creds = UserCreds(TEST_USER, TEST_HASH)
|
||||
assert creds.username == TEST_USER
|
||||
assert creds.password_hash == TEST_HASH
|
||||
|
|
Loading…
Reference in New Issue