# This test exercises the GOAUTH mechanism for specifying
# credentials passed in HTTPS requests to VCS servers.
# See golang.org/issue/26232

env GOPROXY=direct
env GOSUMDB=off

# GOAUTH should default to netrc behavior.
# Without credentials, downloading a module from a path that requires HTTPS
# basic auth should fail.
# Override default location of $HOME/.netrc
env NETRC=$WORK/empty
! go get vcs-test.golang.org/auth/or401
stderr '^\tserver response: ACCESS DENIED, buddy$'

# With credentials from a netrc file, it should succeed.
env NETRC=$WORK/netrc
go get vcs-test.golang.org/auth/or401

# GOAUTH=off should result in failures.
env GOAUTH='off'
# Without credentials, downloading a module from a path that requires HTTPS
# basic auth should fail.
env NETRC=$WORK/empty
! go get vcs-test.golang.org/auth/or401
stderr '^\tserver response: ACCESS DENIED, buddy$'

# GOAUTH='off' should ignore credentials from a valid netrc file.
env GOAUTH='off'
env NETRC=$WORK/netrc
! go get vcs-test.golang.org/auth/or401
stderr '^\tserver response: ACCESS DENIED, buddy$'

# GOAUTH=off cannot be combined with other authentication commands
env GOAUTH='off; netrc'
env NETRC=$WORK/netrc
! go get vcs-test.golang.org/auth/or401
stderr 'GOAUTH=off cannot be combined with other authentication commands \(GOAUTH=off; netrc\)'

# An unset GOAUTH should default to netrc.
env GOAUTH=
# Without credentials, downloading a module from a path that requires HTTPS
# basic auth should fail.
env NETRC=$WORK/empty
! go get vcs-test.golang.org/auth/or401
stderr '^\tserver response: ACCESS DENIED, buddy$'

# With credentials from a netrc file, it should succeed.
env NETRC=$WORK/netrc
go get vcs-test.golang.org/auth/or401

# A missing file should be fail as well.
env NETRC=$WORK/missing
! go get vcs-test.golang.org/auth/or401
stderr '^\tserver response: ACCESS DENIED, buddy$'

[short] skip 'requires a remote vcs lookup'
[!git] skip
# An unset home directory should warn the user but not cause a failure.
env NETRC=
env HOME=
env USERPROFILE=
env home=
go get -x vcs-test.golang.org/git/emptytest.git
[!GOOS:windows] [!GOOS:plan9] stderr 'GOAUTH=netrc: \$HOME is not defined'
[GOOS:windows] stderr 'GOAUTH=netrc: \%userprofile\% is not defined'
[GOOS:plan9] stderr 'GOAUTH=netrc: \$home is not defined'

-- go.mod --
module private.example.com
-- $WORK/empty --
-- $WORK/netrc --
machine vcs-test.golang.org
	login aladdin
	password opensesame
# first one should override this one
machine vcs-test.golang.org
	login aladdin
	password ignored