...

Source file src/github.com/letsencrypt/boulder/ra/mock_test.go

Documentation: github.com/letsencrypt/boulder/ra

     1  package ra
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	corepb "github.com/letsencrypt/boulder/core/proto"
     8  	"github.com/letsencrypt/boulder/mocks"
     9  	sapb "github.com/letsencrypt/boulder/sa/proto"
    10  	grpc "google.golang.org/grpc"
    11  	"google.golang.org/grpc/codes"
    12  	"google.golang.org/grpc/status"
    13  	emptypb "google.golang.org/protobuf/types/known/emptypb"
    14  	"google.golang.org/protobuf/types/known/timestamppb"
    15  )
    16  
    17  type mockInvalidAuthorizationsAuthority struct {
    18  	mocks.StorageAuthority
    19  	domainWithFailures string
    20  }
    21  
    22  // SetCertificateStatusReady implements proto.StorageAuthorityClient
    23  func (*mockInvalidAuthorizationsAuthority) SetCertificateStatusReady(ctx context.Context, in *sapb.Serial, opts ...grpc.CallOption) (*emptypb.Empty, error) {
    24  	return nil, status.Error(codes.Unimplemented, "unimplemented mock")
    25  }
    26  
    27  func (sa *mockInvalidAuthorizationsAuthority) CountOrders(_ context.Context, _ *sapb.CountOrdersRequest, _ ...grpc.CallOption) (*sapb.Count, error) {
    28  	return &sapb.Count{}, nil
    29  }
    30  
    31  func (sa *mockInvalidAuthorizationsAuthority) PreviousCertificateExists(_ context.Context, _ *sapb.PreviousCertificateExistsRequest, _ ...grpc.CallOption) (*sapb.Exists, error) {
    32  	return &sapb.Exists{
    33  		Exists: false,
    34  	}, nil
    35  }
    36  
    37  func (sa *mockInvalidAuthorizationsAuthority) CountInvalidAuthorizations2(ctx context.Context, req *sapb.CountInvalidAuthorizationsRequest, _ ...grpc.CallOption) (*sapb.Count, error) {
    38  	if req.Hostname == sa.domainWithFailures {
    39  		return &sapb.Count{Count: 1}, nil
    40  	} else {
    41  		return &sapb.Count{}, nil
    42  	}
    43  }
    44  
    45  // An authority that returns nonzero failures for CountInvalidAuthorizations2,
    46  // and also returns existing authzs for the same domain from GetAuthorizations2
    47  type mockInvalidPlusValidAuthzAuthority struct {
    48  	mockInvalidAuthorizationsAuthority
    49  }
    50  
    51  func (sa *mockInvalidPlusValidAuthzAuthority) GetAuthorizations2(ctx context.Context, req *sapb.GetAuthorizationsRequest, _ ...grpc.CallOption) (*sapb.Authorizations, error) {
    52  	date := time.Date(2101, 12, 3, 0, 0, 0, 0, time.UTC)
    53  
    54  	return &sapb.Authorizations{
    55  		Authz: []*sapb.Authorizations_MapElement{
    56  			{
    57  				Domain: sa.domainWithFailures, Authz: &corepb.Authorization{
    58  					Id:             "1234",
    59  					Status:         "valid",
    60  					Identifier:     sa.domainWithFailures,
    61  					RegistrationID: 1234,
    62  					ExpiresNS:      date.Unix(),
    63  					Expires:        timestamppb.New(date),
    64  				},
    65  			},
    66  		},
    67  	}, nil
    68  }
    69  

View as plain text