github.com/prebid/prebid-server/v2@v2.18.0/experiment/adscert/signer_test.go (about) 1 package adscert 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/IABTechLab/adscert/pkg/adscert/api" 8 "github.com/prebid/prebid-server/v2/config" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestNilSigner(t *testing.T) { 13 config := config.ExperimentAdsCert{Mode: "off", InProcess: config.AdsCertInProcess{Origin: ""}, Remote: config.AdsCertRemote{Url: ""}} 14 signer, err := NewAdCertsSigner(config) 15 assert.NoError(t, err, "error should not be returned if not inprocess nor remote signer defined, NilSigner should be returned instead") 16 message, err := signer.Sign("test.com", nil) 17 assert.NoError(t, err, "NilSigner should not return an error") 18 assert.Equal(t, "", message, "incorrect message returned NilSigner") 19 } 20 21 func TestNilSignerForAdsCertDisabled(t *testing.T) { 22 config := config.ExperimentAdsCert{Mode: "off", InProcess: config.AdsCertInProcess{Origin: ""}, Remote: config.AdsCertRemote{Url: ""}} 23 signer, err := NewAdCertsSigner(config) 24 assert.NoError(t, err, "error should not be returned if AdsCerts feature is disabled") 25 message, err := signer.Sign("test.com", nil) 26 assert.NoError(t, err, "NilSigner should not return an error") 27 assert.Equal(t, "", message, "incorrect message returned NilSigner") 28 } 29 30 type MockLocalAuthenticatedConnectionsSignatory struct { 31 returnError bool 32 operationStatusOk bool 33 } 34 35 func (ips *MockLocalAuthenticatedConnectionsSignatory) SignAuthenticatedConnection(request *api.AuthenticatedConnectionSignatureRequest) (*api.AuthenticatedConnectionSignatureResponse, error) { 36 if ips.returnError { 37 return nil, errors.New("Test error") 38 } 39 response := &api.AuthenticatedConnectionSignatureResponse{ 40 RequestInfo: &api.RequestInfo{ 41 SignatureInfo: []*api.SignatureInfo{ 42 {SignatureMessage: "Success"}, 43 }, 44 }, 45 } 46 if ips.operationStatusOk { 47 response.SignatureOperationStatus = api.SignatureOperationStatus_SIGNATURE_OPERATION_STATUS_OK 48 } else { 49 response.SignatureOperationStatus = api.SignatureOperationStatus_SIGNATURE_OPERATION_STATUS_UNDEFINED 50 } 51 return response, nil 52 } 53 func (ips *MockLocalAuthenticatedConnectionsSignatory) VerifyAuthenticatedConnection(request *api.AuthenticatedConnectionVerificationRequest) (*api.AuthenticatedConnectionVerificationResponse, error) { 54 return nil, nil 55 }