Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes tfa_host incorrectly splitting scheme #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

katzenbaer
Copy link

@katzenbaer katzenbaer commented Jul 9, 2023

The current implementation returns https rather than the scheme + host

@katzenbaer katzenbaer force-pushed the patch-1 branch 2 times, most recently from c791466 to 9a4637d Compare July 9, 2023 08:39
@@ -896,7 +896,7 @@ def _login(self):
# If token looks invalid we'll try the whole process.
get_new_session = days_until(self._expires_in) < 2
if get_new_session:
self._session = cloudscraper.create_scraper()
self._session = cloudscraper.create_scraper(ecdhCurve='secp384r1')
Copy link
Author

Choose a reason for hiding this comment

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

It's weird. This change is required for me when I run locally on my M1 mac, but it doesn't fix the auth issues when I run inside a docker container.

@twrecked
Copy link
Owner

twrecked commented Aug 3, 2023

Can you update and see if this is still needed?

Your request made me realise the code was wrong in several places so I fixed them all and added some unit tests to make sure I keep handling this correctly.

@katzenbaer
Copy link
Author

@twrecked Your changes wouldn't fix this issue because the Arlo2FARestAPI module still uses the tfa_host property which doesn't include the scheme.

https://github.com/twrecked/pyaarlo/blob/master/pyaarlo/tfa.py#L183C32-L183C40

Having a URL with a scheme is required for requests to work properly.

@katzenbaer
Copy link
Author

@twrecked I just pushed a proposed change to this PR that would fix the issue. Although, I'm not sure implying https as the scheme is correct. It might be better to have a method to extract the scheme from self._kw.get("tfa_host", TFA_DEFAULT_HOST) and then restore it. Or just have a method that doesn't remove the scheme to begin with. But I'll leave that decision to you.

@twrecked
Copy link
Owner

I noticed this the other day as well but have been too busy to fix so thanks for the PR. One comment, in Python the _ at the front is a user/community convention to indicate the function is use internally but this isn't enforced by the interpreter. PyCharm will complain about using it.

Maybe a new function? tfa_host_with_scheme?

@twrecked
Copy link
Owner

Can you try the master again?

@katzenbaer
Copy link
Author

Ah, that would work. I'm not sure if this is an edge-case you want to solve, but this test looks funny. I wouldn't imagine that it prepends https:// to a host specified with an IMAP port, but that's what it does from this test:

    def test_host_20(self):
        arlo = tests.arlo.PyArlo(tfa_host="imap.gmail.com:998")
        self.assertEqual(arlo.cfg.tfa_host, "imap.gmail.com")
        self.assertEqual(arlo.cfg.tfa_host_with_scheme, "https://imap.gmail.com")
        self.assertEqual(arlo.cfg.tfa_port, 998)

@katzenbaer
Copy link
Author

But since tfa_host_with_scheme isn't used outside the 2FA REST API code, it might be okay.

@katzenbaer
Copy link
Author

What about if tfa_host_with_scheme was a method instead with a scheme parameter? It would then pass this down to _add_scheme. I think that would make more sense since the caller knows the context (i.e. REST API) and can default it to https or imap or whatever.

I think inferring the scheme from ports could introduce more edge cases since some people might want to use port obfuscation.

@twrecked
Copy link
Owner

I think converting it to a method and adding the scheme is a good idea. And I'm always using odd ports so trying to pick the right scheme from the port might get complicated.

And the tests don't mean much I was just hoping it would do the right thing even if the results aren't meaningful.

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.

2 participants