示例#1
0
async def _():
    user = User(
        id=1,
        email="*****@*****.**",
        name="Name",
        is_staff=False,
        is_active=True,
        date_joined=datetime.utcnow(),
    )

    repository = FakeUsersRepository(users=[user])

    with patch(
            "users.auth.entities.get_jwt_metadata",
            return_value={
                "exp": datetime(1980, 1, 1),
                "iat": datetime(1980, 1, 1)
            },
    ):
        jwt_token = user.generate_token()

    request = MagicMock()
    request.headers = {"Authorization": f"Bearer {jwt_token}"}

    with raises(AuthenticationError):
        await JWTAuthBackend(repository).authenticate(request)
示例#2
0
async def _():
    user = User(
        id=1,
        email="*****@*****.**",
        name="Name",
        is_staff=False,
        is_active=False,
        date_joined=datetime.utcnow(),
    )

    repository = FakeUsersRepository(users=[user])

    jwt_token = user.generate_token()

    request = MagicMock()
    request.headers = {"Authorization": f"Bearer {jwt_token}"}

    with raises(AuthenticationError):
        await JWTAuthBackend(repository).authenticate(request)
示例#3
0
async def _():
    user = User(
        id=1,
        email="*****@*****.**",
        name="Name",
        is_staff=False,
        date_joined=datetime.utcnow(),
    )

    repository = FakeUsersRepository(users=[user])

    jwt_token = user.generate_token()

    request = MagicMock()
    request.headers = {"Authorization": f"Bearer {jwt_token}"}

    credentials, logged_user = await JWTAuthBackend(repository).authenticate(
        request)

    assert credentials.scopes == [Credential.AUTHENTICATED]
    assert logged_user.id == user.id
示例#4
0
 def force_login(self, user: entities.User):
     self.auth_token = user.generate_token()
示例#5
0
 def from_domain(cls, user: entities.User) -> LoginSuccess:
     return cls(user=User.from_domain(user), token=user.generate_token())