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

MarwanDebbiche / pylambdarest / 5255589737

pending completion
5255589737

push

github-actions

MarwanDebbiche
add CORS_ALLOW_CREDENTIALS config option

3 of 3 new or added lines in 1 file covered. (100.0%)

125 of 159 relevant lines covered (78.62%)

3.14 hits per line

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

72.0
/pylambdarest/config.py
1
# pylint: disable=C0103
2
"""
4✔
3
Config
4
------
5
Config object passed stored in App.
6

7
"""
8

9

10
from enum import Enum
4✔
11
from typing import Optional
4✔
12

13
from pylambdarest.exceptions import ConfigError
4✔
14

15

16
class AuthSchemeEnum(Enum):
4✔
17
    """
18
    Enumeration of the availables authentication schemes.
19
    """
20

21
    JWT_BEARER = "JWT_BEARER"
4✔
22

23

24
class AppConfig:  # pylint: disable=R0903
4✔
25
    """
26
    Store the application confifuration.
27

28
    """
29

30
    def __init__(  # pylint: disable=R0913
4✔
31
        self,
32
        AUTH_SCHEME: Optional[AuthSchemeEnum] = None,
33
        JWT_SECRET: Optional[str] = None,
34
        JWT_ALGORITHM: Optional[str] = None,
35
        ALLOW_CORS: bool = False,
36
        CORS_ORIGIN: Optional[str] = None,
37
        CORS_ALLOW_CREDENTIALS: Optional[bool] = None,
38
        has_jwt: Optional[bool] = None,
39
    ) -> None:
40
        self.AUTH_SCHEME: Optional[AuthSchemeEnum] = AUTH_SCHEME
4✔
41
        self.JWT_SECRET: Optional[str] = JWT_SECRET
4✔
42
        self.JWT_ALGORITHM: Optional[str] = JWT_ALGORITHM
4✔
43
        self.ALLOW_CORS: bool = ALLOW_CORS
4✔
44
        self.CORS_ORIGIN: Optional[str] = CORS_ORIGIN
4✔
45
        self.CORS_ALLOW_CREDENTIALS: Optional[bool] = CORS_ALLOW_CREDENTIALS
4✔
46

47
        if (self.AUTH_SCHEME == "JWT_BEARER") and (self.JWT_SECRET is None):
4✔
48
            raise ConfigError(
×
49
                "JWT_SECRET cannot be none if AUTH_SCHEME = 'JWT_BEARER'"
50
            )
51
        if self.AUTH_SCHEME == "JWT_BEARER":
4✔
52
            if has_jwt is False:
×
53
                raise ImportError(
×
54
                    "PyJWT should be installed when using "
55
                    "JWT_BEARER authentication scheme"
56
                )
57
            if self.JWT_ALGORITHM is None:
×
58
                self.JWT_ALGORITHM = "HS256"
×
59

60
        if (self.ALLOW_CORS) and (self.CORS_ORIGIN is None):
4✔
61
            raise ConfigError(
×
62
                "CORS_ORIGIN cannot be none if ALLOW_CORS is True. "
63
                "To allow all origins, set CORS_ORIGIN to '*'"
64
            )
65

66
        if self.ALLOW_CORS and self.CORS_ALLOW_CREDENTIALS is None:
4✔
67
            self.CORS_ALLOW_CREDENTIALS = False
×
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

© 2025 Coveralls, Inc