Files
2026-10-31 05:36:03 -05:00

269 lines
7.8 KiB
Go

// Code generated by protoc-gen-go-mock. DO NOT EDIT.
// source: ca.proto
package mockpb
import (
"context"
"github.com/effective-security/trustyca/api/pb"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/emptypb"
)
// MockCAServer for testing
type MockCAServer struct {
pb.CAServer
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 *MockCAServer) SetResponse(r proto.Message) {
m.Err = nil
m.Resps = []proto.Message{r}
m.Index = 0
}
// SetResponses sets responses without errors
func (m *MockCAServer) SetResponses(r []proto.Message) {
m.Err = nil
m.Resps = r
m.Index = 0
}
func (m *MockCAServer) next() proto.Message {
c := len(m.Resps)
idx := m.Index
m.Index++
if idx >= c {
idx = c - 1
}
return m.Resps[idx]
}
// RegisterIssuer creates a new issuing authority for the tenant.
// The private key is generated in the configured crypto provider and
// never leaves it. The certificate is signed by the parent issuer,
// self-signed for Root type, or, when no parent is available, the issuer
// is created in Pending status with a CSR to be signed externally.
func (m *MockCAServer) RegisterIssuer(ctx context.Context, req *pb.RegisterIssuerRequest) (*pb.Issuer, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.Issuer), nil
}
// UpdateIssuer updates the runtime configuration or status of an issuer.
// Status transitions: Active -> Archived -> Destroyed.
func (m *MockCAServer) UpdateIssuer(ctx context.Context, req *pb.UpdateIssuerRequest) (*pb.Issuer, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.Issuer), nil
}
// ImportIssuer registers an issuer from an existing certificate and key.
// The key is either referenced by a crypto provider URI or provided as
// PEM and stored protected. Used for bring-your-own-CA.
func (m *MockCAServer) ImportIssuer(ctx context.Context, req *pb.ImportIssuerRequest) (*pb.Issuer, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.Issuer), nil
}
// ActivateIssuer sets the externally signed certificate for a Pending
// issuer and activates it.
func (m *MockCAServer) ActivateIssuer(ctx context.Context, req *pb.ActivateIssuerRequest) (*pb.Issuer, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.Issuer), nil
}
// GetIssuer returns the issuer by ID, label or IKID
func (m *MockCAServer) GetIssuer(ctx context.Context, req *pb.GetIssuerRequest) (*pb.Issuer, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.Issuer), nil
}
// ListIssuers returns the tenant's issuers
func (m *MockCAServer) ListIssuers(ctx context.Context, req *pb.ListIssuersRequest) (*pb.IssuersResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.IssuersResponse), nil
}
// RegisterRoot registers an external trust anchor for the tenant.
// Roots created via RegisterIssuer are registered automatically.
func (m *MockCAServer) RegisterRoot(ctx context.Context, req *pb.RegisterRootRequest) (*pb.RootCertificate, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.RootCertificate), nil
}
// ListRoots returns the tenant's trust anchors
func (m *MockCAServer) ListRoots(ctx context.Context, req *pb.ListRootsRequest) (*pb.RootsResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.RootsResponse), nil
}
// RegisterProfile creates or replaces a certificate profile, keyed by
// (org, ProjectID, Label)
func (m *MockCAServer) RegisterProfile(ctx context.Context, req *pb.RegisterProfileRequest) (*pb.CertProfile, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.CertProfile), nil
}
// GetProfile returns the profile by ID or label
func (m *MockCAServer) GetProfile(ctx context.Context, req *pb.GetProfileRequest) (*pb.CertProfile, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.CertProfile), nil
}
// ListProfiles returns the tenant's profiles
func (m *MockCAServer) ListProfiles(ctx context.Context, req *pb.ListProfilesRequest) (*pb.ProfilesResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.ProfilesResponse), nil
}
// DeleteProfile deletes a profile
func (m *MockCAServer) DeleteProfile(ctx context.Context, req *pb.DeleteProfileRequest) (*emptypb.Empty, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*emptypb.Empty), nil
}
// SignCertificate signs a certificate request with the profile's issuer
func (m *MockCAServer) SignCertificate(ctx context.Context, req *pb.SignCertificateRequest) (*pb.CertificateResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.CertificateResponse), nil
}
// GetCertificate returns the certificate by ID, SKID, Sha256 or
// issuer and serial number
func (m *MockCAServer) GetCertificate(ctx context.Context, req *pb.GetCertificateRequest) (*pb.CertificateResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.CertificateResponse), nil
}
// ListCertificates returns the tenant's certificates, newest first
func (m *MockCAServer) ListCertificates(ctx context.Context, req *pb.ListCertificatesRequest) (*pb.CertificatesResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.CertificatesResponse), nil
}
// UpdateCertificateLabel updates the client-provided label and metadata
func (m *MockCAServer) UpdateCertificateLabel(ctx context.Context, req *pb.UpdateCertificateLabelRequest) (*pb.CertificateResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.CertificateResponse), nil
}
// RevokeCertificate revokes the certificate
func (m *MockCAServer) RevokeCertificate(ctx context.Context, req *pb.RevokeCertificateRequest) (*pb.RevokedCertificateResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.RevokedCertificateResponse), nil
}
// ListRevokedCertificates returns the tenant's revoked certificates
func (m *MockCAServer) ListRevokedCertificates(ctx context.Context, req *pb.ListRevokedCertificatesRequest) (*pb.RevokedCertificatesResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.RevokedCertificatesResponse), nil
}
// GetCRL returns the current CRL of the issuer
func (m *MockCAServer) GetCRL(ctx context.Context, req *pb.GetCrlRequest) (*pb.CrlResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.CrlResponse), nil
}
// PublishCrls generates and publishes CRLs on demand: the CRL of the
// issuer of the IKID, or the due CRLs of the issuers in scope. A project
// Admin and an API key restricted to a project publish for their project.
// The scheduled CRL renewal task publishes the due CRLs of every org
// in-process.
func (m *MockCAServer) PublishCrls(ctx context.Context, req *pb.PublishCrlsRequest) (*pb.CrlsResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.CrlsResponse), nil
}
// SignOCSP signs an OCSP response; the AIA OCSP responder calls
// Backend.SignOCSP.
func (m *MockCAServer) SignOCSP(ctx context.Context, req *pb.OCSPRequest) (*pb.OCSPResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.OCSPResponse), nil
}
// GetSummary returns the counts of the tenant's dashboard: the issuers
// by status, the certificates by status and by expiry, and the issuers
// that publish CRLs by the state of their CRL, for the org or for one
// project. Without a project, a member with project grants only gets
// the org-wide rows and those of its projects, as the lists do.
func (m *MockCAServer) GetSummary(ctx context.Context, req *pb.GetSummaryRequest) (*pb.SummaryResponse, error) {
if m.Err != nil {
return nil, m.Err
}
return m.next().(*pb.SummaryResponse), nil
}