Skip to content

Conversation

@jd-au
Copy link
Contributor

@jd-au jd-au commented Apr 30, 2022

This replaces the custom login in CASDA with use of QueryWithLogin.

@pep8speaks
Copy link

pep8speaks commented Apr 30, 2022

Hello @jd-au! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-05-06 00:38:43 UTC

@jd-au jd-au added this to the v0.4.7 milestone Apr 30, 2022
@codecov
Copy link

codecov bot commented Apr 30, 2022

Codecov Report

Merging #2386 (740b05a) into main (f20c85b) will decrease coverage by 0.04%.
The diff coverage is 46.15%.

@@            Coverage Diff             @@
##             main    #2386      +/-   ##
==========================================
- Coverage   62.87%   62.83%   -0.05%     
==========================================
  Files         133      133              
  Lines       17246    17264      +18     
==========================================
+ Hits        10844    10848       +4     
- Misses       6402     6416      +14     
Impacted Files Coverage Δ
astroquery/casda/core.py 87.85% <46.15%> (-5.16%) ⬇️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

'and CASDA_PASSWD environment variables)')
def test_stage_data(self):
'and CASDA_PASSWD environment variables or password in keyring)')
def test_stage_data(self, cached_credentials):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've shown two approaches to credentials for the remote tests. However there is no keyring backend on the CI server, so I am thinking of removing this approach based around the keyring.

Copy link
Member

Choose a reason for hiding this comment

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

If there is any "test" user that we could use, I'm happy to set up github tokens that the CI will have access to. But that definitely seems to be something beyond this PR, so any approach that works for now sounds good on my end (e.g. you have real login credentials and say that these tests pass, I'm happy with it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've run these tests with real credentials and they pass. These remote tests now require the keyring so they can't be run on the github CI environment.

return self._complete_job(job_url, verbose)

def cutout(self, table, *, coordinates=None, radius=None, height=None,
def cutout(self, table, *, coordinates=None, radius=1*u.arcmin, height=None,
Copy link
Member

Choose a reason for hiding this comment

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

I think this was accidentally pulled in with one of the merge commits, please rebase to get rid of those and any unrelated changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The commit was intentional - just cleaning up a minor aspect that was missed in the last PR

'and CASDA_PASSWD environment variables)')
def test_stage_data(self):
'and CASDA_PASSWD environment variables or password in keyring)')
def test_stage_data(self, cached_credentials):
Copy link
Member

Choose a reason for hiding this comment

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

If there is any "test" user that we could use, I'm happy to set up github tokens that the CI will have access to. But that definitely seems to be something beyond this PR, so any approach that works for now sounds good on my end (e.g. you have real login credentials and say that these tests pass, I'm happy with it).

self._authenticated = False

def _login(self, *, username=None, store_password=False,
reenter_password=False, password=None):
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit torn here as we're not at all consistent in the library as a whole, but having the password in the signature seems a bit of a counter-effective of security. I think I best like how the alma module is set up in this regard. What do you all think, am I just overly cautious?

@keflavich @andamian @pllim

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the password param to allow testing of the login as there is no keyring backend in the CI environment. I couldn't see anyone else testing the login path. I agree the password param should not be used by other users, so perhaps either a "For testing use only" note in the method's docstring, or hiding it in a **kwargs would be better?

Copy link
Member

Choose a reason for hiding this comment

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

👎 to explicit password argument in API. Might as well set up the backend to handle anonymous login without a password, or enable a more secure way (encrypted token) for the CI. Or just not test this at all in the CI and set up something private server-side to test this securely.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Backend changes are out of scope for this piece of work unfortunately. I've removed the password parameter and the tests for the login code. For the other test code which requires login I have added a utility to simulate the login result.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Thank you. I opened #2391 with the aim of tracking this password in API issue for the other affected modules, and finding an acceptable backend solution for testing (very much beyond the scope for this PR) has already have one opened one in #2367.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A consequence of removing the tests relying on the password parameter is that I can't achieve the code coverage target, so the CodeCov checks will fail unfortunately. The untested code occurs after the call to the keyring which would fail as there is no keyring backend in the GitHub CI environment.

Copy link
Member

@bsipocz bsipocz May 6, 2022

Choose a reason for hiding this comment

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

yeah, no worries about the coverage test, those are not run with remote-data anyway, so always show a much smaller percentage as the reality.

I'll open a follow-up issue to get a backend installed in the VM, it shouldn't be too hard (though populating it may not be trivial).

Comment on lines 139 to 142
with pytest.raises(LoginError) as excinfo:
Casda.login()

assert "If you do not pass a username to login()," in str(excinfo.value)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
with pytest.raises(LoginError) as excinfo:
Casda.login()
assert "If you do not pass a username to login()," in str(excinfo.value)
with pytest.raises(LoginError, match=r"If you do not pass a username to login\(\),") as excinfo:
Casda.login()

Copy link
Contributor Author

@jd-au jd-au May 4, 2022

Choose a reason for hiding this comment

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

I've made this change for all exception tests

@bsipocz
Copy link
Member

bsipocz commented May 6, 2022

I'm sorry for merging the conflicting PR before this one, I missed noticing that it will cause issues. However, I'll go ahead and rebase this before merge to get a clear, linear history instead of the 3 merges.

@bsipocz bsipocz force-pushed the CASDA-Use-QueryWithLogin branch from ed57149 to 95b41d1 Compare May 6, 2022 00:34
@bsipocz
Copy link
Member

bsipocz commented May 6, 2022

(It looks like the email address you did these commits are not recognized by github, thus the weird avatar listing on them. In the git history, they all look good, with you as the author. I guess your avatar would also come up if you were to add that other email address to your GH account (you can have multiple ones associated)).

@jd-au
Copy link
Contributor Author

jd-au commented May 6, 2022

(It looks like the email address you did these commits are not recognized by github, thus the weird avatar listing on them. It the git history it all look good, with you as author. I guess your avatar would also come up if you were to add that other email address to your GH account (you can have multiple ones associated)).

Thanks for letting me know. I've corrected it locally now but will also update my GH account.

Copy link
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

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

The remaining follow-up item requires to get keyring work on CI, so I would not hold this up any longer.

@bsipocz
Copy link
Member

bsipocz commented May 6, 2022

When running the tests with remote-data=any, the coverage is indeed much higher, 88%.

I'll look into installing a keyring backend to CI, but that should not hold this one up.

@bsipocz bsipocz merged commit ad6cb80 into astropy:main May 6, 2022
@bsipocz
Copy link
Member

bsipocz commented May 6, 2022

Thank you @jd-au!

@jd-au
Copy link
Contributor Author

jd-au commented May 6, 2022

Once the keyring backend is installed I'll be able to use the cached_credentials fixture from the remote tests to test the login code properly.

Thanks @bsipocz

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants