9737c787f9
Инфраструктура M2M (живой обмен с НРД через ИШ): - обработка M2MTransferResponse: ERROR(M2Mxx) → заявка Отклонена, сохранение ответа; INFO → ждём Decision; идемпотентность поллера - fallback-корреляция ответов с нулевым GUID (M2M14/M2M17) по FIFO - сырой XML ответа НРД в карточке заявки (для пересылки в ТП) - тестовый пакет роботу приведён к эталону m2m_robot_samples (CostInfo=Yes, 4 бумаги, IsolationStatus, DocumentSeries=сценарий); override паспорта - редирект из теста сразу в карточку заявки Мастер установки ключа Валидаты на флешку (admin/setup/keywizard): - пошаговый: загрузка .7z+пароль → выбор флешки → запись → справочник сертификатов (CRL) → перезапуск+проверка ИШ → готово - привилегированный воркер (bj-keymedia) в host-namespace через файл-обмен, bj-server остаётся в песочнице - сохранение структуры профиля архива (spr<N>), перечисление съёмных USB Прочее: - пакет-доказательство для ТП НРД + форма регистрации участника M2M - эталонные образцы робота (DOC/m2m_robot_samples) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
202 lines
7.3 KiB
Go
202 lines
7.3 KiB
Go
package m2mcore_test
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.zetit.ru/zuevav/Bridge-and-Join-s/internal/m2m"
|
|
"git.zetit.ru/zuevav/Bridge-and-Join-s/internal/m2mcore"
|
|
)
|
|
|
|
// fakeStore — тестовая реализация FansyStore.
|
|
type fakeStore struct {
|
|
client *m2mcore.Client
|
|
accounts []m2mcore.DepoAccount
|
|
getErr error
|
|
}
|
|
|
|
func (f *fakeStore) GetClientByID(_ context.Context, _ string) (*m2mcore.Client, error) {
|
|
if f.getErr != nil {
|
|
return nil, f.getErr
|
|
}
|
|
return f.client, nil
|
|
}
|
|
|
|
func (f *fakeStore) GetDepoAccounts(_ context.Context, _ string, _ m2m.OrganizationINN) ([]m2mcore.DepoAccount, error) {
|
|
return f.accounts, nil
|
|
}
|
|
|
|
func (f *fakeStore) GetBalances(_ context.Context, _ string, _ []m2m.SecurityCode) ([]m2mcore.SecurityBalance, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func TestNewReferenceIDFormat(t *testing.T) {
|
|
at := time.Date(2026, 3, 2, 14, 30, 0, 0, time.UTC)
|
|
id, err := m2mcore.NewReferenceID(at)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if string(id)[:11] != "M2M20260302" {
|
|
t.Errorf("префикс/дата ReferenceID неверен: %q", id)
|
|
}
|
|
}
|
|
|
|
func TestEnrichRequestHappyPath(t *testing.T) {
|
|
store := &fakeStore{
|
|
client: &m2mcore.Client{
|
|
ID: "inv-1",
|
|
LastName: "Иванов",
|
|
FirstName: "Иван",
|
|
MiddleName: "Иванович",
|
|
Document: m2mcore.ClientDocument{
|
|
DocumentType: m2m.DocCode21,
|
|
Series: "4512",
|
|
Number: "654321",
|
|
},
|
|
},
|
|
accounts: []m2mcore.DepoAccount{
|
|
{
|
|
ID: "acc-1",
|
|
ClientID: "inv-1",
|
|
DeponentCode: "DP789456",
|
|
AccountID: m2m.AccountID("31MC0021900000F01"),
|
|
SectionID: "P001",
|
|
DepositoryINN: m2m.OrganizationINN("7702070139"),
|
|
},
|
|
},
|
|
}
|
|
whole := uint64(1500)
|
|
isin := m2m.ISIN("RU0007661625")
|
|
|
|
claim := m2mcore.ClaimInput{
|
|
InvestorClientID: "inv-1",
|
|
TransferringDepositoryINN: m2m.OrganizationINN("0702345678"),
|
|
ReceivingDepositoryINN: m2m.OrganizationINN("0710987654"),
|
|
CostInfo: m2m.CostInfo{
|
|
No: &m2m.CostInfoNo{},
|
|
},
|
|
Securities: []m2mcore.ClaimSecurityInput{
|
|
{
|
|
SecurityCode: m2m.SecurityCode("MM0766162534"),
|
|
Details: m2m.SecurityDetails{ISIN: &isin},
|
|
Quantity: m2m.Quantity{Whole: &whole},
|
|
},
|
|
},
|
|
}
|
|
codes := m2mcore.SenderReceiver{
|
|
SenderCode: m2m.DeponentCode("MC0079200000"),
|
|
ReceiverCode: m2m.DeponentCode("MC0010300000"),
|
|
}
|
|
|
|
req, err := m2mcore.EnrichRequest(context.Background(), store, claim, codes)
|
|
if err != nil {
|
|
t.Fatalf("EnrichRequest: %v", err)
|
|
}
|
|
if err := req.Validate(); err != nil {
|
|
t.Fatalf("собранный Request не прошёл валидацию: %v", err)
|
|
}
|
|
if req.Data.InvestorInformation.LastName != "Иванов" {
|
|
t.Errorf("LastName не пробросился")
|
|
}
|
|
if len(req.Data.TransferredSecurities.Securities) != 1 {
|
|
t.Errorf("ожидалась 1 ЦБ, получено %d", len(req.Data.TransferredSecurities.Securities))
|
|
}
|
|
}
|
|
|
|
// TestEnrichRequestDocumentOverride — для теста с роботом НРД серия ДУЛ
|
|
// кодирует сценарий. Override должен заместить паспорт из анкеты, оставив ФИО.
|
|
func TestEnrichRequestDocumentOverride(t *testing.T) {
|
|
store := &fakeStore{
|
|
client: &m2mcore.Client{
|
|
ID: "inv-1", LastName: "Иванов", FirstName: "Иван", MiddleName: "Иванович",
|
|
Document: m2mcore.ClientDocument{
|
|
DocumentType: m2m.DocCode21, Series: "4513", Number: "654322",
|
|
},
|
|
},
|
|
accounts: []m2mcore.DepoAccount{{
|
|
ID: "acc-1", ClientID: "inv-1", DeponentCode: "DP789456",
|
|
AccountID: m2m.AccountID("31MC0021900000F01"), SectionID: "P001",
|
|
DepositoryINN: m2m.OrganizationINN("7702070139"),
|
|
}},
|
|
}
|
|
whole := uint64(1)
|
|
isin := m2m.ISIN("RU0007661625")
|
|
claim := m2mcore.ClaimInput{
|
|
InvestorClientID: "inv-1",
|
|
TransferringDepositoryINN: m2m.OrganizationINN("0702345678"),
|
|
ReceivingDepositoryINN: m2m.OrganizationINN("0710987654"),
|
|
CostInfo: m2m.CostInfo{No: &m2m.CostInfoNo{}},
|
|
Securities: []m2mcore.ClaimSecurityInput{{
|
|
SecurityCode: m2m.SecurityCode("RU0007661625"),
|
|
Details: m2m.SecurityDetails{ISIN: &isin}, Quantity: m2m.Quantity{Whole: &whole},
|
|
}},
|
|
// Сценарий робота 2001 в серии ДУЛ.
|
|
InvestorDocument: &m2mcore.ClientDocument{
|
|
DocumentType: m2m.DocCode21, Series: "2001", Number: "111111",
|
|
},
|
|
}
|
|
req, err := m2mcore.EnrichRequest(context.Background(), store, claim, m2mcore.SenderReceiver{
|
|
SenderCode: m2m.DeponentCode("MC0413600000"), ReceiverCode: m2m.DeponentCode("MC0012500000"),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("EnrichRequest: %v", err)
|
|
}
|
|
doc := req.Data.InvestorInformation.IdentityDocument
|
|
if doc.DocumentSeries == nil || string(*doc.DocumentSeries) != "2001" {
|
|
t.Errorf("DocumentSeries = %v, ожидалось 2001 (override сценария)", doc.DocumentSeries)
|
|
}
|
|
if string(doc.DocumentNumber) != "111111" {
|
|
t.Errorf("DocumentNumber = %q, ожидалось 111111", doc.DocumentNumber)
|
|
}
|
|
// ФИО берётся из анкеты, не из override.
|
|
if req.Data.InvestorInformation.LastName != "Иванов" {
|
|
t.Errorf("ФИО должно остаться из анкеты, получено %q", req.Data.InvestorInformation.LastName)
|
|
}
|
|
}
|
|
|
|
func TestEnrichRequestNoAccounts(t *testing.T) {
|
|
store := &fakeStore{
|
|
client: &m2mcore.Client{LastName: "X", FirstName: "Y", Document: m2mcore.ClientDocument{DocumentType: m2m.DocCode21, Number: "1"}},
|
|
accounts: nil,
|
|
}
|
|
_, err := m2mcore.EnrichRequest(context.Background(), store, m2mcore.ClaimInput{}, m2mcore.SenderReceiver{})
|
|
if err == nil {
|
|
t.Errorf("ожидалась ошибка при отсутствии счетов")
|
|
}
|
|
}
|
|
|
|
func TestEnrichRequestStoreError(t *testing.T) {
|
|
store := &fakeStore{getErr: errors.New("db down")}
|
|
_, err := m2mcore.EnrichRequest(context.Background(), store, m2mcore.ClaimInput{}, m2mcore.SenderReceiver{})
|
|
if err == nil {
|
|
t.Errorf("ожидалась ошибка от FansyStore")
|
|
}
|
|
}
|
|
|
|
func TestNoopPortsReturnErrNotImplemented(t *testing.T) {
|
|
ctx := context.Background()
|
|
if _, err := (m2mcore.NoopNSDSender{}).Send(ctx, nil); !errors.Is(err, m2mcore.ErrNotImplemented) {
|
|
t.Errorf("NoopNSDSender.Send ожидалась ErrNotImplemented, получено %v", err)
|
|
}
|
|
if err := (m2mcore.NoopNSDSender{}).SendDecision(ctx, nil); !errors.Is(err, m2mcore.ErrNotImplemented) {
|
|
t.Errorf("NoopNSDSender.SendDecision ожидалась ErrNotImplemented, получено %v", err)
|
|
}
|
|
if err := (m2mcore.NoopLKCallbackClient{}).UpdateStatus(ctx, "", "", ""); !errors.Is(err, m2mcore.ErrNotImplemented) {
|
|
t.Errorf("LKCallbackClient ожидалась ErrNotImplemented")
|
|
}
|
|
if _, err := (m2mcore.NoopCryptoVerifier{}).VerifyXMLDSig(ctx, nil); !errors.Is(err, m2mcore.ErrNotImplemented) {
|
|
t.Errorf("CryptoVerifier ожидалась ErrNotImplemented")
|
|
}
|
|
if _, err := (m2mcore.NoopFansyStore{}).GetClientByID(ctx, ""); !errors.Is(err, m2mcore.ErrNotImplemented) {
|
|
t.Errorf("FansyStore.GetClientByID ожидалась ErrNotImplemented")
|
|
}
|
|
if _, err := (m2mcore.NoopFansyStore{}).GetDepoAccounts(ctx, "", ""); !errors.Is(err, m2mcore.ErrNotImplemented) {
|
|
t.Errorf("FansyStore.GetDepoAccounts ожидалась ErrNotImplemented")
|
|
}
|
|
if _, err := (m2mcore.NoopFansyStore{}).GetBalances(ctx, "", nil); !errors.Is(err, m2mcore.ErrNotImplemented) {
|
|
t.Errorf("FansyStore.GetBalances ожидалась ErrNotImplemented")
|
|
}
|
|
}
|