anvil

package
v0.0.0-...-ee64981 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package anvil runs functional tests for the Thing SDK

Index

Constants

View Source
const (
	PassString = "\033[1;32mPASS\033[0m"
	FailString = "\033[1;31mFAIL\033[0m"

	// Standard timeout used in SDK calls in tests
	StdTimeOut = 10 * time.Second

	RootRealm = "/"

	GatewayClientType = "gateway"
	AMClientType      = "am"
)

Variables

View Source
var DebugLogger = log.New(ioutil.Discard, "", 0)
View Source
var ProgressLogger = log.New(os.Stdout, "", 0)

Functions

func BaseURL

func BaseURL() *url.URL

BaseURL returns the root realm URL of AM

func CertVerificationKey

func CertVerificationKey() (*jose.JSONWebKey, error)

CertVerificationKey returns the test JSON web key used by AM to verify certificates

func ConfigureTestRealm

func ConfigureTestRealm(realm string, testDataDir string) (err error)

ConfigureTestRealm configures the realm by loading all the data in the testDataDir

func CreateCertVerificationMapping

func CreateCertVerificationMapping() error

CreateCertVerificationMapping maps the IoT certification verification secret to the test key

func CreateCertificate

func CreateCertificate(caWebKey *jose.JSONWebKey, thingID string, thingKey crypto.Signer) (*x509.Certificate, error)

CreateCertificate creates a certificate for a Thing signed by the given CA JSON web key

func CreateRealmHierarchy

func CreateRealmHierarchy(names ...string) (fullName string, ids []string, err error)

CreateRealmHierarchy creates the supplied realms in a linear hierarchy The first realm is a child of root, otherwise a realm is a child of the previously created realm Returns the fully-qualified name of the leaf realm and a list of ids of all the created realms

func CreateRealmWithAlias

func CreateRealmWithAlias(name string, alias string) (id string, err error)

CreateRealmWithAlias creates a test realm with an alias

func CreateRealmWithDNSAlias

func CreateRealmWithDNSAlias(name string, alias string) (id string, err error)

CreateRealmWithDNSAlias creates a test realm with a DNS alias

func DeleteRealms

func DeleteRealms(ids []string) (err error)

DeleteRealms deletes all the realms in the id slice from the AM instance Assumes that the ids are in an order that can be safely deleted e.g. children before parents

func GetIdentityAttributes

func GetIdentityAttributes(realm, name string, attributes interface{}) error

GetIdentityAttributes gets the identity and unmarshals its attributes into the supplied struct

func ModifyOAuth2Provider

func ModifyOAuth2Provider(realm string, clientBased bool, signingAlgorithm jose.SignatureAlgorithm) (original []byte, err error)

ModifyOAuth2Provider changes the OAuth 2.0 access tokens issued by AM Returns the original configuration so that the provider can be restored

func NewFileDebugger

func NewFileDebugger(directory, testName string) (*log.Logger, *os.File)

NewFileDebugger creates a new Anvil logger that logs to file with the given test name

func RandomName

func RandomName() string

RandomName returns a random string

func RestoreOAuth2Service

func RestoreOAuth2Service(realm string, config []byte) error

RestoreOAuth2Service restores the OAut 2.0 service using the supplied config

func RestoreTestRealm

func RestoreTestRealm(realm string, testDataDir string) (err error)

RestoreTestRealm restores the configuration of the realm to a pre-test state

func RunTest

func RunTest(state TestState, t SDKTest) (pass bool)

RunTest runs the given SDKTest

func TestName

func TestName(t SDKTest) string

TestName returns the name of the test

func TestThingGateway

func TestThingGateway(u *url.URL, realm string, audience string, authTree string, dnsConfigured bool) (*gateway.ThingGateway, error)

TestThingGateway creates a test Thing Gateway

func TypeName

func TypeName(t interface{}) string

TypeName returns the name of the type after removing the package prefix

func URL

func URL(subDomain string) *url.URL

