-
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Try to use .netrc if available and enable session cookies by default #98
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ac36960
Try to use .netrc if available
evetion de7efaa
Also enable cookies by default.
evetion fed2492
Merged and added tests.
evetion f578143
Disable verbosity.
evetion b4fcfd0
Can't use Julia 1.6 syntax here.
evetion ea96862
Use temporary file for .netrc.
evetion 44a8923
Forgot to remove joinpath
evetion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,6 +177,52 @@ include("setup.jl") | |
end | ||
end | ||
|
||
@testset "session support" begin | ||
downloader = Downloader() | ||
|
||
# This url will redirect to /cookies, which echoes the set cookies as json | ||
set_cookie_url = "$server/cookies/set?k1=v1&k2=v2" | ||
cookies = download_json(set_cookie_url, downloader=downloader) | ||
@test get(cookies, "k1", "") == "v1" | ||
@test get(cookies, "k2", "") == "v2" | ||
|
||
# As the handle is destroyed, subsequent requests have no cookies | ||
cookie_url = "$server/cookies" | ||
cookies = download_json(cookie_url, downloader=downloader) | ||
@test isempty(cookies) | ||
end | ||
|
||
@testset "netrc support" begin | ||
|
||
auth_url = "$server/basic-auth/user/passwd" | ||
resp = request(auth_url) | ||
@test resp isa Response | ||
@test resp.status == 401 # no succesful authentication | ||
|
||
# Setup .netrc | ||
servername = split(server, "/")[end] # strip https:// | ||
netrc = tempname() | ||
open(netrc, "w") do io | ||
write(io, "machine $servername login user password passwd\n") | ||
end | ||
|
||
# Setup config to point to custom .netrc (normally in ~/.netrc) | ||
downloader = Downloads.Downloader() | ||
easy_hook = (easy, info) -> begin | ||
Downloads.Curl.setopt( | ||
easy, | ||
Downloads.Curl.CURLOPT_NETRC_FILE, netrc) | ||
end | ||
downloader.easy_hook = easy_hook | ||
|
||
resp = request(auth_url, throw=false, downloader=downloader) | ||
@test resp isa Response | ||
@test resp.status == 200 # succesful authentication | ||
|
||
# Cleanup | ||
rm(netrc) # isn't cleaned automatically on Julia 1.3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Best practice to explicitly delete it anyway. |
||
end | ||
|
||
@testset "file protocol" begin | ||
@testset "success" begin | ||
path = tempname() | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to have a control test for this, but it seems there's no way to actually disable the cookie engine once set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about
setopt(easy, CURLOPT_COOKIEFILE, C_NULL)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem to work, this fails:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. That's a shame. I guess we don't strictly need the control. I may file an issue with libcurl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed: curl/curl#6889
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, that's quite productive. Do you want to wait for a fix (and subsequent release?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we should proceed without it since it's a bunch of effort to update the library version (new BinaryBuilder release, bumping version in Julia's makefiles, checksum updates — it's a whole process).