Skip to content

Commit

Permalink
completed test
Browse files Browse the repository at this point in the history
  • Loading branch information
zubairk14 committed Aug 13, 2023
1 parent 02294e6 commit 11b1a61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 6 additions & 3 deletions pkg/detectors/huggingface/huggingface.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
matches := keyPat.FindAllStringSubmatch(dataStr, -1)

for _, match := range matches {
if len(match) != 2 {
if len(match) != 1 {
continue
}
resMatch := strings.TrimSpace(match[1])
resMatch := strings.TrimSpace(match[0])

s1 := detectors.Result{
DetectorType: detectorspb.DetectorType_HuggingFace,
Expand All @@ -53,10 +53,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
if client == nil {
client = defaultClient
}
req, err := http.NewRequestWithContext(ctx, "GET", "https://eth-mainnet.g.huggingface.com/v2/"+resMatch+"/getNFTs/?owner=vitalik.eth", nil)
req, err := http.NewRequestWithContext(ctx, "GET", "https://huggingface.co/api/whoami-v2", nil)
if err != nil {
continue
}

req.Header.Set("Authorization", "Bearer "+resMatch)

res, err := client.Do(req)
if err == nil {
defer res.Body.Close()
Expand Down
10 changes: 5 additions & 5 deletions pkg/detectors/huggingface/huggingface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
func TestHuggingface_FromChunk(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors4")
testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors5")
if err != nil {
t.Fatalf("could not get test secrets from GCP: %s", err)
}
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestHuggingface_FromChunk(t *testing.T) {
},
want: []detectors.Result{
{
DetectorType: detectorspb.DetectorType_Huggingface,
DetectorType: detectorspb.DetectorType_HuggingFace,
Verified: true,
},
},
Expand All @@ -67,7 +67,7 @@ func TestHuggingface_FromChunk(t *testing.T) {
},
want: []detectors.Result{
{
DetectorType: detectorspb.DetectorType_Huggingface,
DetectorType: detectorspb.DetectorType_HuggingFace,
Verified: false,
},
},
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestHuggingface_FromChunk(t *testing.T) {
},
want: []detectors.Result{
{
DetectorType: detectorspb.DetectorType_Huggingface,
DetectorType: detectorspb.DetectorType_HuggingFace,
Verified: false,
},
},
Expand All @@ -113,7 +113,7 @@ func TestHuggingface_FromChunk(t *testing.T) {
},
want: []detectors.Result{
{
DetectorType: detectorspb.DetectorType_Huggingface,
DetectorType: detectorspb.DetectorType_HuggingFace,
Verified: false,
},
},
Expand Down

0 comments on commit 11b1a61

Please sign in to comment.