Skip to content

power/mfi_mpower: Fix url handling in get_credentials#1925

Merged
Bastian-Krause merged 1 commit into
labgrid-project:masterfrom
enkiusz:mfi-mpower-fix-get_credentials
Jul 7, 2026
Merged

power/mfi_mpower: Fix url handling in get_credentials#1925
Bastian-Krause merged 1 commit into
labgrid-project:masterfrom
enkiusz:mfi-mpower-fix-get_credentials

Conversation

@enkiusz

@enkiusz enkiusz commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Description

Before:

>>> url
'http://login:password@hostname:port/path;params?query=query#fragment'
>>> def get_credentials(base_url: str) -> Tuple[str, dict]:
...     base_url = urlparse(base_url)
...     if base_url.username is None or base_url.password is None:
...         credentials = dict(username='ubnt', password='ubnt')
...     else:
...         credentials = dict(username=base_url.username, password=base_url.password)
...         base_url._replace(netloc=base_url.netloc.replace(f'{base_url.username}:{base_url.password}@', ''))
...     base_url = base_url.geturl()
...     return (base_url, credentials)
... 
>>> get_credentials(url)
('http://login:password@hostname:port/path;params?query=query#fragment', {'username': 'login', 'password': 'password'})

After:

>>> url
'http://login:password@hostname:port/path;params?query=query#fragment'
>>> def get_credentials(base_url: str) -> Tuple[str, dict]:
...     base_url = urlparse(base_url)
...     if base_url.username is None or base_url.password is None:
...         credentials = dict(username='ubnt', password='ubnt')
...     else:
...         credentials = dict(username=base_url.username, password=base_url.password)
...         base_url = base_url._replace(netloc=base_url.netloc.replace(f'{base_url.username}:{base_url.password}@', ''))
...     base_url = base_url.geturl()
...     return (base_url, credentials)
... 
>>> get_credentials(url)
('http://hostname:port/path;params?query=query#fragment', {'username': 'login', 'password': 'password'})

Checklist

  • PR has been tested

Copilot AI review requested due to automatic review settings July 4, 2026 11:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes get_credentials() so that when a URL contains embedded username:password@, the returned base_url correctly strips the credentials while still returning them in the credentials dict. This aligns the driver’s behavior with the intended flow: credentials are used for login, but are not retained in the base URL used for subsequent requests.

Changes:

  • Assign the result of urlparse(...)._replace(...) back to base_url so the updated netloc is preserved.
  • Ensure get_credentials() returns a credential-free base_url when credentials are provided in the input URL.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Jul 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 61.0%. Comparing base (e7a4844) to head (e189aeb).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/driver/power/mfi_mpower.py 0.0% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##           master   #1925   +/-   ##
======================================
  Coverage    61.0%   61.0%           
======================================
  Files         182     182           
  Lines       14848   14848           
======================================
  Hits         9067    9067           
  Misses       5781    5781           
Flag Coverage Δ
3.10 61.0% <0.0%> (+<0.1%) ⬆️
3.11 61.0% <0.0%> (-0.1%) ⬇️
3.12 61.0% <0.0%> (+<0.1%) ⬆️
3.13 61.0% <0.0%> (-0.1%) ⬇️
3.14 61.0% <0.0%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Signed-off-by: Maciej Grela <enki@fsck.pl>
@enkiusz
enkiusz force-pushed the mfi-mpower-fix-get_credentials branch from 22f9500 to e189aeb Compare July 4, 2026 11:51
@Bastian-Krause
Bastian-Krause merged commit 6b46364 into labgrid-project:master Jul 7, 2026
10 of 11 checks passed
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.

3 participants