Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Signed-off-by: Ramon Petgrave <ramon.petgrave64@gmail.com>
  • Loading branch information
ramonpetgrave64 committed Jan 10, 2024
1 parent 508257d commit 852f46d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion verifiers/internal/gha/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func init() {
if err != nil {
log.Fatal(err)
}
npmRegistryPublicKey, err = GetAttestationKeyMaterialByKeyId(keys, npmRegistryPublicKeyID)
npmRegistryPublicKey, err = GetAttestationKeyMaterialByKeyID(keys, npmRegistryPublicKeyID)
if err != nil {
log.Fatal(err)
}
Expand Down
12 changes: 6 additions & 6 deletions verifiers/internal/gha/npm_sigstore_tuf.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (

const (
KeyUsage = "npm:attestations"
KeyId = "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
KeyID = "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
TargetPath = "registry.npmjs.org/keys.json"
)

// NpmjsKeysTarget describes the structure of the target file
// NpmjsKeysTarget describes the structure of the target file.
type NpmjsKeysTarget struct {
Keys []Key `json:"keys"`
}
Expand All @@ -39,7 +39,7 @@ type SigstoreTufClient interface {
GetTarget(target string) ([]byte, error)
}

// NewSigstoreTufClient Get a Sigstore TUF client, which itself is a wrapper around the official TUF client
// NewSigstoreTufClient Get a Sigstore TUF client, which itself is a wrapper around the official TUF client.
func NewSigstoreTufClient() (*sigstoreTuf.Client, error) {
_, filename, _, ok := runtime.Caller(1)
if !ok {
Expand Down Expand Up @@ -73,13 +73,13 @@ func GetNpmjsKeysTarget(client SigstoreTufClient, targetPath string) (*NpmjsKeys
}

/*
GetAttestationKeyMaterialByKeyId Given our set of keys, return the target key's material.
GetAttestationKeyMaterialByKeyID Given our set of keys, return the target key's material.
It also checks that the keyUsage is "nmp:attestations", but we may also want to check
the existing ValidFor.Start (and a potential future ValidFor.End).
*/
func GetAttestationKeyMaterialByKeyId(keys *NpmjsKeysTarget, keyId string) (string, error) {
func GetAttestationKeyMaterialByKeyID(keys *NpmjsKeysTarget, keyID string) (string, error) {
for _, key := range keys.Keys {
if key.KeyID == keyId && key.KeyUsage == KeyUsage {
if key.KeyID == keyID && key.KeyUsage == KeyUsage {
return key.PublicKey.RawBytes, nil
}
}
Expand Down
12 changes: 6 additions & 6 deletions verifiers/internal/gha/npm_sigstore_tuf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,27 @@ func TestGetNpmjsKeysTarget(t *testing.T) {
})
}

// TestGetAttestationKeyMaterialByKeyId ensure that we find the "npm:attestations" key material, given keyid
func TestGetAttestationKeyMaterialByKeyId(t *testing.T) {
// TestGetAttestationKeyMaterialByKeyID ensure that we find the "npm:attestations" key material, given keyid

Check failure on line 56 in verifiers/internal/gha/npm_sigstore_tuf_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Comment should end in a period (godot)
func TestGetAttestationKeyMaterialByKeyID(t *testing.T) {
tests := []struct {
name string
localPath string
keyId string
keyID string
keyUsage string
expectedKeyMaterial string
expectError bool
}{
{
name: "npmjs' first attestation key",
localPath: testTargetLocalFilePath,
keyId: testTargetKeyId,
keyID: testTargetKeyId,
expectedKeyMaterial: testTargetKeyMaterial,
expectError: false,
},
{
name: "missing the 'npm:attestations' keyusage",
localPath: "./testdata/wrong_keyusage_registry.npmjs.org_keys.json",
keyId: testTargetKeyId,
keyID: testTargetKeyId,
expectedKeyMaterial: testTargetKeyMaterial,
expectError: true,
},
Expand All @@ -83,7 +83,7 @@ func TestGetAttestationKeyMaterialByKeyId(t *testing.T) {
mockClient := mockSigstoreTufClient{localPath: tt.localPath}
keys, err := GetNpmjsKeysTarget(mockClient, tt.localPath)
assert.NoError(t, err)
actualKeyMaterial, err := GetAttestationKeyMaterialByKeyId(keys, tt.keyId)
actualKeyMaterial, err := GetAttestationKeyMaterialByKeyID(keys, tt.keyID)
if !tt.expectError {
assert.NoError(t, err)
assert.Equalf(t, tt.expectedKeyMaterial, actualKeyMaterial, "key materials do not match")
Expand Down

0 comments on commit 852f46d

Please sign in to comment.