-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PLAT-559: sender test Co-authored-by: mariavasilenko <[email protected]> Co-authored-by: Eugene Blikh <[email protected]>
- Loading branch information
1 parent
627dd54
commit 9141aec
Showing
2 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Copyright 2020 Insolar Network Ltd. | ||
// All rights reserved. | ||
// This material is licensed under the Insolar License version 1.0, | ||
// available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md. | ||
|
||
package integration | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/gojuno/minimock/v3" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/insolar/assured-ledger/ledger-core/insolar/jet" | ||
"github.com/insolar/assured-ledger/ledger-core/insolar/payload" | ||
"github.com/insolar/assured-ledger/ledger-core/instrumentation/inslogger" | ||
"github.com/insolar/assured-ledger/ledger-core/reference" | ||
commontestutils "github.com/insolar/assured-ledger/ledger-core/testutils" | ||
"github.com/insolar/assured-ledger/ledger-core/virtual/authentication" | ||
"github.com/insolar/assured-ledger/ledger-core/virtual/integration/utils" | ||
) | ||
|
||
var messagesWithoutToken = []struct { | ||
name string | ||
msg interface{} | ||
ignoreSenderCheck bool | ||
}{ | ||
{ | ||
name: "VCallRequest", | ||
msg: &payload.VCallRequest{}, | ||
}, | ||
{ | ||
name: "VCallResult", | ||
msg: &payload.VCallResult{}, | ||
}, | ||
{ | ||
name: "VStateRequest", | ||
msg: &payload.VStateRequest{}, | ||
}, | ||
{ | ||
name: "VStateReport", | ||
msg: &payload.VStateReport{}, | ||
}, | ||
{ | ||
name: "VDelegatedCallRequest", | ||
msg: &payload.VDelegatedCallRequest{}, | ||
}, | ||
{ | ||
name: "VDelegatedCallResponse", | ||
msg: &payload.VDelegatedCallResponse{}, | ||
}, | ||
{ | ||
name: "VFindCallRequest", | ||
msg: &payload.VFindCallRequest{}, | ||
}, | ||
{ | ||
name: "VFindCallResponse", | ||
msg: &payload.VFindCallResponse{}, | ||
ignoreSenderCheck: true, | ||
}, | ||
} | ||
|
||
type reseter interface { | ||
Reset() | ||
} | ||
|
||
func TestVirtual_SenderCheck_With_ExpectedVE(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
caseId string | ||
senderIsEqualExpectedVE bool | ||
}{ | ||
{"Sender is equal expectedVE", "C5188", true}, | ||
{"Sender is not equal expectedVE", "C5196", false}, | ||
} | ||
|
||
for _, cases := range testCases { | ||
t.Run(cases.name, func(t *testing.T) { | ||
t.Log(cases.caseId) | ||
for _, testMsg := range messagesWithoutToken { | ||
t.Run(testMsg.name, func(t *testing.T) { | ||
defer commontestutils.LeakTester(t) | ||
|
||
mc := minimock.NewController(t) | ||
|
||
server, ctx := utils.NewUninitializedServerWithErrorFilter(nil, t, func(s string) bool { | ||
return false | ||
}) | ||
|
||
jetCoordinatorMock := jet.NewAffinityHelperMock(mc) | ||
auth := authentication.NewService(ctx, jetCoordinatorMock) | ||
server.ReplaceAuthenticationService(auth) | ||
|
||
var ( | ||
unexpectedError error | ||
errorFound bool | ||
) | ||
{ | ||
logHandler := func(arg interface{}) { | ||
err, ok := arg.(error) | ||
if !ok { | ||
return | ||
} | ||
|
||
errorMsg := err.Error() | ||
if strings.Contains(errorMsg, "unexpected sender") && | ||
strings.Contains(errorMsg, "illegitimate msg") { | ||
errorFound = true | ||
} else { | ||
unexpectedError = err | ||
} | ||
} | ||
logger := utils.InterceptLog(inslogger.FromContext(ctx), logHandler) | ||
server.OverrideConveyorFactoryLogContext(inslogger.SetLogger(ctx, logger)) | ||
} | ||
|
||
server.Init(ctx) | ||
server.IncrementPulseAndWaitIdle(ctx) | ||
|
||
if !testMsg.ignoreSenderCheck { | ||
rv := server.RandomGlobalWithPulse() | ||
if cases.senderIsEqualExpectedVE { | ||
rv = server.GlobalCaller() | ||
} | ||
jetCoordinatorMock.QueryRoleMock.Return([]reference.Global{rv}, nil) | ||
} | ||
|
||
testMsg.msg.(reseter).Reset() | ||
server.SendPayload(ctx, testMsg.msg.(payload.Marshaler)) // default caller == server.GlobalCaller() | ||
|
||
server.WaitIdleConveyor() | ||
|
||
expectNoError := cases.senderIsEqualExpectedVE || testMsg.ignoreSenderCheck == true | ||
assert.Equal(t, !expectNoError, errorFound, "Fail "+testMsg.name) | ||
assert.NoError(t, unexpectedError) | ||
|
||
server.Stop() | ||
mc.Finish() | ||
}) | ||
} | ||
}) | ||
} | ||
} |