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

Fuzzing: add more fuzzers #1215

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions pkg/signer/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright The Rekor Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package signer

import (
"os"
"testing"
)

func FuzzNewFile(f *testing.F) {
f.Fuzz(func(t *testing.T, keyData []byte, keyPass string) {
keyPath, err := os.CreateTemp(t.TempDir(), "keyfile")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename keyPath to keyFile as CreateTemp returns a *File, not a path.

if err != nil {
t.Skip()
}
defer func() {
keyPath.Close()
os.Remove(keyPath.Name())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to call os.Remove as the directory (and it's contents) created by t.TempDir() is removed automatically when the test is finished.

}()
_, err = keyPath.Write(keyData)
if err != nil {
t.Skip()
}

_, _ = NewFile(keyPath.Name(), keyPass)
})
}
32 changes: 32 additions & 0 deletions pkg/types/cose/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright 2022 The Sigstore Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cose

import (
"context"
"testing"

"github.com/sigstore/rekor/pkg/types"
)

func FuzzCreateProposedEntry(f *testing.F) {
f.Fuzz(func(t *testing.T, version string) {
ctx := context.Background()
brt := New()
props := types.ArtifactProperties{}
_, _ = brt.CreateProposedEntry(ctx, version, props)
})
}
34 changes: 34 additions & 0 deletions pkg/types/jar/fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright 2022 The Sigstore Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package jar

import (
"testing"

"github.com/sigstore/rekor/pkg/generated/models"
)

func FuzzJarUnmarshal(f *testing.F) {
f.Fuzz(func(t *testing.T, raw []byte) {
m := &models.Jar{}
err := m.UnmarshalJSON(raw)
if err != nil {
t.Skip()
}
brt := New()
brt.UnmarshalEntry(m)
})
}