Skip to content

Commit

Permalink
tests: fussy netrc test tweaks (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski authored Apr 14, 2021
1 parent 644d7d8 commit db1d8d5
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,34 +193,31 @@ include("setup.jl")
end

@testset "netrc support" begin

auth_url = "$server/basic-auth/user/passwd"
user = "gVvkQiHN62"
passwd = "dlctfSMTno8n"
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://
hostname = match(r"^\w+://([^/]+)"i, server).captures[1]

This comment has been minimized.

Copy link
@evetion

evetion Apr 14, 2021

Member

🥇

This comment has been minimized.

Copy link
@StefanKarpinski

StefanKarpinski Apr 14, 2021

Author Member

I grew up on Perl so regexes are a reflex 😁

netrc = tempname()
open(netrc, "w") do io
write(io, "machine $servername login user password passwd\n")
write(io, "machine $hostname 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
downloader.easy_hook = (easy, info) ->
Curl.setopt(easy, Curl.CURLOPT_NETRC_FILE, netrc)

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
rm(netrc)
end

@testset "file protocol" begin
Expand Down

0 comments on commit db1d8d5

Please sign in to comment.