bluebutton-web-server icon indicating copy to clipboard operation
bluebutton-web-server copied to clipboard

BB2-3192: Added Accept-Language hearder to logging

Open stiwarisemanticbits opened this issue 9 months ago • 1 comments

JIRA Ticket: BB2-3192

User Story or Bug Summary:

Get language data into logging

What Does This PR Do?

Added Accept-Language header to logging

auth_language is already part of logging

  1. Go to http://localhost:8000/testclient/ (Make sure docker is running)
  2. Click on Get a Sample Authorization Token for v2
  3. Copy authorization link e.g http://localhost:8000/v2/o/authorize/?response_type=code&client_id=cx2SXi6ZLJAvn4hD7yHp9uRHkA00BamWZZwiwesl&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Ftestclient%2Fcallback&state=G95wjFI2jV1Bvxiqlwc78Q6EhrF3Hk
  4. Append &lang=es to above link
  5. Paste above link in browser and check logs, you will see below log
[15/May/2024 18:52:59] "GET /v1/o/authorize/?response_type=code&client_id=cx2SXi6ZLJAvn4hD7yHp9uRHkA00BamWZZwiwesl&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Ftestclient%2Fcallback&state=G95wjFI2jV1Bvxiqlwc78Q6EhrF3Hk&lang=es HTTP/1.1" 302 0
/tmp/venv/lib/python3.8/site-packages/urllib3/connectionpool.py:1061: InsecureRequestWarning: Unverified HTTPS request is being made to host 'test.accounts.cms.gov'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
  warnings.warn(
2024-05-15 18:52:59,788 INFO [26] audit.hhs_oauth_server.request_logging line:81 {
  "access_token_hash": "",
  "app_id": "1",
  "app_name": "TestApp",
  "auth_app_data_access_type": "THIRTEEN_MONTH",
  "auth_app_id": "1",
  "auth_app_name": "TestApp",
  "auth_client_id": "cx2SXi6ZLJAvn4hD7yHp9uRHkA00BamWZZwiwesl",
  "auth_language": "es",
  "auth_require_demographic_scopes": "True",
  "auth_uuid": "fc44d224-85e9-45ff-a81e-b18b6ccaa028",
  "dev_id": "",
  "dev_name": "",
  "elapsed": 0.17141294479370117,
  "end_time": 1715799179.788512,
  "ip_addr": "192.168.65.1",
  "location": "https://test.medicare.gov/sso/authorize?client_id=bb2api&relay=36535236347951237888771649&redirect_uri=http%3A//localhost%3A8000/mymedicare/sls-callback&lang=es-mx",
  "path": "/mymedicare/login",
  "req_header_accept_encoding": "gzip, deflate, br, zstd",
  "req_header_accept_language": "en-US,en;q=0.9",
  "req_header_content_type": "text/plain",
  "req_header_host": "localhost:8000",
  "req_header_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
  "request_method": "GET",
  "request_scheme": "http",
  "request_uuid": "59931e46-12ec-11ef-9d87-0242ac1c0003",
  "response_code": 302,
  "size": 0,
  "start_time": 1715799179.617101,
  "type": "request_response_middleware"
}

To view accept header in logs

  1. Go to http://localhost:8000/testclient/ (Make sure docker is running)
  2. Click on Get a Sample Authorization Token for v2
  3. Click on authorize as beneficiary and you will see logs with accept language. See example below
2024-05-15 19:09:53,993 INFO [39] audit.hhs_oauth_server.request_logging line:81 {
  "access_token_hash": "",
  "app_id": "",
  "app_name": "",
  "dev_id": "",
  "dev_name": "",
  "elapsed": 0.04573988914489746,
  "end_time": 1715800193.993144,
  "ip_addr": "192.168.65.1",
  "location": "",
  "path": "/testclient/authorize-link",
  "req_header_accept_encoding": "gzip, deflate, br, zstd",
  "req_header_accept_language": "en-US,en;q=0.9",
  "req_header_content_type": "text/plain",
  "req_header_host": "localhost:8000",
  "req_header_referrer": "http://localhost:8000/testclient/",
  "req_header_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
  "request_method": "GET",
  "request_scheme": "http",
  "request_uuid": "b629a560-12ee-11ef-a514-0242ac1c0003",
  "response_code": 200,
  "size": 59187,
  "start_time": 1715800193.947406,
  "type": "request_response_middleware"
}

What Should Reviewers Watch For?

If you're reviewing this PR, please check these things, in particular:

  • TODO

What Security Implications Does This PR Have?

Submitters should complete the following questionnaire:

  • If the answer to any of the questions below is Yes, then here's a link to the associated Security Impact Assessment (SIA), security checklist, or other similar document in Confluence: N/A.
    • Does this PR add any new software dependencies? Yes or No.
    • Does this PR modify or invalidate any of our security controls? Yes or No.
    • Does this PR store or transmit data that was not stored or transmitted before? Yes or No.
  • If the answer to any of the questions below is Yes, then please add StewGoin as a reviewer, and note that this PR should not be merged unless/until he also approves it.
    • Do you think this PR requires additional review of its security implications for other reasons? Yes or No.

What Needs to Be Merged and Deployed Before this PR?

This PR cannot be either merged or deployed until the following pre-requisite changes have been fully deployed:

  • CMSgov/some_repo#42

Any Migrations?

  • [ ] Yes, there are migrations
    • [ ] The migrations should be run PRIOR to the code being deployed
    • [ ] The migrations should be run AFTER the code is deployed
    • [ ] There is a more complicated migration plan (downtime, etc)
  • [ ] No migrations

Submitter Checklist

I have gone through and verified that...:

  • [ ] This PR is reasonably limited in scope, to help ensure that:
    1. It doesn't unnecessarily tie a bunch of disparate features, fixes, refactorings, etc. together.
    2. There isn't too much of a burden on reviewers.
    3. Any problems it causes have a small "blast radius".
    4. It'll be easier to rollback if that becomes necessary.
  • [ ] I have named this PR and its branch such that they'll be automatically be linked to the (most) relevant Jira issue, per: https://confluence.atlassian.com/adminjiracloud/integrating-with-development-tools-776636216.html.
  • [ ] This PR includes any required documentation changes, including README updates and changelog / release notes entries.
  • [ ] All new and modified code is appropriately commented, such that the what and why of its design would be reasonably clear to engineers, preferably ones unfamiliar with the project.
  • [ ] All tech debt and/or shortcomings introduced by this PR are detailed in TODO and/or FIXME comments, which include a JIRA ticket ID for any items that require urgent attention.
  • [ ] Reviews are requested from both:
    • At least two other engineers on this project, at least one of whom is a senior engineer or owns the relevant component(s) here.
    • Any relevant engineers on other projects (e.g. BFD, SLS, etc.).
  • [ ] Any deviations from the other policies in the DASG Engineering Standards are specifically called out in this PR, above.
    • Please review the standards every few months to ensure you're familiar with them.

stiwarisemanticbits avatar May 15 '24 19:05 stiwarisemanticbits