Browse Source

Updated nidhoggr_core to 0.4.1

tags/0.7.1
parent
commit
86b7159c32
Signed by: Andriy Kushnir (Orhideous) <[email protected]> GPG Key ID: 62E078AB621B0D15
6 changed files with 19 additions and 13 deletions
  1. +4
    -0
      HISTORY.md
  2. +3
    -3
      nidhoggr/utils/repository.py
  3. +4
    -2
      nidhoggr/views/auth.py
  4. +1
    -1
      requirements.txt
  5. +1
    -1
      setup.py
  6. +6
    -6
      tests/conftest.py

+ 4
- 0
HISTORY.md View File

@@ -1,5 +1,9 @@
# History

## 0.7.1 (2020-01-09)

* Updated nidhoggr_core to 0.4.1

## 0.7.0 (2020-01-07)

* **Breaking** Be aware of StatusResponse returned from repository

+ 3
- 3
nidhoggr/utils/repository.py View File

@@ -1,12 +1,12 @@
from typing import Union, TypeVar

from nidhoggr_core.response import StatusResponse
from nidhoggr_core.response import ErrorResponse
from werkzeug.exceptions import InternalServerError

T = TypeVar("T")


def handle_status(repository_response: Union[StatusResponse, T]) -> T:
if isinstance(repository_response, StatusResponse):
def handle_status(repository_response: Union[ErrorResponse, T]) -> T:
if isinstance(repository_response, ErrorResponse):
raise InternalServerError(description=repository_response.reason)
return repository_response

+ 4
- 2
nidhoggr/views/auth.py View File

@@ -22,7 +22,8 @@ def authenticate(
if user is None:
return InvalidCredentials

if not users.check_password(clean=req.password, uuid=user.uuid).status:
password_check = handle_status(users.check_password(clean=req.password, uuid=user.uuid))
if not password_check.status:
return InvalidCredentials

if not config.simple_login and req.username == user.login:
@@ -120,7 +121,8 @@ def signout(req: auth.SignOutRequest, users: BaseUserRepo) -> Union[auth.EmptyRe
if user is None:
return InvalidCredentials

if not users.check_password(clean=req.password, uuid=user.uuid).status:
password_check = handle_status(users.check_password(clean=req.password, uuid=user.uuid))
if not password_check.status:
return InvalidCredentials

user = user.copy(update=dict(access=None))

+ 1
- 1
requirements.txt View File

@@ -1,4 +1,4 @@
Flask>=1.1
nidhoggr_core>=0.3.0
nidhoggr_core>=0.4.1
pydantic>=1.3
M2Crypto>=0.35

+ 1
- 1
setup.py View File

@@ -11,7 +11,7 @@ test_requirements = Path('requirements_dev.txt').read_text().splitlines()

setup(
name="nidhoggr",
version="0.7.0",
version="0.7.1",
license="MIT",
description="Yggdrasil protocol implementation",
long_description=readme + '\n\n' + history,

+ 6
- 6
tests/conftest.py View File

@@ -7,7 +7,7 @@ from typing import Optional, Dict, Any, Union, Callable, TypeVar
import pytest
from flask import url_for, Response, Flask
from flask.testing import FlaskClient
from nidhoggr_core.response import StatusResponse
from nidhoggr_core.response import StatusResponse, ErrorResponse

from nidhoggr.application import create_app
from nidhoggr_core.user import User
@@ -89,7 +89,7 @@ class TestUserRepo(BaseUserRepo):
def __init__(self, *, users):
self.__users = {user.uuid: user.copy() for user in users}

def get_user(self, **kw: Dict[str, str]) -> Union[StatusResponse, Optional[User]]:
def get_user(self, **kw: Dict[str, str]) -> Union[ErrorResponse, Optional[User]]:
res = [
u
for u
@@ -98,18 +98,18 @@ class TestUserRepo(BaseUserRepo):
]
return (res or [None])[0]

def save_user(self, *, user: TestUser) -> StatusResponse:
def save_user(self, *, user: TestUser) -> Union[ErrorResponse, User]:
self.__users[user.uuid] = user
return StatusResponse()
return user

def check_password(self, *, clean: str, uuid: str) -> StatusResponse:
def check_password(self, *, clean: str, uuid: str) -> Union[ErrorResponse, StatusResponse]:
user = self.get_user(uuid=uuid)
status = user and user.password == clean
return StatusResponse(status=status)


class TestTextureRepo(BaseTextureRepo):
def get(self, *, uuid: str) -> Union[StatusResponse, Dict[TextureType, TextureItem]]:
def get(self, *, uuid: str) -> Union[ErrorResponse, Dict[TextureType, TextureItem]]:
return {}



Loading…
Cancel
Save