Skip to content

Commit 5424f2e

Browse files
samthanawallagopherbot
authored andcommitted
cmd/go: add more tests for GOAUTH's user provided authenticator
For #26232 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Change-Id: I4b6eb63d4c1d71983e1ae764a6a38744a5f01317 Reviewed-on: https://go-review.googlesource.com/c/go/+/635255 Auto-Submit: Sam Thanawalla <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent d5c1333 commit 5424f2e

File tree

1 file changed

+75
-19
lines changed

1 file changed

+75
-19
lines changed

src/cmd/go/testdata/script/goauth_userauth.txt

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33

44
env GOPROXY=direct
55
env GOSUMDB=off
6-
7-
# Use a custom authenticator to provide custom credentials
86
mkdir $WORK/bin
97
env PATH=$WORK/bin${:}$PATH
10-
cd auth
11-
go build -o $WORK/bin/my-auth$GOEXE .
12-
cd ..
138

149
# Without credentials, downloading a module from a path that requires HTTPS
1510
# basic auth should fail.
@@ -21,16 +16,65 @@ stderr '^\tserver response: ACCESS DENIED, buddy$'
2116
! go mod tidy
2217
stderr '^\tserver response: ACCESS DENIED, buddy$'
2318

24-
# With credentials from the my-auth binary, it should succeed.
25-
env GOAUTH='my-auth'$GOEXE' --arg1 "value with spaces"'
19+
# Initial invocation of authenticator is successful.
20+
go build -o $WORK/bin/basic$GOEXE scripts/basic.go
21+
# With credentials from the binary, it should succeed.
22+
env GOAUTH='basic'$GOEXE
23+
cp go.mod.orig go.mod
24+
go get vcs-test.golang.org/auth/or401
25+
# go imports should resolve correctly as well.
26+
go mod tidy
27+
go list all
28+
stdout vcs-test.golang.org/auth/or401
29+
30+
# Second invocation of authenticator is successful.
31+
go build -o $WORK/bin/reinvocation$GOEXE scripts/reinvocation.go
32+
# With credentials from the binary, it should succeed.
33+
env GOAUTH='reinvocation'$GOEXE
2634
cp go.mod.orig go.mod
2735
go get vcs-test.golang.org/auth/or401
2836
# go imports should resolve correctly as well.
2937
go mod tidy
3038
go list all
3139
stdout vcs-test.golang.org/auth/or401
3240

33-
-- auth/main.go --
41+
# Authenticator can parse arguments correctly.
42+
go build -o $WORK/bin/arguments$GOEXE scripts/arguments.go
43+
# With credentials from the binary, it should succeed.
44+
env GOAUTH='arguments'$GOEXE' --arg1 "value with spaces"'
45+
cp go.mod.orig go.mod
46+
go get vcs-test.golang.org/auth/or401
47+
# go imports should resolve correctly as well.
48+
go mod tidy
49+
go list all
50+
stdout vcs-test.golang.org/auth/or401
51+
52+
# Authenticator provides bad credentials.
53+
go build -o $WORK/bin/invalid$GOEXE scripts/invalid.go
54+
# With credentials from the binary, it should fail.
55+
env GOAUTH='invalid'$GOEXE
56+
cp go.mod.orig go.mod
57+
! go get vcs-test.golang.org/auth/or401
58+
stderr '^\tserver response: ACCESS DENIED, buddy$'
59+
# go imports should fail as well.
60+
! go mod tidy
61+
stderr '^\tserver response: ACCESS DENIED, buddy$'
62+
63+
-- go.mod.orig --
64+
module private.example.com
65+
-- main.go --
66+
package useprivate
67+
68+
import "vcs-test.golang.org/auth/or401"
69+
-- scripts/basic.go --
70+
package main
71+
72+
import "fmt"
73+
74+
func main() {
75+
fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n")
76+
}
77+
-- scripts/reinvocation.go --
3478
package main
3579

3680
import(
@@ -45,11 +89,7 @@ import(
4589
)
4690

4791
func main() {
48-
arg1 := flag.String("arg1", "", "")
4992
flag.Parse()
50-
if *arg1 != "value with spaces" {
51-
log.Fatal("argument with spaces does not work")
52-
}
5393
// wait for re-invocation
5494
if !strings.HasPrefix(flag.Arg(0), "https://vcs-test.golang.org") {
5595
return
@@ -68,12 +108,28 @@ func main() {
68108
}
69109
fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n")
70110
}
111+
-- scripts/arguments.go --
112+
package main
71113

72-
-- auth/go.mod --
73-
module my-auth
74-
-- go.mod.orig --
75-
module private.example.com
76-
-- main.go --
77-
package useprivate
114+
import(
115+
"flag"
116+
"fmt"
117+
"log"
118+
)
78119

79-
import "vcs-test.golang.org/auth/or401"
120+
func main() {
121+
arg1 := flag.String("arg1", "", "")
122+
flag.Parse()
123+
if *arg1 != "value with spaces" {
124+
log.Fatal("argument with spaces does not work")
125+
}
126+
fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n")
127+
}
128+
-- scripts/invalid.go --
129+
package main
130+
131+
import "fmt"
132+
133+
func main() {
134+
fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic invalid\n\n")
135+
}

0 commit comments

Comments
 (0)