Skip to content

Commit

Permalink
INFOPLAT-1560 Fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hendoxc committed Dec 17, 2024
1 parent 83ef2a4 commit 5acee42
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/beholder/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ func buildAuthHeadersV2(privKey ed25519.PrivateKey, config *AuthHeaderConfig) ma
if config.version == "" {
config.version = authHeaderVersion2
}
// If timestamp is negative, set it to 0. negative values cause overflow on conversion to uint64
// If timestamp is negative or 0, set it to current timestamp.
// negative values cause overflow on conversion to uint64
if config.timestamp <= 0 {
config.timestamp = time.Now().UnixMilli()
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/beholder/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func TestBuildAuthHeadersV2WithDefaults(t *testing.T) {
}

func TestBuildAuthHeadersV2WithNegativeTimestamp(t *testing.T) {
// This tests that if the timestamp is negative, it will be set it to current timestamp
csaPrivKey, err := generateTestCSAPrivateKey()
require.NoError(t, err)
timestamp := int64(-111)
Expand All @@ -126,7 +127,8 @@ func TestBuildAuthHeadersV2WithNegativeTimestamp(t *testing.T) {
_, _, timestampStr, _ := parts[0], parts[1], parts[2], parts[3]
timestampParsed, err := strconv.ParseInt(timestampStr, 10, 64)
require.NoError(t, err)
assert.Zero(t, timestampParsed)
// Verify the timestamp is within the last 50ms
assert.InDelta(t, time.Now().UnixMilli(), timestampParsed, 50, "timestamp should be 0")
}

func generateTestCSAPrivateKey() (ed25519.PrivateKey, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/beholder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ func ExampleConfig() {
}
fmt.Printf("%+v\n", *config.LogRetryConfig)
// Output:
// {InsecureConnection:true CACertFile: OtelExporterGRPCEndpoint:localhost:4317 OtelExporterHTTPEndpoint:localhost:4318 ResourceAttributes:[{Key:package_name Value:{vtype:4 numeric:0 stringly:beholder slice:<nil>}} {Key:sender Value:{vtype:4 numeric:0 stringly:beholderclient slice:<nil>}}] EmitterExportTimeout:1s EmitterBatchProcessor:true TraceSampleRatio:1 TraceBatchTimeout:1s TraceSpanExporter:<nil> TraceRetryConfig:<nil> MetricReaderInterval:1s MetricRetryConfig:<nil> MetricViews:[] LogExportTimeout:1s LogBatchProcessor:true LogRetryConfig:<nil> AuthPublicKeyHex: AuthHeaders:map[]}
// {InsecureConnection:true CACertFile: OtelExporterGRPCEndpoint:localhost:4317 OtelExporterHTTPEndpoint:localhost:4318 ResourceAttributes:[{Key:package_name Value:{vtype:4 numeric:0 stringly:beholder slice:<nil>}} {Key:sender Value:{vtype:4 numeric:0 stringly:beholderclient slice:<nil>}}] EmitterExportTimeout:1s EmitterBatchProcessor:true TraceSampleRatio:1 TraceBatchTimeout:1s TraceSpanExporter:<nil> TraceRetryConfig:<nil> MetricReaderInterval:1s MetricRetryConfig:<nil> MetricViews:[] LogExportTimeout:1s LogBatchProcessor:true LogRetryConfig:<nil> AuthPublicKeyHex: AuthHeaders:map[] AuthHeaderProvider:<nil>}
// {InitialInterval:5s MaxInterval:30s MaxElapsedTime:1m0s}
}

0 comments on commit 5acee42

Please sign in to comment.