Skip to content

Commit 21211a0

Browse files
authored
add response id and response name to postman metadata (#4555)
1 parent 71caba8 commit 21211a0

File tree

6 files changed

+296
-218
lines changed

6 files changed

+296
-218
lines changed

pkg/pb/source_metadatapb/source_metadata.pb.go

Lines changed: 239 additions & 218 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/pb/source_metadatapb/source_metadata.pb.validate.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sources/postman/postman.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ func (s *Source) scanHTTPResponse(ctx context.Context, chunksChan chan *sources.
682682
if response.Uid != "" {
683683
m.Link = LINK_BASE_URL + "example/" + response.Uid
684684
m.FullID = response.Uid
685+
m.ResponseID = response.Uid
686+
m.ResponseName = response.Name
685687
}
686688
originalType := m.Type
687689

@@ -785,6 +787,8 @@ func (s *Source) scanData(ctx context.Context, chunksChan chan *sources.Chunk, d
785787
FolderName: metadata.FolderName,
786788
FieldType: metadata.FieldType,
787789
LocationType: metadata.LocationType,
790+
ResponseId: metadata.ResponseID,
791+
ResponseName: metadata.ResponseName,
788792
},
789793
},
790794
},

pkg/sources/postman/postman_client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ type Metadata struct {
8787
FieldType string // Path of the item type
8888
fromLocal bool
8989
LocationType source_metadatapb.PostmanLocationType // The distinct Postman location type that the item falls under
90+
ResponseID string
91+
ResponseName string
9092
}
9193

9294
type Collection struct {

pkg/sources/postman/postman_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
1414
"gopkg.in/h2non/gock.v1"
1515

16+
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
1617
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
1718
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
1819
"google.golang.org/protobuf/types/known/anypb"
@@ -689,3 +690,47 @@ func TestSource_HeadersScanning(t *testing.T) {
689690
t.Logf("Generated %d chunks from the mock data", chunksReceived)
690691
}
691692
}
693+
694+
func TestSource_ResponseID(t *testing.T) {
695+
ctx := context.Background()
696+
697+
s := &Source{
698+
DetectorKeywords: map[string]struct{}{
699+
"keyword1": {},
700+
},
701+
keywords: map[string]struct{}{
702+
"keyword1": {},
703+
},
704+
}
705+
706+
chunksChan := make(chan *sources.Chunk, 1)
707+
708+
response := Response{
709+
Uid: "response-1234",
710+
Name: "Test Response",
711+
Body: "This is a test response body containing keyword1.",
712+
}
713+
714+
go func() {
715+
s.scanHTTPResponse(ctx, chunksChan, Metadata{}, response)
716+
close(chunksChan)
717+
}()
718+
719+
var gotChunk *sources.Chunk
720+
for chunk := range chunksChan {
721+
gotChunk = chunk
722+
}
723+
724+
postmanMetadata, ok := gotChunk.SourceMetadata.Data.(*source_metadatapb.MetaData_Postman)
725+
if !ok {
726+
t.Fatalf("expected Postman metadata, got: %T", gotChunk.SourceMetadata.Data)
727+
}
728+
729+
if postmanMetadata.Postman.ResponseId != response.Uid {
730+
t.Errorf("expected response ID: %s, got: %s", response.Uid, postmanMetadata.Postman.ResponseId)
731+
}
732+
if postmanMetadata.Postman.ResponseName != response.Name {
733+
t.Errorf("expected response Name: %s, got: %s", response.Name, postmanMetadata.Postman.ResponseName)
734+
}
735+
736+
}

proto/source_metadata.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ message Postman {
316316
string folder_name = 12;
317317
string field_type = 13; // Do not use this field for transport. It is only used for output to STDOUT.
318318
PostmanLocationType location_type = 16;
319+
string response_id = 17;
320+
string response_name = 18;
319321
}
320322

321323
enum PostmanLocationType {

0 commit comments

Comments
 (0)