URL returns an AM URL that points at the given sub-domain

Types

type AMTestState

type AMTestState struct {
	Realm         string
	TestAudience  string
	TestURL       *url.URL
	DNSConfigured bool
}

AMTestState contains data and methods for testing the AM client

func (*AMTestState) Audience

func (a *AMTestState) Audience() string

func (*AMTestState) ClientType

func (a *AMTestState) ClientType() string

func (*AMTestState) RealmForConfiguration

func (a *AMTestState) RealmForConfiguration() string

func (*AMTestState) SetGatewayTree

func (a *AMTestState) SetGatewayTree(tree string)

func (*AMTestState) TestRealm

func (a *AMTestState) TestRealm() string

func (*AMTestState) URL

func (a *AMTestState) URL() *url.URL

type NopSetupCleanup

type NopSetupCleanup struct {
}

NopSetupCleanup defines a struct with no-op Setup and Cleanup methods

func (NopSetupCleanup) Cleanup

Cleanup is a no op function

func (NopSetupCleanup) NameSuffix

func (t NopSetupCleanup) NameSuffix() string

NameSuffix returns the empty string

func (NopSetupCleanup) Setup

func (t NopSetupCleanup) Setup() bool

Setup is a no op function

type SDKTest

type SDKTest interface {
	Setup(state TestState) (data ThingData, ok bool)     // setup actions before the test starts
	Run(state TestState, data ThingData) bool            // function that runs and validates the test
	Cleanup(state TestState, data ThingData) (err error) // cleanup actions after the test has finished
	NameSuffix() string                                  // optional suffix to add to struct name to create the test name
}

SDKTest defines the interface required by a SDK API test

type SigningKey

type SigningKey struct {
	KID    string
	Signer crypto.Signer
}

SigningKey describes a key used for signing messages sent to AM

func ConfirmationKey

func ConfirmationKey(algorithm jose.SignatureAlgorithm) (public jose.JSONWebKeySet, private SigningKey, err error)

ConfirmationKey returns a key for signing requests to AM that is accompanied by a restricted PoP SSO token.

type TestState

type TestState interface {
	// RealmForConfiguration returns the realm that can be used for test setup, validation and clean up
	RealmForConfiguration() string
	// TestRealm returns the test realm that should be passed to the Thing SDK
	TestRealm() string
	// Audience returns the JWT audience for the current test realm
	Audience() string
	// ClientType returns 'am' or 'gateway' depending on the type of client
	ClientType() string
	// URL of the current test server (AM or Gateway)
	URL() *url.URL
	// SetGatewayTree sets the auth tree used by the test Thing Gateway
	SetGatewayTree(tree string)
}

TestState contains client and realm data required to run a test

type ThingData

type ThingData struct {
	Id           am.IdAttributes
	Signer       SigningKey
	Certificates []*x509.Certificate
}

ThingData holds information about a Thing used in a test

func CreateIdentity

func CreateIdentity(realm string, data ThingData) (ThingData, bool)

Create an identity in AM from the supplied data uses sensible defaults for certain fields if none have been set

type ThingGatewayTestState

type ThingGatewayTestState struct {
	ThingGateway *gateway.ThingGateway
	Realm        string
	TestAudience string
}

ThingGatewayTestState contains data and methods for testing the Thing Gateway client

func (*ThingGatewayTestState) Audience

func (i *ThingGatewayTestState) Audience() string

func (*ThingGatewayTestState) ClientType

func (i *ThingGatewayTestState) ClientType() string

func (*ThingGatewayTestState) RealmForConfiguration

func (i *ThingGatewayTestState) RealmForConfiguration() string

func (*ThingGatewayTestState) SetGatewayTree

func (i *ThingGatewayTestState) SetGatewayTree(tree string)

func (*ThingGatewayTestState) TestRealm

func (i *ThingGatewayTestState) TestRealm() string

func (*ThingGatewayTestState) URL

func (i *ThingGatewayTestState) URL() *url.URL

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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