Skip to content

fix: ignore a UTF-8 BOM in the Vault token file - #117

Open
Partha-Shankar wants to merge 1 commit into
dbpedia:mainfrom
Partha-Shankar:fix/vault-token-bom
Open

Partha-Shankar wants to merge 1 commit into
dbpedia:mainfrom
Partha-Shankar:fix/vault-token-bom

Conversation

@Partha-Shankar

@Partha-Shankar Partha-Shankar commented Nov 25, 2026 •

Copy link
Copy Markdown

Pull Request

Description

__get_vault_access__ reads the Vault refresh-token file with open(token_file, "r"). Without an explicit encoding Python uses the locale codec (cp1252 on Windows), and .strip() does not remove a UTF-8 byte-order mark. So a token file saved with a BOM (for example by Windows PowerShell 5.1 Set-Content -Encoding UTF8) is sent to the token endpoint as eyJ… on Windows (eyJ… on Linux). The token request then fails and the download stops with a requests.HTTPError.

This PR opens the file with encoding="utf-8-sig", the encoding the other text reads in the package already use (cli.py, manifest/replay.py, workflow/parser.py, filehandling/format.py). Files without a BOM are read exactly as before.

It also adds a parametrized test to tests/test_download_auth.py (token file with and without a BOM, requests.post mocked) that checks the refresh token sent in the first token request. The BOM case fails on main on Windows and on Linux.

No version bump, following #103; I can add one if you want it.

Related Issues
No existing issue. Same kind of fix as #103 (UTF-8 BOM in CSV/TSV).

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • This change requires a documentation update
  • Housekeeping

Checklist:

  • My code follows the ruff code style of this project.
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas (one-line change; the test has a comment)
  • I have made corresponding changes to the documentation (if applicable) (not applicable)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
    • pytest - all tests passed (280 passed, 3 skipped on Windows, Python 3.11, with and without PYTHONUTF8=1; I installed with pip instead of Poetry)
    • ruff check - no linting errors (ruff 0.5.7)

Summary by CodeRabbit

  • Bug Fixes
    • Fixed reading vault refresh tokens from files that include a UTF-8 byte-order mark or Windows-style line endings.

Read the refresh-token file with encoding="utf-8-sig" like the other text reads in the package. A BOM (e.g. from PowerShell 5.1 Set-Content -Encoding UTF8) was sent as part of the token. Adds a regression test.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Vault refresh tokens read from files now use UTF-8-with-BOM decoding. A parametrized test checks files with and without a BOM and verifies that the exchange receives the token without the BOM or CRLF ending.

Changes: Vault token file handling

Layer / File(s) Summary
Read and validate the refresh token
databusclient/api/download.py, tests/test_download_auth.py
The token-file reader uses utf-8-sig. The test checks the token sent to the mocked exchange for BOM and non-BOM files containing CRLF endings.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: integer-ctrl

Merge Risk: Minimal · up to 3b820

This change makes Vault token files with a UTF-8 BOM, such as those written by Windows PowerShell, work correctly. Files without a BOM behave as before. No merge-blocking risk is identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the Vault token file is now read so that a UTF-8 BOM is ignored. The raw summary confirms the change to read the token file with utf-8-sig and a test for token files w…
Description check Passed The description follows the repository template. It explains the problem and the fix, and it names the new test. It gives a related issue reference (none exists, and the author links the similar fix i…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: the Vault token file is now read so that a UTF-8 BOM is ignored. The raw summary confirms the change to read the token file with utf-8-sig and a test for token files with and without a BOM. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description follows the repository template. It explains the problem and the fix, and it names the new test. It gives a related issue reference (none exists, and the author links the similar fix in #103). The type of change is marked as Bug fix. The checklist is filled in, and the author notes the one unchecked item (code comments: the one-line change has a test comment). The documentation item is marked not applicable. The template sections are all present and mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7e1708df-73bf-4b38-ba8b-002b5d5c3c06
Commits

Reviewing files that changed from the base of the PR and between b35bd2c and 3b82009.

Files selected for processing: 2

  • databusclient/api/download.py
  • tests/test_download_auth.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant