Documentation
¶
Overview ¶
Package fakeapi provides a fake Snyk API server for tests. It serves machine enrollment, tokens, whoami, the machine's and the authenticated principal's own records, and organizations. It independently verifies everything the client signs, so a client bug cannot pass by agreeing with itself.
Index ¶
- func DecodeJWT(t *testing.T, token string) (header, claims map[string]any)
- func VerifyJWT(token string, pub crypto.PublicKey) error
- type Server
- func (s *Server) AddOrg(orgID, tenantID string)
- func (s *Server) AllowFleetKey(pub *ecdsa.PublicKey, machineIDs ...string)
- func (s *Server) BearerTokens() []string
- func (s *Server) ClientCount() int
- func (s *Server) ClientKey(clientID string) *rsa.PublicKey
- func (s *Server) CredentialHeaders() []string
- func (s *Server) DeprovisionMachine(machineID string)
- func (s *Server) EnrollmentRequests() int
- func (s *Server) FailMachineSelf(status int)
- func (s *Server) IssueDeviceToken(machineID string) string
- func (s *Server) MachineSelfRequests() int
- func (s *Server) OrgRequests() int
- func (s *Server) RegisterClient(clientID string, key *rsa.PublicKey)
- func (s *Server) RegisterClientSecret(clientID, secret string)
- func (s *Server) RegisterMachine(serialNumbers ...string) string
- func (s *Server) RegisterPAT(pat string)
- func (s *Server) RevokeClient(clientID string)
- func (s *Server) SetDefaultOrg(orgID string)
- func (s *Server) SetErrorTitles(on bool)
- func (s *Server) SetTenantID(tenantID string)
- func (s *Server) TokenAttempts() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Server ¶
type Server struct {
*httptest.Server
// TokenRequests counts accepted token requests.
TokenRequests int
// contains filtered or unexported fields
}
Server is a fake API serving the enrollment and token endpoints.
func (*Server) AddOrg ¶
AddOrg makes the organization record for orgID exist, naming tenantID as its tenant, or no tenant if tenantID is empty.
func (*Server) AllowFleetKey ¶
AllowFleetKey registers the public half of a fleet key and allows it for the machines.
func (*Server) BearerTokens ¶
BearerTokens returns the bearer tokens that requests carried in their Authorization header, in the order they arrived.
func (*Server) ClientCount ¶
ClientCount returns how many clients are registered, whether active or not.
func (*Server) CredentialHeaders ¶
CredentialHeaders returns the names of the credential headers (Authorization, Session-Token) that requests carried, one entry per header per request. The enrollment endpoints take none.
func (*Server) DeprovisionMachine ¶
DeprovisionMachine retires a machine: it can't enroll again, with any join material.
func (*Server) EnrollmentRequests ¶
EnrollmentRequests returns how many requests reached the enrollment endpoint, accepted or not.
func (*Server) FailMachineSelf ¶
FailMachineSelf makes the machine's own record answer with status and a JSON:API error, whoever asks.
func (*Server) IssueDeviceToken ¶
IssueDeviceToken returns a new single-use device token for a registered machine, as an admin gets. Like the service, it revokes the machine's earlier device tokens.
func (*Server) MachineSelfRequests ¶
MachineSelfRequests returns how many requests reached the machine's own record, answered or not.
func (*Server) OrgRequests ¶
OrgRequests returns how many requests reached an organization record, answered or not.
func (*Server) RegisterClient ¶
RegisterClient makes the token endpoint accept client assertions for clientID signed by key.
func (*Server) RegisterClientSecret ¶
RegisterClientSecret makes the token endpoint accept the shared secret for clientID, in the Authorization header or in the request body.
func (*Server) RegisterMachine ¶
RegisterMachine registers a machine with serial numbers, as an admin does, and returns its id.
func (*Server) RegisterPAT ¶
RegisterPAT makes GET /rest/self accept pat, sent as the API sends a token: "Authorization: token <pat>".
func (*Server) RevokeClient ¶
RevokeClient makes the token endpoint reject clientID and invalidates the access tokens issued to it, as an admin revoking the client does.
func (*Server) SetDefaultOrg ¶
SetDefaultOrg sets the organization the principal's own record names as its default.
func (*Server) SetErrorTitles ¶
SetErrorTitles sets whether enrollment error responses carry a JSON:API title.
func (*Server) SetTenantID ¶
SetTenantID sets the tenant the machine's own record names.
func (*Server) TokenAttempts ¶
TokenAttempts returns how many requests reached the token endpoint, accepted or not.