• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

andgineer / api-db-prototype / 8766121206

20 Apr 2024 03:45PM UTC coverage: 83.956% (-2.9%) from 86.892%
8766121206

push

github

andgineer
upgrade reqs

2 of 2 new or added lines in 2 files covered. (100.0%)

89 existing lines in 23 files now uncovered.

1057 of 1259 relevant lines covered (83.96%)

0.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.0
/src/controllers/users/auth.py
1
"""Authenticates a user and returns a JWT token."""
2

3
from typing import Any, Dict
1✔
4

5
import db.conn
1✔
6
import db.models
1✔
7
import password_hash
1✔
8
import settings
1✔
9
from controllers.auth import JWT_EMAIL, JWT_GROUP
1✔
10
from controllers.helper import api_result, transaction
1✔
11
from controllers.models import APILogicError, APIUnauthError
1✔
12
from journaling import log
1✔
13
from jwt_token import JWT_CREATED, JWT_EXPIRATION, token
1✔
14

15

16
# mypy: disallow_untyped_decorators=False
17
@api_result
1✔
18
@transaction
1✔
19
def get_token(
1✔
20
    email: str,
21
    password: str,
22
    auth_token: Any = None,  # pylint: disable=unused-argument
23
) -> Dict[str, Any]:  # todo: remove auth_token
24
    """Return {"token": <JWT for the email/password>}."""
25
    assert settings.config
1✔
26
    user = db.models.User.by_email(email)
1✔
27
    if not user:
1✔
UNCOV
28
        log.debug(f"No user with email={email}")
×
UNCOV
29
        raise APILogicError(f"No user with email={email}")
×
30
    if not password_hash.verify(password, user.password_hash):
1✔
31
        log.debug(f"Invalid email/password for user {email}")
1✔
32
        raise APIUnauthError(f"Invalid email/password for user {email}")
1✔
33
    log.debug(f"Issuing JWT for {email}")
1✔
34
    payload = {
1✔
35
        JWT_EXPIRATION: token.datetime2jwt(
36
            settings.config.now() + settings.config.token_expiration_delta
37
        ),
38
        JWT_CREATED: token.datetime2jwt(settings.config.now()),
39
        JWT_EMAIL: user.email,
40
        JWT_GROUP: user.group.value,
41
    }
42
    assert "." not in payload["exp"]
1✔
43
    return {"token": token.encode(payload)}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc