Skip to content

Commit

Permalink
Continue in kolide_jwt when rawData is empty (#1751)
Browse files Browse the repository at this point in the history
  • Loading branch information
Micah-Kolide authored Jun 13, 2024
1 parent d3ffb8c commit aefa457
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ee/tables/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) (
for _, includeRawJWT := range tablehelpers.GetConstraints(queryContext, "include_raw_jwt", tablehelpers.WithAllowedValues(allowedIncludeValues), tablehelpers.WithDefaults("false")) {
for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) {
rawData, err := os.ReadFile(path)
if err != nil {
if len(rawData) == 0 || err != nil {
t.slogger.Log(ctx, slog.LevelInfo, "error reading JWT data file", "err", err)
continue
}
Expand Down
11 changes: 10 additions & 1 deletion ee/tables/jwt/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func TestTransformOutput(t *testing.T) {
keys map[string]string
res map[string]string
}{
{
name: "empty token",
path: "testdata/empty",
},
{
name: "rsa256 JWT valid",
path: "testdata/rsa256.raw",
Expand Down Expand Up @@ -149,7 +153,12 @@ func TestTransformOutput(t *testing.T) {
rows, err := jwtTable.generate(context.TODO(), mockQC)

require.NoError(t, err)
require.Contains(t, rows, tt.res, "generated rows should contain the expected result")

if tt.name == "empty token" {
require.Nil(t, rows, "the result should be nil for an empty token")
} else {
require.Contains(t, rows, tt.res, "generated rows should contain the expected result")
}
})
}
}
Empty file added ee/tables/jwt/testdata/empty
Empty file.

0 comments on commit aefa457

Please sign in to comment.