Skip to content

Commit

Permalink
chore: Adds e2e tests (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
priteshbandi authored Jan 24, 2024
1 parent 4df400e commit 113b0ed
Show file tree
Hide file tree
Showing 14 changed files with 413 additions and 15 deletions.
25 changes: 22 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,29 @@ name: Build

on:
push:
branches: main
pull_request:
branches: main

permissions:
contents: read

jobs:
build:
uses: notaryproject/notation-core-go/.github/workflows/reusable-build.yml@main
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ "1.20", "1.21" ]
fail-fast: true
steps:
- name: Check out code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: Run unit tests
run: make test
- name: Run e2e tests
run: make e2e
- name: Upload coverage to codecov.io
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3.1.4
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ all: test
test: check-line-endings ## run unit tests
go test -race -v -coverprofile=coverage.txt -covermode=atomic ./...

.PHONY: e2e
e2e:
cd ./test/e2e && ./run.sh;

.PHONY: clean
clean:
git status --ignored --short | grep '^!! ' | sed 's/!! //' | xargs rm -rf
Expand Down
2 changes: 2 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This package contains examples for creating plugins in a way that enables the creation of executable binaries and
also facilitates its use as a library in notation-go
16 changes: 16 additions & 0 deletions example/envelopegenerator/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright The Notary Project 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.

go 1.20

use ./../..
File renamed without changes.
10 changes: 5 additions & 5 deletions example/plugin.go → example/envelopegenerator/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ func NewExamplePlugin() (*ExamplePlugin, error) {
return &ExamplePlugin{}, nil
}

