Documentation
¶
Overview ¶
Package testing is what the API key packages' tests share: a database of a test package's own, on the server TEST_DATABASE_URL names, with the library's tables in it; accounts in it; and session tokens for them, signed by a key the tests hold, as a browser or a minted token would carry them.
It is the one package of the library that reaches a database through a driver, and nothing but tests imports it, so a service importing the library is not made to build pgx unless it already does.
Index ¶
- Constants
- Variables
- func ApiKeyAuthorizer() (*authorizer_request_parser.Parser, error)
- func Db(t testing.TB) *sql.DB
- func InsertCustomer(ctx context.Context, db *sql.DB, name string) (string, error)
- func Main(m *testing.M, name string) int
- func Schema() (string, error)
- func SessionManager(db *sql.DB) (*session_manager.Manager, error)
- type Account
- type Database
- type Session
Constants ¶
const ( // Issuer is what the sessions here are issued by, and what Authorizer expects. Issuer = "https://login.example.test" // Audience is what the sessions here are for: the cookie domain of the session manager. Audience = "example.test" )
const DatabaseUrlVariable = "TEST_DATABASE_URL"
DatabaseUrlVariable names the server the tests run against, as a postgres:// URL of a role that may create databases. Without it, the tests that need a database skip.
const UnrecordedAuthenticationId = "00000000-0000-0000-0000-000000000000"
UnrecordedAuthenticationId is the sign-in a session names when nothing about it is in the database: enough for an endpoint that judges the token alone, and refused by one that looks the sign-in up.
Variables ¶
var ( // SessionMethod signs the sessions made here and verifies them in the authorizers. SessionMethod *altshiftCryptoEddsa.Method // Authorizer is an authorizer as an endpoint for a signed-in person has one: the session in a // cookie, and the browser's ways of signing in and no other. Authorizer *authorizer_request_parser.Parser )
Functions ¶
func ApiKeyAuthorizer ¶
func ApiKeyAuthorizer() (*authorizer_request_parser.Parser, error)
ApiKeyAuthorizer is an authorizer as an endpoint for API clients has one: the token as a bearer token, minted against a key and in no other way.
func InsertCustomer ¶
InsertCustomer makes a customer, which an account belongs to when it is given one.
func Main ¶
* Main is a test package's TestMain, as os.Exit(Main(m, "package_name")). * * Where DatabaseUrlVariable names a server, the package's tests run with a database of their own, * which Db hands out; where it does not, they run without one, and Db skips the tests that would * have used it. The tests that need no database run either way.
func Schema ¶
Schema is the SQL the library's tables generate: an account with its customer, its sign-ins, and the keys it registers with what they mint.
func SessionManager ¶
func SessionManager(db *sql.DB) (*session_manager.Manager, error)
SessionManager mints sessions signed by SessionMethod, issued by Issuer for Audience.
Types ¶
type Account ¶
Account is an account as the tests make one.
func InsertAccount ¶
func InsertAccount( ctx context.Context, db *sql.DB, emailAddress string, customerId string, roles ...string, ) (*Account, error)
InsertAccount makes an account with the roles, belonging to the customer where one is named.
func (*Account) ActiveSession ¶
ActiveSession is a session for the account whose sign-in is in the database and running, which is what an endpoint that checks a session against the database finds standing behind it.
type Database ¶
Database is a database made for one test package, dropped again when it is closed.
func NewDatabase ¶
* NewDatabase makes a database of its own on the server databaseUrl reaches and applies Schema to it. * * It is named after name with a random suffix, so that two runs side by side -- the packages of one * `go test ./...`, or two of those -- never share one. The connection databaseUrl makes is kept for * dropping it again.
type Session ¶
type Session struct {
AccountId string
EmailAddress string
AuthenticationId string
Roles []string
// AuthenticationMethods is the token's "amr"; a browser's sign-in where it is left empty.
AuthenticationMethods []string
}
Session is a session token's subject and the sign-in it names.