-
Notifications
You must be signed in to change notification settings - Fork 3
fix: add validation for malformed headers in metrics module and add unit tests #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
17019c4
feat: add OtelMetricsExporterOTLPHeadersFlag to be able to add header…
philtremblay 3bb497a
Merge branch 'formancehq:main' into main
philtremblay b01cee7
fix: add validation for malformed headers in metrics module and add u…
devin-ai-integration[bot] f83722d
style: fix whitespace in test file
devin-ai-integration[bot] 8a9e736
fix: explicitly handle malformed headers with no value
devin-ai-integration[bot] 04528b6
fix: trigger error for malformed headers with missing values
devin-ai-integration[bot] 14c7b4b
fix: return CLI error instead of panic for malformed headers
devin-ai-integration[bot] 697d458
fix: remove error print statement as requested
devin-ai-integration[bot] e2a9525
fix: use length check instead of nil check for headers map
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package otlpmetrics | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestHeadersParsing(t *testing.T) { | ||
cmd := &cobra.Command{} | ||
AddFlags(cmd.Flags()) | ||
|
||
cmd.SetArgs([]string{ | ||
"--otel-metrics-exporter-otlp-headers=Authorization=Bearer token,Content-Type=application/json", | ||
}) | ||
err := cmd.Execute() | ||
assert.NoError(t, err) | ||
|
||
headers, _ := cmd.Flags().GetStringSlice(OtelMetricsExporterOTLPHeadersFlag) | ||
assert.Len(t, headers, 2) | ||
|
||
cmd2 := &cobra.Command{} | ||
AddFlags(cmd2.Flags()) | ||
cmd2.SetArgs([]string{ | ||
"--otel-metrics-exporter-otlp-headers=Authorization=Bearer token,BadHeader", | ||
}) | ||
err = cmd2.Execute() | ||
assert.NoError(t, err) | ||
|
||
headers, _ = cmd2.Flags().GetStringSlice(OtelMetricsExporterOTLPHeadersFlag) | ||
|
||
cmd3 := &cobra.Command{} | ||
AddFlags(cmd3.Flags()) | ||
cmd3.SetArgs([]string{ | ||
"--otel-metrics-exporter-otlp-headers=Authorization=Bearer token,BadHeader", | ||
"--otel-metrics-exporter-otlp-mode=grpc", | ||
}) | ||
err = cmd3.Execute() | ||
assert.NoError(t, err) | ||
|
||
_ = FXModuleFromFlags(cmd3) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle the case where len(parts) == 1