anvil

package
v7.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package anvil runs functional tests for the IoT 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 (
	// CTS based (stateful) access token type
	CTS = AccessTokenType{/* contains filtered or unexported fields */}
	// Client based (stateless) encrypted access token type
	ClientEncrypted = AccessTokenType{/* contains filtered or unexported fields */}
)
View Source
var DebugLogger = log.New(io.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 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(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 CreateSoftwareStatement added in v7.2.0

func CreateSoftwareStatement(clientJWK jose.JSONWebKey) (string, error)

CreateSoftwareStatement creates a software statement for a Thing signed with the configured Software Publisher key

func CreateUser added in v7.1.0

func CreateUser(realm string) (am.IdAttributes, error)

CreateUser creates a human identity in AM with a unique name.

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 ModifyOAuth2Provider

func ModifyOAuth2Provider(realm string, tokenType AccessTokenType) (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 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 RevokeAccessToken added in v7.1.0

func RevokeAccessToken(realm string, token string) error

RevokeAccessToken uses the custom OAuth 2.0 client to revoke the access token

func RunTest

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

RunTest runs the given SDKTest

func TestGateway added in v7.1.0

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

TestGateway creates a test IoT Gateway

func TestName

func TestName(t SDKTest) string

TestName returns the name of the test

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 AccessTokenType added in v7.1.0

type AccessTokenType struct {
	// contains filtered or unexported fields
}

AccessTokenType is used to configure the type of OAuth2 access token issues by AM

func ClientSignedTokenType added in v7.1.0

func ClientSignedTokenType(alg jose.SignatureAlgorithm) AccessTokenType

ClientSignedTokenType returns a client based (stateless) signed token type

func (AccessTokenType) Name added in v7.1.0

func (a AccessTokenType) Name() string

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(state TestState) (data ThingData, ok 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 struct {
	// contains filtered or unexported fields
}

TestState contains client and realm data required to run a test

func NewTestState added in v7.2.0

func NewTestState(gateway *gateway.Gateway, amURL *url.URL, realm, realmPath string, dns bool) TestState

NewTestState will create a new TestState instance with the given properties

func (*TestState) AMURL added in v7.2.0

func (t *TestState) AMURL() string

AMURL returns the URL of the AM server as a string

func (*TestState) ClientType

func (t *TestState) ClientType() string

ClientType returns 'am' or 'gateway' depending on the type of client

func (*TestState) ConnectionURL added in v7.2.0

func (t *TestState) ConnectionURL() *url.URL

ConnectionURL of the current test server (AM or Gateway)

func (*TestState) DNSConfigured added in v7.2.0

func (t *TestState) DNSConfigured() bool

DNSConfigured will be true if DNS configuration is used instead of a realm path

func (*TestState) Realm added in v7.2.0

func (t *TestState) Realm() string

Realm returns the test realm that should be passed to the IoT SDK

func (*TestState) RealmForConfiguration

func (t *TestState) RealmForConfiguration() string

RealmForConfiguration returns the realm that can be used for test setup, validation and clean up

func (*TestState) RealmPath added in v7.2.0

func (t *TestState) RealmPath() string

RealmPath returns the path of the current test realm

func (*TestState) SetGatewayTree

func (t *TestState) SetGatewayTree(tree string)

SetGatewayTree sets the auth tree used by the test IoT Gateway

func (*TestState) String added in v7.2.0

func (t *TestState) String() string

type ThingData

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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