mirror of
https://github.com/hanzoai/ca.git
synced 2026-11-03 18:08:27 +00:00
143 lines
3.7 KiB
Go
143 lines
3.7 KiB
Go
// Code generated by protoc-gen-go-mock. DO NOT EDIT.
|
|
// source: auth.proto
|
|
|
|
package mockpb
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/effective-security/trustyca/api/pb"
|
|
"google.golang.org/protobuf/proto"
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
)
|
|
|
|
// MockAuthServer for testing
|
|
type MockAuthServer struct {
|
|
pb.AuthServer
|
|
|
|
Reqs []proto.Message
|
|
|
|
// If set, all calls return this error.
|
|
Err error
|
|
|
|
// responses to return if err == nil
|
|
Resps []proto.Message
|
|
Index int
|
|
}
|
|
|
|
// SetResponse sets a single response without errors
|
|
func (m *MockAuthServer) SetResponse(r proto.Message) {
|
|
m.Err = nil
|
|
m.Resps = []proto.Message{r}
|
|
m.Index = 0
|
|
}
|
|
|
|
// SetResponses sets responses without errors
|
|
func (m *MockAuthServer) SetResponses(r []proto.Message) {
|
|
m.Err = nil
|
|
m.Resps = r
|
|
m.Index = 0
|
|
}
|
|
|
|
func (m *MockAuthServer) next() proto.Message {
|
|
c := len(m.Resps)
|
|
idx := m.Index
|
|
m.Index++
|
|
if idx >= c {
|
|
idx = c - 1
|
|
}
|
|
return m.Resps[idx]
|
|
}
|
|
|
|
// GetProviders returns the list of supported providers
|
|
|
|
func (m *MockAuthServer) GetProviders(ctx context.Context, req *pb.AuthProvidersRequest) (*pb.AuthProvidersResponse, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*pb.AuthProvidersResponse), nil
|
|
}
|
|
|
|
// GetUserToken returns the user token info
|
|
|
|
func (m *MockAuthServer) GetUserToken(ctx context.Context, req *emptypb.Empty) (*pb.UserTokenResponse, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*pb.UserTokenResponse), nil
|
|
}
|
|
|
|
// RevokeToken revokes the user token
|
|
|
|
func (m *MockAuthServer) RevokeToken(ctx context.Context, req *emptypb.Empty) (*emptypb.Empty, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*emptypb.Empty), nil
|
|
}
|
|
|
|
// Caller returns the caller status.
|
|
|
|
func (m *MockAuthServer) Caller(ctx context.Context, req *emptypb.Empty) (*pb.CallerStatusResponse, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*pb.CallerStatusResponse), nil
|
|
}
|
|
|
|
// ExchangeCode exchanges the one-time code for a token.
|
|
// The returned token only contains the Access Token.
|
|
// The client should call GetUserToken for full info.
|
|
|
|
func (m *MockAuthServer) ExchangeCode(ctx context.Context, req *pb.ExchangeCodeRequest) (*pb.Token, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*pb.Token), nil
|
|
}
|
|
|
|
// SelectOrg verifies the caller's access to the org and returns a new
|
|
// token scoped to it. This is the only tenant request that carries OrgID.
|
|
|
|
func (m *MockAuthServer) SelectOrg(ctx context.Context, req *pb.SelectOrgRequest) (*pb.UserTokenResponse, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*pb.UserTokenResponse), nil
|
|
}
|
|
|
|
// AuthenticateAPIKey returns the user token info.
|
|
// The caller must include the API key in the Authorization header
|
|
// with HMAC SHA256 signature of the request, using API key secret.
|
|
//
|
|
// Date: RFC3339 timestamp
|
|
// Authorization: APIKey {KeyID}:{signature}
|
|
// signature = Base64(HMAC-SHA256(secret, method + timestamp))
|
|
|
|
func (m *MockAuthServer) AuthenticateAPIKey(ctx context.Context, req *emptypb.Empty) (*pb.UserTokenResponse, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*pb.UserTokenResponse), nil
|
|
}
|
|
|
|
// GetAllowedMethods returns the allowed methods for the caller
|
|
|
|
func (m *MockAuthServer) GetAllowedMethods(ctx context.Context, req *emptypb.Empty) (*pb.ServiceAccessInfo, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*pb.ServiceAccessInfo), nil
|
|
}
|
|
|
|
// GetCallerScope returns the caller's resolved scope in the selected org:
|
|
// the org role, project roles, token scopes, and per method the roles
|
|
// and scopes it requires.
|
|
|
|
func (m *MockAuthServer) GetCallerScope(ctx context.Context, req *emptypb.Empty) (*pb.CallerScope, error) {
|
|
if m.Err != nil {
|
|
return nil, m.Err
|
|
}
|
|
return m.next().(*pb.CallerScope), nil
|
|
}
|