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

localstack / localstack / 20565403496

29 Dec 2025 05:11AM UTC coverage: 84.103% (-2.8%) from 86.921%
20565403496

Pull #13567

github

web-flow
Merge 4816837a5 into 2417384aa
Pull Request #13567: Update ASF APIs

67166 of 79862 relevant lines covered (84.1%)

0.84 hits per line

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

95.24
/localstack-core/localstack/aws/handlers/auth.py
1
import logging
1✔
2

3
from localstack.aws.accounts import (
1✔
4
    get_account_id_from_access_key_id,
5
)
6
from localstack.constants import (
1✔
7
    AWS_REGION_US_EAST_1,
8
    DEFAULT_AWS_ACCOUNT_ID,
9
)
10
from localstack.http import Response
1✔
11
from localstack.utils.aws.request_context import (
1✔
12
    extract_access_key_id_from_auth_header,
13
    mock_aws_request_headers,
14
)
15

16
from ..api import RequestContext
1✔
17
from ..chain import Handler, HandlerChain
1✔
18

19
LOG = logging.getLogger(__name__)
1✔
20

21

22
class MissingAuthHeaderInjector(Handler):
1✔
23
    def __call__(self, chain: HandlerChain, context: RequestContext, response: Response):
1✔
24
        # FIXME: this is needed for allowing access to resources via plain URLs where access is typically restricted (
25
        #  e.g., GET requests on S3 URLs or apigateway routes). this should probably be part of a general IAM middleware
26
        #  (that allows access to restricted resources by default)
27
        if not context.service:
1✔
28
            return
×
29

30
        api = context.service.service_name
1✔
31
        headers = context.request.headers
1✔
32

33
        if not headers.get("Authorization"):
1✔
34
            headers["Authorization"] = mock_aws_request_headers(
1✔
35
                api, aws_access_key_id="injectedaccesskey", region_name=AWS_REGION_US_EAST_1
36
            )["Authorization"]
37

38

39
class AccountIdEnricher(Handler):
1✔
40
    """
41
    A handler that sets the AWS account of the request in the RequestContext.
42
    """
43

44
    def __call__(self, chain: HandlerChain, context: RequestContext, response: Response):
1✔
45
        # Obtain the access key ID
46
        access_key_id = (
1✔
47
            extract_access_key_id_from_auth_header(context.request.headers)
48
            or DEFAULT_AWS_ACCOUNT_ID
49
        )
50

51
        # Obtain the account ID from access key ID
52
        context.account_id = get_account_id_from_access_key_id(access_key_id)
1✔
53

54
        # Make Moto use the same Account ID as LocalStack
55
        context.request.headers.add("x-moto-account-id", context.account_id)
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