func (p *ExamplePlugin) DescribeKey(ctx context.Context, req *plugin.DescribeKeyRequest) (*plugin.DescribeKeyResponse, error) {
func (p *ExamplePlugin) DescribeKey(_ context.Context, _ *plugin.DescribeKeyRequest) (*plugin.DescribeKeyResponse, error) {
return nil, plugin.NewUnsupportedError("DescribeKey operation is not implemented by example plugin")
}

func (p *ExamplePlugin) GenerateSignature(ctx context.Context, req *plugin.GenerateSignatureRequest) (*plugin.GenerateSignatureResponse, error) {
func (p *ExamplePlugin) GenerateSignature(_ context.Context, _ *plugin.GenerateSignatureRequest) (*plugin.GenerateSignatureResponse, error) {
return nil, plugin.NewUnsupportedError("GenerateSignature operation is not implemented by example plugin")
}

func (p *ExamplePlugin) GenerateEnvelope(ctx context.Context, req *plugin.GenerateEnvelopeRequest) (*plugin.GenerateEnvelopeResponse, error) {
func (p *ExamplePlugin) GenerateEnvelope(_ context.Context, _ *plugin.GenerateEnvelopeRequest) (*plugin.GenerateEnvelopeResponse, error) {
sig := "eyJwYXlsb2FkIjoiZXlKMFlYSm5aWFJCY25ScFptRmpkQ0k2ZXlKa2FXZGxjM1FpT2lKemFHRXlOVFk2Wm1VM1pUa3pNek16T1RVd05qQmpNbVkxWlRZelkyWXpObUV6" +
"T0daaVlURXdNVGMyWmpFNE0ySTBNVFl6WVRVM09UUmxNRGd4WVRRNE1HRmlZbUUxWmlJc0ltMWxaR2xoVkhsd1pTSTZJbUZ3Y0d4cFkyRjBhVzl1TDNadVpDNWtiMk5yWlh" +
"JdVpHbHpkSEpwWW5WMGFXOXVMbTFoYm1sbVpYTjBMbll5SzJwemIyNGlMQ0p6YVhwbElqbzVOREo5ZlEiLCJwcm90ZWN0ZWQiOiJleUpoYkdjaU9pSlFVekkxTmlJc0ltTn" +
Expand Down Expand Up @@ -67,7 +67,7 @@ func (p *ExamplePlugin) GenerateEnvelope(ctx context.Context, req *plugin.Genera
}, nil
}

func (p *ExamplePlugin) VerifySignature(ctx context.Context, req *plugin.VerifySignatureRequest) (*plugin.VerifySignatureResponse, error) {
func (p *ExamplePlugin) VerifySignature(_ context.Context, req *plugin.VerifySignatureRequest) (*plugin.VerifySignatureResponse, error) {
upAttrs := req.Signature.UnprocessedAttributes
pAttrs := make([]interface{}, len(upAttrs))
for i := range upAttrs {
Expand All @@ -89,7 +89,7 @@ func (p *ExamplePlugin) VerifySignature(ctx context.Context, req *plugin.VerifyS
}, nil
}

func (p *ExamplePlugin) GetMetadata(ctx context.Context, req *plugin.GetMetadataRequest) (*plugin.GetMetadataResponse, error) {
func (p *ExamplePlugin) GetMetadata(_ context.Context, _ *plugin.GetMetadataRequest) (*plugin.GetMetadataResponse, error) {
return &plugin.GetMetadataResponse{
SupportedContractVersions: []string{plugin.ContractVersion},
Name: "com.example.plugin",
Expand Down
7 changes: 0 additions & 7 deletions example/go.mod

This file was deleted.

Empty file removed example/go.sum
Empty file.
16 changes: 16 additions & 0 deletions example/signaturegenerator/go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright The Notary Project 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.

go 1.20

use ./../..
40 changes: 40 additions & 0 deletions example/signaturegenerator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright The Notary Project 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 main

import (
"context"
"fmt"
"os"

"github.com/notaryproject/notation-plugin-framework-go/cli"
)

func main() {
ctx := context.Background()
// Initialize plugin
plugin, err := NewExamplePlugin()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "failed to initialize plugin: %v\n", err)
os.Exit(2)
}

// Create executable
pluginCli, err := cli.New(plugin)
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "failed to create executable: %v\n", err)
os.Exit(3)
}
pluginCli.Execute(ctx, os.Args)
}
83 changes: 83 additions & 0 deletions example/signaturegenerator/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright The Notary Project 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 main

import (
"context"

"github.com/notaryproject/notation-plugin-framework-go/plugin"
)

type ExamplePlugin struct {
}

func NewExamplePlugin() (*ExamplePlugin, error) {
return &ExamplePlugin{}, nil
}

func (p *ExamplePlugin) DescribeKey(_ context.Context, req *plugin.DescribeKeyRequest) (*plugin.DescribeKeyResponse, error) {
return &plugin.DescribeKeyResponse{
KeyID: req.KeyID,
KeySpec: plugin.KeySpecRSA3072,
}, nil
}

func (p *ExamplePlugin) GenerateSignature(_ context.Context, req *plugin.GenerateSignatureRequest) (*plugin.GenerateSignatureResponse, error) {
return &plugin.GenerateSignatureResponse{
KeyID: req.KeyID,
Signature: []byte("generatedMockSignature"),
SigningAlgorithm: plugin.SignatureAlgorithmRSASSA_PSS_SHA384,
CertificateChain: [][]byte{[]byte("mockCert1"), []byte("mockCert2")},
}, nil
}

func (p *ExamplePlugin) GenerateEnvelope(_ context.Context, _ *plugin.GenerateEnvelopeRequest) (*plugin.GenerateEnvelopeResponse, error) {
return nil, plugin.NewUnsupportedError("GenerateSignature operation is not implemented by example plugin")
}

func (p *ExamplePlugin) VerifySignature(_ context.Context, req *plugin.VerifySignatureRequest) (*plugin.VerifySignatureResponse, error) {
upAttrs := req.Signature.UnprocessedAttributes
pAttrs := make([]interface{}, len(upAttrs))
for i := range upAttrs {
pAttrs[i] = upAttrs[i]
}

return &plugin.VerifySignatureResponse{
ProcessedAttributes: pAttrs,
VerificationResults: map[plugin.Capability]*plugin.VerificationResult{
plugin.CapabilityTrustedIdentityVerifier: {
Success: true,
Reason: "Valid trusted Identity",
},
plugin.CapabilityRevocationCheckVerifier: {
Success: true,
Reason: "Not revoked",
},
},
}, nil
}

func (p *ExamplePlugin) GetMetadata(_ context.Context, _ *plugin.GetMetadataRequest) (*plugin.GetMetadataResponse, error) {
return &plugin.GetMetadataResponse{
SupportedContractVersions: []string{plugin.ContractVersion},
Name: "com.example.plugin",
Description: "This is an description of example plugin",
URL: "https://example.com/notation/plugin",
Version: "1.0.0",
Capabilities: []plugin.Capability{
plugin.CapabilitySignatureGenerator,
plugin.CapabilityTrustedIdentityVerifier,
plugin.CapabilityRevocationCheckVerifier},
}, nil
}
Loading

0 comments on commit 113b0ed

Please sign in to comment.