validationtesting

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AlicePrivateKey       = "" /* 184-byte string literal not displayed */
	AlicePublicKey        = "" /* 132-byte string literal not displayed */
	AlicePublicKeyEscaped = `` /* 132-byte string literal not displayed */

	BobPrivateKey       = "" /* 184-byte string literal not displayed */
	BobPublicKey        = "" /* 132-byte string literal not displayed */
	BobPublicKeyEscaped = `` /* 132-byte string literal not displayed */

	CarolPrivateKey       = "" /* 184-byte string literal not displayed */
	CarolPublicKey        = "" /* 132-byte string literal not displayed */
	CarolPublicKeyEscaped = `` /* 132-byte string literal not displayed */
)

These are the test key pairs of Alice and Bob.

View Source
const AuctionJSONStepsRules = `` /* 628-byte string literal not displayed */

AuctionJSONStepsRules is a set of steps validation rules for the auction process.

View Source
const ChatJSONStepsRules = `` /* 337-byte string literal not displayed */

ChatJSONStepsRules is a set of steps validation rules for the chat process.

Variables

View Source
var (
	AuctionJSONRules = CreateValidatorJSON("auction", AuctionJSONPKI, AuctionJSONStepsRules)
	ChatJSONRules    = CreateValidatorJSON("chat", ChatJSONPKI, ChatJSONStepsRules)
	TestJSONRules    = fmt.Sprintf(`{%s,%s}`, AuctionJSONRules, ChatJSONRules)
)

Sample test validation rules exported by this package.

View Source
var (
	// Plugin missing the required Validate func.
	PluginMissingValidate = []byte(`
		package main

		import (
			"context"
		
			"github.com/stratumn/go-core/store"
			"github.com/stratumn/go-core/types"
		)

		func NotValidate(_ context.Context, _ store.SegmentReader, _ *types.Link) error {
			return nil
		}

		func main() {}
	`)

	// Plugin containing an invalid Validate func (signature doesn't match).
	PluginInvalidValidate = []byte(`
		package main

		import (
			"github.com/stratumn/go-core/store"
			"github.com/stratumn/go-core/types"
		)

		func Validate(_ store.SegmentReader, _ *types.Link) error {
			return nil
		}

		func main() {}
	`)

	// Plugin that returns a validation failure.
	PluginValidationError = []byte(`
		package main

		import (
			"context"
			"errors"
		
			"github.com/stratumn/go-core/store"
			"github.com/stratumn/go-core/types"
		)

		func Validate(_ context.Context, _ store.SegmentReader, _ *types.Link) error {
			return errors.New("invalid link")
		}

		func main() {}
	`)

	// Plugin that returns a validation success.
	PluginValidationSuccess = []byte(`
		package main

		import (
			"context"
			"errors"
		
			"github.com/stratumn/go-core/store"
			"github.com/stratumn/go-core/types"
		)

		func Validate(_ context.Context, _ store.SegmentReader, l *types.Link) error {
			if l.Link.Meta.Process == nil {
				return errors.New("link is missing process")
			}

			return nil
		}

		func main() {}
	`)
)

Sample validation plugins.

View Source
var AuctionJSONPKI = fmt.Sprintf(`
{
	"alice.vandenbudenmayer@stratumn.com": {
		"keys": ["%s"],
		"roles": ["employee"]
	},
	"Bob Wagner": {
		"keys": ["%s"],
		"roles": ["manager", "it"]
	}
}
`, AlicePublicKeyEscaped, BobPublicKeyEscaped)

AuctionJSONPKI is a sample PKI for the auction process.

View Source
var ChatJSONPKI = fmt.Sprintf(`
{
	"Bob Wagner": {
		"keys": ["%s"],
		"roles": ["manager", "it"]
	}
}
`, BobPublicKeyEscaped)

ChatJSONPKI is a sample PKI for the chat process.

Functions

func CompilePlugin

func CompilePlugin(t *testing.T, pluginContent []byte) (string, []byte)

CompilePlugin compiles the given plugin and stores it in a temporary folder. The name of the file will be its hex-encoded hash. It returns the path to the directory and the compiled file hash.

func CreateValidatorJSON

func CreateValidatorJSON(name, pki, stepsRules string) string

CreateValidatorJSON formats a PKI and steps rules into a valid JSON configuration.

func UnmarshalPKI

func UnmarshalPKI(data []byte) (*validators.PKI, error)

UnmarshalPKI unmarshals a JSON-formatted PKI.

func UnmarshalStepsRules

func UnmarshalStepsRules(data []byte) (map[string]*validation.StepRules, error)

UnmarshalStepsRules unmarshals JSON-formatted steps validation rules.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL