Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion confmap/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/knadh/koanf/v2 v2.3.0
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/collector/featuregate v1.44.0
go.opentelemetry.io/collector/internal/testutil v0.0.0-00010101000000-000000000000
go.uber.org/goleak v1.3.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
Expand All @@ -30,4 +31,7 @@ retract (
v0.69.0 // Release failed, use v0.69.1
)

replace go.opentelemetry.io/collector/featuregate => ../featuregate
replace (
go.opentelemetry.io/collector/featuregate => ../featuregate
go.opentelemetry.io/collector/internal/testutil => ../internal/testutil
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/internal/testutil"
)

func newConfigurableHTTPProvider(scheme SchemeType, set confmap.ProviderSettings) *provider {
Expand All @@ -51,6 +52,7 @@ func answerGet(w http.ResponseWriter, _ *http.Request) {
// Generate a self signed certificate specific for the tests. Based on
// https://go.dev/src/crypto/tls/generate_cert.go
func generateCertificate(t *testing.T, hostname string) (cert, key string, err error) {
testutil.SkipIfFIPSOnly(t, "x509.CreateCertificate uses SHA-1")
priv, err := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
return "", "", fmt.Errorf("Failed to generate private key: %w", err)
Expand Down
1 change: 1 addition & 0 deletions internal/testutil/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../Makefile.Common
4 changes: 4 additions & 0 deletions internal/testutil/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Test Utilities

The `go.opentelemetry.io/collector/internal/testutil` module provides utility functions, etc. for use by tests in other
OpenTelemetry Collector modules.
21 changes: 21 additions & 0 deletions internal/testutil/fips.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package testutil // import "go.opentelemetry.io/collector/internal/testutil"

import (
"os"
"strings"
"testing"
)

// SkipIfFIPSOnly will mark the passed test as skipped if GODEBUG=fips140=only is detected.
// If GODEBUG=fips140=on, go may call non-compliant algorithms and the test does not need to be skipped.
func SkipIfFIPSOnly(t *testing.T, msg string) {
// NOTE: This only checks env var; at the time of writing fips140 can only be set via env
// other GODEBUG settings can be set via embedded comments or in go.mod, we may need to account for this in the future.
Comment on lines +15 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own education: is the GOFIPS140 env variable only used for deciding the version but not for enabling/disabling then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the GOFIPS140 environment variable is used to select the version of the Go Cryptographic Module to use but, as of now, none of these versions are validated as being FIPS-compliant (mentioned further down in the same doc). So, IMO, there is no benefit to setting this variable, again, as of now.

s := os.Getenv("GODEBUG")
if strings.Contains(s, "fips140=only") {
t.Skip("GODEBUG=fips140=only detected, skipping test:", msg)
}
}
15 changes: 15 additions & 0 deletions internal/testutil/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module go.opentelemetry.io/collector/internal/testutil

go 1.24.0

require (
github.com/stretchr/testify v1.11.1
go.uber.org/goleak v1.3.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
18 changes: 18 additions & 0 deletions internal/testutil/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading