Skip to content

Commit

Permalink
adding Schema to test attestors (part of interface)
Browse files Browse the repository at this point in the history
Signed-off-by: chaosinthecrd <[email protected]>
  • Loading branch information
ChaosInTheCRD committed May 10, 2024
1 parent 009796d commit 9f3096e
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 24 deletions.
9 changes: 6 additions & 3 deletions internal/attestors/commandrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"github.com/in-toto/go-witness/attestation"
"github.com/in-toto/go-witness/attestation/commandrun"
"github.com/in-toto/go-witness/cryptoutil"
"github.com/invopop/jsonschema"
)

var (
_ commandrun.CommandRunAttestor = &TestCommandRunAttestor{}
)
var _ commandrun.CommandRunAttestor = &TestCommandRunAttestor{}

type TestCommandRunAttestor struct {
comAtt commandrun.CommandRun
Expand All @@ -45,6 +44,10 @@ func (t *TestCommandRunAttestor) RunType() attestation.RunType {
return t.comAtt.RunType()
}

func (t *TestCommandRunAttestor) Schema() *jsonschema.Schema {
return jsonschema.Reflect(&t)
}

func (t *TestCommandRunAttestor) Attest(ctx *attestation.AttestationContext) error {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions internal/attestors/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ package attestors
import (
"github.com/in-toto/go-witness/attestation"
"github.com/in-toto/go-witness/attestation/environment"
"github.com/invopop/jsonschema"
)

var (
_ environment.EnvironmentAttestor = &TestEnvironmentAttestor{}
)
var _ environment.EnvironmentAttestor = &TestEnvironmentAttestor{}

type TestEnvironmentAttestor struct {
environmentAtt environment.Attestor
Expand All @@ -44,6 +43,10 @@ func (t *TestEnvironmentAttestor) RunType() attestation.RunType {
return t.environmentAtt.RunType()
}

func (t *TestEnvironmentAttestor) Schema() *jsonschema.Schema {
return jsonschema.Reflect(&t)
}

func (t *TestEnvironmentAttestor) Attest(ctx *attestation.AttestationContext) error {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions internal/attestors/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"github.com/in-toto/go-witness/attestation"
"github.com/in-toto/go-witness/attestation/git"
"github.com/in-toto/go-witness/cryptoutil"
"github.com/invopop/jsonschema"
)

var (
_ git.GitAttestor = &TestGitAttestor{}
)
var _ git.GitAttestor = &TestGitAttestor{}

type TestGitAttestor struct {
gitAtt git.Attestor
Expand All @@ -45,6 +44,10 @@ func (t *TestGitAttestor) RunType() attestation.RunType {
return t.gitAtt.RunType()
}

func (t *TestGitAttestor) Schema() *jsonschema.Schema {
return jsonschema.Reflect(&t)
}

func (t *TestGitAttestor) Attest(ctx *attestation.AttestationContext) error {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions internal/attestors/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import (
"github.com/in-toto/go-witness/attestation/github"
"github.com/in-toto/go-witness/attestation/jwt"
"github.com/in-toto/go-witness/cryptoutil"
"github.com/invopop/jsonschema"
)

var (
_ github.GitHubAttestor = &TestGitHubAttestor{}
)
var _ github.GitHubAttestor = &TestGitHubAttestor{}

type TestGitHubAttestor struct {
githubAtt github.Attestor
Expand All @@ -47,6 +46,10 @@ func (t *TestGitHubAttestor) RunType() attestation.RunType {
return t.githubAtt.RunType()
}

func (t *TestGitHubAttestor) Schema() *jsonschema.Schema {
return jsonschema.Reflect(&t)
}

func (t *TestGitHubAttestor) Attest(ctx *attestation.AttestationContext) error {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions internal/attestors/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import (
"github.com/in-toto/go-witness/attestation/gitlab"
"github.com/in-toto/go-witness/attestation/jwt"
"github.com/in-toto/go-witness/cryptoutil"
"github.com/invopop/jsonschema"
)

var (
_ gitlab.GitLabAttestor = &TestGitLabAttestor{}
)
var _ gitlab.GitLabAttestor = &TestGitLabAttestor{}

type TestGitLabAttestor struct {
gitlabAtt gitlab.Attestor
Expand All @@ -47,6 +46,10 @@ func (t *TestGitLabAttestor) RunType() attestation.RunType {
return t.gitlabAtt.RunType()
}

func (t *TestGitLabAttestor) Schema() *jsonschema.Schema {
return jsonschema.Reflect(&t)
}

func (t *TestGitLabAttestor) Attest(ctx *attestation.AttestationContext) error {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions internal/attestors/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"github.com/in-toto/go-witness/attestation"
"github.com/in-toto/go-witness/attestation/material"
"github.com/in-toto/go-witness/cryptoutil"
"github.com/invopop/jsonschema"
)

var (
_ material.MaterialAttestor = &TestMaterialAttestor{}
)
var _ material.MaterialAttestor = &TestMaterialAttestor{}

type TestMaterialAttestor struct {
matAtt *material.Attestor
Expand All @@ -47,6 +46,10 @@ func (t *TestMaterialAttestor) RunType() attestation.RunType {
return t.matAtt.RunType()
}

func (t *TestMaterialAttestor) Schema() *jsonschema.Schema {
return jsonschema.Reflect(&t)
}

func (t *TestMaterialAttestor) Attest(ctx *attestation.AttestationContext) error {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions internal/attestors/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"github.com/in-toto/go-witness/attestation"
"github.com/in-toto/go-witness/attestation/oci"
"github.com/in-toto/go-witness/cryptoutil"
"github.com/invopop/jsonschema"
)

var (
_ oci.OCIAttestor = &TestOCIAttestor{}
)
var _ oci.OCIAttestor = &TestOCIAttestor{}

type TestOCIAttestor struct {
ociAtt oci.Attestor
Expand All @@ -45,6 +44,10 @@ func (t *TestOCIAttestor) RunType() attestation.RunType {
return t.ociAtt.RunType()
}

func (t *TestOCIAttestor) Schema() *jsonschema.Schema {
return jsonschema.Reflect(&t)
}

func (t *TestOCIAttestor) Attest(ctx *attestation.AttestationContext) error {
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions internal/attestors/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import (
"github.com/in-toto/go-witness/attestation"
"github.com/in-toto/go-witness/attestation/product"
"github.com/in-toto/go-witness/cryptoutil"
"github.com/invopop/jsonschema"
)

var (
_ product.ProductAttestor = &TestProductAttestor{}
)
var _ product.ProductAttestor = &TestProductAttestor{}

type TestProductAttestor struct {
prodAtt product.ProductAttestor
Expand All @@ -45,6 +44,10 @@ func (t *TestProductAttestor) RunType() attestation.RunType {
return t.prodAtt.RunType()
}

func (t *TestProductAttestor) Schema() *jsonschema.Schema {
return jsonschema.Reflect(&t)
}

func (t *TestProductAttestor) Attest(ctx *attestation.AttestationContext) error {
return nil
}
Expand Down
9 changes: 9 additions & 0 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/in-toto/go-witness/cryptoutil"
"github.com/in-toto/go-witness/intoto"
"github.com/in-toto/go-witness/source"
"github.com/invopop/jsonschema"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -367,6 +368,10 @@ func (DummyMaterialer) RunType() attestation.RunType {
return attestation.PreMaterialRunType
}

func (DummyMaterialer) Schema() *jsonschema.Schema {
return jsonschema.Reflect(DummyMaterialer{})
}

func (DummyMaterialer) Attest(*attestation.AttestationContext) error {
return nil
}
Expand All @@ -391,6 +396,10 @@ func (DummyProducer) RunType() attestation.RunType {
return attestation.PostProductRunType
}

func (DummyProducer) Schema() *jsonschema.Schema {
return jsonschema.Reflect(DummyProducer{})
}

func (DummyProducer) Attest(*attestation.AttestationContext) error {
return nil
}
Expand Down

0 comments on commit 9f3096e

Please sign in to comment.