Skip to content

fix(test): prevent panic on missing API/App key#21

Closed
giannileggio wants to merge 1 commit into
mainfrom
gianni.leggio/fix-missing-app-key
Closed

fix(test): prevent panic on missing API/App key#21
giannileggio wants to merge 1 commit into
mainfrom
gianni.leggio/fix-missing-app-key

Conversation

@giannileggio
Copy link
Copy Markdown

Summary

  • pup test panicked with slice bounds out of range [:8] with length 0 when DD_APP_KEY (or DD_API_KEY) was not set, because the masking code tried to slice an empty string
  • Added explicit empty-key checks before the masking code, returning a clear error message

Changes

  • cmd/root.go:208-214 - validate APIKey and AppKey are non-empty before slicing
  • cmd/root_test.go - added TestTestCmd_MissingKeys (3 cases) and TestTestCmd_ValidKeys

Testing

  • go test ./... all passing
  • Manually verified pup test with missing app key now returns a helpful error instead of panicking

The test command panicked with slice bounds out of range when
DD_APP_KEY (or DD_API_KEY) was not set, because it tried to mask
an empty string. Add explicit checks before the masking code.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@giannileggio giannileggio marked this pull request as ready for review February 10, 2026 15:28
@giannileggio giannileggio requested a review from a team as a code owner February 10, 2026 15:28
@platinummonkey
Copy link
Copy Markdown
Collaborator

fixed in #20

@giannileggio
Copy link
Copy Markdown
Author

fixed in #20

closing this

@github-actions
Copy link
Copy Markdown

📊 Test Coverage Report

Overall Coverage: 80.4% Coverage

Threshold: 80% ✅

Coverage by Package
## Coverage by Package

- github.com/DataDog/pup/pkg/auth/callback/server.go:40: 81.2%
- github.com/DataDog/pup/pkg/auth/dcr/client.go:28: 100.0%
- github.com/DataDog/pup/pkg/auth/dcr/types.go:24: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/client.go:22: 100.0%
- github.com/DataDog/pup/pkg/auth/oauth/pkce.go:24: 85.7%
- github.com/DataDog/pup/pkg/auth/storage/factory.go:53: 94.7%
- github.com/DataDog/pup/pkg/auth/storage/keychain.go:44: 42.9%
- github.com/DataDog/pup/pkg/auth/storage/storage.go:58: 71.4%
- github.com/DataDog/pup/pkg/auth/types/types.go:23: 100.0%
- github.com/DataDog/pup/pkg/client/client.go:32: 94.4%
- github.com/DataDog/pup/pkg/config/config.go:22: 100.0%
- github.com/DataDog/pup/pkg/formatter/formatter.go:31: 100.0%
- github.com/DataDog/pup/pkg/useragent/useragent.go:32: 100.0%
- github.com/DataDog/pup/pkg/util/time.go:20: 95.8%

## Summary

total:								(statements)		80.4%

📈 Coverage Status: ✅ PASSED - Coverage meets minimum threshold

Updated for commit 8d510b9

@platinummonkey platinummonkey deleted the gianni.leggio/fix-missing-app-key branch February 22, 2026 03:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants