Documentation ¶
Overview ¶
dynoidtest provides helper functions for testing code that uses DynoID
Index ¶
Examples ¶
Constants ¶
const ( DefaultHerokuHost = "heroku.local" // issuer host used when one is not provided DefaultSpaceID = "test" // space id used when one is not provided DefaultAppID = "00000000-0000-0000-0000-000000000001" // app id used when one is not provided DefaultAppName = "sushi" // app name used when one is not provided DefaultDyno = "web.1" // dyno used when one is not provided )
Variables ¶
This section is empty.
Functions ¶
func GenerateDefaultFS ¶ added in v0.4.0
Configure dynoid.DefaultFS to use tokens generated by the provided issuer for the audiences listed.
Types ¶
type FS ¶ added in v0.3.0
type FS struct {
// contains filtered or unexported fields
}
FS implements fs.ReadFileFS and is suitable for testing reading tokens.
type Issuer ¶
type Issuer struct {
// contains filtered or unexported fields
}
Issuer generates test tokens and provides a client for verifying them.
Example ¶
package main import ( "context" "fmt" "github.com/heroku/x/dynoid" "github.com/heroku/x/dynoid/dynoidtest" ) const Audience = "testing" func main() { ctx, iss, err := dynoidtest.NewWithContext(context.Background()) if err != nil { panic(err) } if err := dynoidtest.GenerateDefaultFS(iss, Audience); err != nil { panic(err) } token, err := dynoid.ReadLocalToken(ctx, Audience) if err != nil { panic(err) } fmt.Println(token.Subject.AppID) fmt.Println(token.Subject.AppName) fmt.Println(token.Subject.Dyno) }
Output: 00000000-0000-0000-0000-000000000001 sushi web.1
func NewWithContext ¶ added in v0.2.0
Create a new Issuer with the supplied opts applied inheriting from the provided context
func (*Issuer) GenerateIDToken ¶
GenerateIDToken returns a new signed token as a string
func (*Issuer) HTTPClient ¶
HTTPClient returns a client that leverages the Issuer to validate tokens.
type IssuerOpt ¶ added in v0.3.0
type IssuerOpt interface {
// contains filtered or unexported methods
}
IssuerOpt allows the behavior of the issuer to be modified.
func WithHerokuHost ¶ added in v0.4.0
WithHerokuHost allows an issuer host to be supplied instead of using the default
func WithKey ¶ added in v0.4.0
func WithKey(key *rsa.PrivateKey) IssuerOpt
WithKey allows you to set the issuer's private key. Useful for leveraging test middleware.
func WithSpaceID ¶ added in v0.3.0
WithSpaceID allows a spaceID to be supplied instead of using the default
func WithTokenOpts ¶ added in v0.3.0
WithTokenOpts allows a default set of TokenOpt to be applied to every token generated by the issuer
type LocalConfiguration ¶ added in v0.4.0
type LocalConfiguration struct {
// contains filtered or unexported fields
}
LocalConfiguration provides methods for working with a local issuer configured with ConfigureLocal
func ConfigureLocal ¶ added in v0.4.0
func ConfigureLocal(audiences []string, opts ...IssuerOpt) (*LocalConfiguration, error)
ConfigureLocal sets up the environment with a local DynoID issuer and generates tokens for the audiences provided.
The returned LocalConfiguration provides methods for working with the issuer.
func ConfigureLocalWithContext ¶ added in v0.4.0
func (*LocalConfiguration) Context ¶ added in v0.4.0
func (c *LocalConfiguration) Context() context.Context
func (*LocalConfiguration) GenerateToken ¶ added in v0.4.0
func (c *LocalConfiguration) GenerateToken(audience string) (string, error)
GenerateToken mints a token for the given audience using the configured issuer.
func (*LocalConfiguration) Handler ¶ added in v0.4.0
func (c *LocalConfiguration) Handler() http.Handler
Handler mints tokens for the configured issuer using for the audience specified by the audience query param.
func (*LocalConfiguration) Middleware ¶ added in v0.4.0
func (c *LocalConfiguration) Middleware() func(http.Handler) http.Handler
The Middleware should be inserted in the middleware stack before any functions that use dynoid are called.
type TokenOpt ¶ added in v0.3.0
type TokenOpt interface {
// contains filtered or unexported methods
}
A TokenOpt modifies the way a token is minted
func WithSubject ¶ added in v0.3.0
WithSubject allows the Subject to be different than the default