Skip to content
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

feat: expose SigstoreTUFClient mocks #773

Open
ramonpetgrave64 opened this issue May 21, 2024 · 1 comment
Open

feat: expose SigstoreTUFClient mocks #773

ramonpetgrave64 opened this issue May 21, 2024 · 1 comment

Comments

@ramonpetgrave64
Copy link
Contributor

Following #768

For folks using slsa-verifier as a library, it could be useful to export the mocks we already have for the TUF client newMockSigstoreTUFClient, and it's implementation for GetTarget. We may also include some sample data for the mock.

// mockSigstoreTUFClient a mock implementation of sigstoreTUFClient.
type mockSigstoreTUFClient struct {
fileContentMap map[string]string
}
// newMockSigstoreTUFClient returns an instance of the mock client,
// with fileContentMap as input and outputs of the GetTarget() method.
func newMockSigstoreTUFClient() *mockSigstoreTUFClient {
return &mockSigstoreTUFClient{fileContentMap: mockFileContentMap}
}
// GetTarget mock implementation of GetTarget for the mockSigstoreTUFClient.
func (c mockSigstoreTUFClient) GetTarget(targetPath string) ([]byte, error) {
content, exists := c.fileContentMap[targetPath]
if !exists {
return nil, fmt.Errorf("content not definied in this mock, key: %s", targetPath)
}
return []byte(content), nil
}

@haydentherapper
Copy link
Contributor

Can we upstream or align this with the existing testing in sigstore-go? In https://github.com/sigstore/sigstore-go/blob/main/pkg/tuf/client_test.go, we have stubbed out the TUF repo so that you can initialize a real client that doesn't make outbound network calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants