Skip to content

Commit

Permalink
saving test case progress
Browse files Browse the repository at this point in the history
  • Loading branch information
joeleonjr committed Aug 23, 2023
1 parent 95f6528 commit 6b8ce2f
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions pkg/handlers/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
diskbufferreader "github.com/bill-rich/disk-buffer-reader"
"github.com/stretchr/testify/assert"

"github.com/google/go-containerregistry/pkg/v1/remote"

"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/tarball"
logContext "github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
)
Expand Down Expand Up @@ -184,3 +188,84 @@ func TestExtractRPMContent(t *testing.T) {
expectedLength := 1822720
assert.Equal(t, expectedLength, len(string(content)))
}

func TestFoundKeyInDockerTar(t *testing.T) {
// URI of the Docker image to clone
imageURI := "ghcr.io/joeleonjr/getting-started-app-with-canary-token:main"

var imageName name.Reference
imageName, err := name.NewTag(imageURI)
if err != nil {
t.Errorf("%s: error creating image name: %s", imageURI, err)
}

// Pull the image
img, err := remote.Image(imageName)
if err != nil {
t.Errorf("%s: error pulling image: %s", imageURI, err)
}

tempFile, err := os.CreateTemp("", "archive_test_docker_img.tar")
if err != nil {
t.Errorf("%s: error creating temporary file: %s", imageURI, err)
return
}

defer os.Remove(tempFile.Name()) // Clean up the temporary file

// Save the image as a tar file
err = tarball.WriteToFile(tempFile.Name(), imageName, img)
if err != nil {
t.Errorf("%s: error saving image as tar file: %s", imageURI, err)
return
}

// ctx := logContext.AddLogger(context.Background())

// inputFile, err := os.Open(tempFile.Name())
// if err != nil {
// t.Errorf("%s: error opening tar file: %s", imageURI, err)
// return
// }
// defer inputFile.Close()

// reReader, err := diskbufferreader.New(inputFile)
// if err != nil {
// t.Errorf("%s: error creating re-readable reader: %s", imageURI, err)
// return
// }
// defer reReader.Close()

// chunkSkel := &sources.Chunk{
// SourceType: 1,
// SourceName: "filesystem",
// SourceID: 1,
// SourceMetadata: &source_metadatapb.MetaData{
// Data: &source_metadatapb.MetaData_Filesystem{
// Filesystem: &source_metadatapb.Filesystem{
// File: sanitizer.UTF8(tempFile.Name()),
// },
// },
// },
// Verify: true,
// }

// chunksChan := make(chan *sources.Chunk, 1)

// HandleFile(ctx, reReader, chunkSkel, chunksChan)

// println("here")
// fmt.Printf("chunksChan: %v\n", chunksChan)
// fmt.Printf("chunksChan: %v\n", &chunksChan)

// secret := "AKIA2OGYBAH6Q2PQJUGN"

// // Read from the channel and validate the secrets.
// foundSecret := ""
// for chunkCh := range chunksChan {
// foundSecret += string(chunkCh.Data)
// }

// assert.Contains(t, foundSecret, secret)

}

0 comments on commit 6b8ce2f

Please sign in to comment.