Skip to content

Commit 37f27fb

Browse files
committed
cmd/go: enable fips test and fix caching bug
Enable the cmd/go fips test now that v1.0.0.zip has been checked in. Will still need to enable the alias half when the alias is checked in. Also fix a problem that was causing spurious failures, by fixing repeated unpackings and also disabling modindex reads of the virtual fips140 snapshot directories. Fixes #71491. Change-Id: I7fa21e9bde07ff4eb6c3483e99d49316ee0ea7f0 Reviewed-on: https://go-review.googlesource.com/c/go/+/645835 Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Sam Thanawalla <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 77d2083 commit 37f27fb

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/cmd/go/internal/modfetch/cache.go

+7
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ func DownloadDir(ctx context.Context, m module.Version) (string, error) {
113113
return dir, err
114114
}
115115

116+
// Special case: ziphash is not required for the golang.org/fips140 module,
117+
// because it is unpacked from a file in GOROOT, not downloaded.
118+
// We've already checked that it's not a partial unpacking, so we're happy.
119+
if m.Path == "golang.org/fips140" {
120+
return dir, nil
121+
}
122+
116123
// Check if a .ziphash file exists. It should be created before the
117124
// zip is extracted, but if it was deleted (by another program?), we need
118125
// to re-calculate it. Note that checkMod will repopulate the ziphash

src/cmd/go/internal/modindex/read.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ import (
3333
"cmd/internal/par"
3434
)
3535

36-
// enabled is used to flag off the behavior of the module index on tip.
37-
// It will be removed before the release.
38-
// TODO(matloob): Remove enabled once we have more confidence on the
39-
// module index.
36+
// enabled is used to flag off the behavior of the module index on tip, for debugging.
4037
var enabled = godebug.New("#goindex").Value() != "0"
4138

4239
// Module represents and encoded module index file. It is used to
@@ -126,6 +123,7 @@ var ErrNotIndexed = errors.New("not in module index")
126123
var (
127124
errDisabled = fmt.Errorf("%w: module indexing disabled", ErrNotIndexed)
128125
errNotFromModuleCache = fmt.Errorf("%w: not from module cache", ErrNotIndexed)
126+
errFIPS140 = fmt.Errorf("%w: fips140 snapshots not indexed", ErrNotIndexed)
129127
)
130128

131129
// GetPackage returns the IndexPackage for the directory at the given path.
@@ -143,6 +141,11 @@ func GetPackage(modroot, pkgdir string) (*IndexPackage, error) {
143141
if cfg.BuildContext.Compiler == "gccgo" && str.HasPathPrefix(modroot, cfg.GOROOTsrc) {
144142
return nil, err // gccgo has no sources for GOROOT packages.
145143
}
144+
// The pkgdir for fips140 has been replaced in the fsys overlay,
145+
// but the module index does not see that. Do not try to use the module index.
146+
if strings.Contains(filepath.ToSlash(pkgdir), "internal/fips140/v") {
147+
return nil, errFIPS140
148+
}
146149
return openIndexPackage(modroot, pkgdir)
147150
}
148151

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
## Note: Need a snapshot in lib/fips140 to run this test.
2-
## For local testing, can run 'cd lib/fips140; make v0.0.1.test'
3-
## and then remove the skip.
4-
env snap=v0.0.1
1+
env snap=v1.0.0
52
env alias=inprocess
63

7-
skip 'no snapshots yet'
84
env GOFIPS140=$snap
95

106
# Go+BoringCrypto conflicts with GOFIPS140.
@@ -27,7 +23,8 @@ stdout crypto/internal/fips140/$snap/sha256
2723
! stdout crypto/internal/fips140/check
2824

2925
# again with GOFIPS140=$alias
30-
env GOFIPS140=$alias
26+
# TODO: enable when we add inprocess.txt
27+
# env GOFIPS140=$alias
3128

3229
# default GODEBUG includes fips140=on
3330
go list -f '{{.DefaultGODEBUG}}'

0 commit comments

Comments
 (0)