| 1 |
# This test covers the HTTP authentication mechanism over GOAUTH by using a custom authenticator. |
| 2 |
# See golang.org/issue/26232 |
| 3 |
|
| 4 |
[short] skip 'runs build to create authenticators' |
| 5 |
|
| 6 |
env GOPROXY=direct |
| 7 |
env GOSUMDB=off |
| 8 |
mkdir $WORK/bin |
| 9 |
env PATH=$WORK/bin${:}$PATH |
| 10 |
|
| 11 |
# Without credentials, downloading a module from a path that requires HTTPS |
| 12 |
# basic auth should fail. |
| 13 |
env GOAUTH=off |
| 14 |
cp go.mod.orig go.mod |
| 15 |
! go get vcs-test.golang.org/auth/or401 |
| 16 |
stderr '^\tserver response: ACCESS DENIED, buddy$' |
| 17 |
# go imports should fail as well. |
| 18 |
! go mod tidy |
| 19 |
stderr '^\tserver response: ACCESS DENIED, buddy$' |
| 20 |
|
| 21 |
# Initial invocation of authenticator is successful. |
| 22 |
go build -o $WORK/bin/basic$GOEXE scripts/basic.go |
| 23 |
# With credentials from the binary, it should succeed. |
| 24 |
env GOAUTH='basic'$GOEXE |
| 25 |
cp go.mod.orig go.mod |
| 26 |
go get vcs-test.golang.org/auth/or401 |
| 27 |
# go imports should resolve correctly as well. |
| 28 |
go mod tidy |
| 29 |
go list all |
| 30 |
stdout vcs-test.golang.org/auth/or401 |
| 31 |
|
| 32 |
# Second invocation of authenticator is successful. |
| 33 |
go build -o $WORK/bin/reinvocation$GOEXE scripts/reinvocation.go |
| 34 |
# With credentials from the binary, it should succeed. |
| 35 |
env GOAUTH='reinvocation'$GOEXE |
| 36 |
cp go.mod.orig go.mod |
| 37 |
go get vcs-test.golang.org/auth/or401 |
| 38 |
# go imports should resolve correctly as well. |
| 39 |
go mod tidy |
| 40 |
go list all |
| 41 |
stdout vcs-test.golang.org/auth/or401 |
| 42 |
|
| 43 |
# Authenticator can parse arguments correctly. |
| 44 |
go build -o $WORK/bin/arguments$GOEXE scripts/arguments.go |
| 45 |
# With credentials from the binary, it should succeed. |
| 46 |
env GOAUTH='arguments'$GOEXE' --arg1 "value with spaces"' |
| 47 |
cp go.mod.orig go.mod |
| 48 |
go get vcs-test.golang.org/auth/or401 |
| 49 |
# go imports should resolve correctly as well. |
| 50 |
go mod tidy |
| 51 |
go list all |
| 52 |
stdout vcs-test.golang.org/auth/or401 |
| 53 |
|
| 54 |
# Authenticator provides bad credentials. |
| 55 |
go build -o $WORK/bin/invalid$GOEXE scripts/invalid.go |
| 56 |
# With credentials from the binary, it should fail. |
| 57 |
env GOAUTH='invalid'$GOEXE |
| 58 |
cp go.mod.orig go.mod |
| 59 |
! go get vcs-test.golang.org/auth/or401 |
| 60 |
stderr '^\tserver response: ACCESS DENIED, buddy$' |
| 61 |
# go imports should fail as well. |
| 62 |
! go mod tidy |
| 63 |
stderr '^\tserver response: ACCESS DENIED, buddy$' |
| 64 |
|
| 65 |
-- go.mod.orig -- |
| 66 |
module private.example.com |
| 67 |
-- main.go -- |
| 68 |
package useprivate |
| 69 |
|
| 70 |
import "vcs-test.golang.org/auth/or401" |
| 71 |
-- scripts/basic.go -- |
| 72 |
package main |
| 73 |
|
| 74 |
import "fmt" |
| 75 |
|
| 76 |
func main() { |
| 77 |
fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n") |
| 78 |
} |
| 79 |
-- scripts/reinvocation.go -- |
| 80 |
package main |
| 81 |
|
| 82 |
import( |
| 83 |
"bufio" |
| 84 |
"flag" |
| 85 |
"fmt" |
| 86 |
"io" |
| 87 |
"log" |
| 88 |
"net/http" |
| 89 |
"os" |
| 90 |
"strings" |
| 91 |
) |
| 92 |
|
| 93 |
func main() { |
| 94 |
flag.Parse() |
| 95 |
// wait for re-invocation |
| 96 |
if !strings.HasPrefix(flag.Arg(0), "https://vcs-test.golang.org") { |
| 97 |
return |
| 98 |
} |
| 99 |
input, err := io.ReadAll(os.Stdin) |
| 100 |
if err != nil { |
| 101 |
log.Fatal("unexpected error while reading from stdin") |
| 102 |
} |
| 103 |
reader := bufio.NewReader(strings.NewReader(string(input))) |
| 104 |
resp, err := http.ReadResponse(reader, nil) |
| 105 |
if err != nil { |
| 106 |
log.Fatal("could not parse HTTP response") |
| 107 |
} |
| 108 |
if resp.StatusCode != 401 { |
| 109 |
log.Fatal("expected 401 error code") |
| 110 |
} |
| 111 |
fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n") |
| 112 |
} |
| 113 |
-- scripts/arguments.go -- |
| 114 |
package main |
| 115 |
|
| 116 |
import( |
| 117 |
"flag" |
| 118 |
"fmt" |
| 119 |
"log" |
| 120 |
) |
| 121 |
|
| 122 |
func main() { |
| 123 |
arg1 := flag.String("arg1", "", "") |
| 124 |
flag.Parse() |
| 125 |
if *arg1 != "value with spaces" { |
| 126 |
log.Fatal("argument with spaces does not work") |
| 127 |
} |
| 128 |
fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic YWxhZGRpbjpvcGVuc2VzYW1l\n\n") |
| 129 |
} |
| 130 |
-- scripts/invalid.go -- |
| 131 |
package main |
| 132 |
|
| 133 |
import "fmt" |
| 134 |
|
| 135 |
func main() { |
| 136 |
fmt.Printf("https://vcs-test.golang.org\n\nAuthorization: Basic invalid\n\n") |
| 137 |
} |