feat: yoomoney host validate
This commit is contained in:
parent
ebd9639162
commit
c5a8f6baeb
@ -41,7 +41,7 @@ func (receiver *YoomoneyMockService) Register(host string) errors.Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (receiver *YoomoneyMockService) RegisterPayments(host string) errors.Error {
|
func (receiver *YoomoneyMockService) RegisterPayments(host string) errors.Error {
|
||||||
url, parseErr := url.Parse(receiver.yoomoneyURL.Payments)
|
paymentsURL, parseErr := url.Parse(receiver.yoomoneyURL.Payments)
|
||||||
if parseErr != nil {
|
if parseErr != nil {
|
||||||
receiver.logger.Error("failed to parse payment url on <RegisterPayment> of <YoomoneyMockService>",
|
receiver.logger.Error("failed to parse payment url on <RegisterPayment> of <YoomoneyMockService>",
|
||||||
zap.Error(parseErr),
|
zap.Error(parseErr),
|
||||||
@ -51,14 +51,28 @@ func (receiver *YoomoneyMockService) RegisterPayments(host string) errors.Error
|
|||||||
return errors.NewWithError(fmt.Errorf("failed to parse payment url: %w", parseErr), errors.ErrInternalError)
|
return errors.NewWithError(fmt.Errorf("failed to parse payment url: %w", parseErr), errors.ErrInternalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
if url.Host != host {
|
hostURL, parseErr := url.Parse(host)
|
||||||
|
if parseErr != nil {
|
||||||
|
receiver.logger.Error("failed to parse payment url on <RegisterPayment> of <YoomoneyMockService>",
|
||||||
|
zap.Error(parseErr),
|
||||||
|
zap.String("url", receiver.yoomoneyURL.Payments),
|
||||||
|
)
|
||||||
|
|
||||||
|
return errors.NewWithError(fmt.Errorf("failed to parse payment url: %w", parseErr), errors.ErrInternalError)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hostURL.Host != paymentsURL.Host {
|
||||||
return errors.NewWithMessage("yoomoney hosts not equal", errors.ErrInternalError)
|
return errors.NewWithMessage("yoomoney hosts not equal", errors.ErrInternalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hostURL.Scheme != paymentsURL.Scheme {
|
||||||
|
return errors.NewWithMessage("yoomoney scheme not equal", errors.ErrInternalError)
|
||||||
|
}
|
||||||
|
|
||||||
mockClient := wiremock.NewClient(host)
|
mockClient := wiremock.NewClient(host)
|
||||||
|
|
||||||
rule := wiremock.
|
rule := wiremock.
|
||||||
Post(wiremock.URLPathEqualTo(url.Path)).
|
Post(wiremock.URLPathEqualTo(paymentsURL.Path)).
|
||||||
WillReturnJSON(
|
WillReturnJSON(
|
||||||
&yandex.Payment{
|
&yandex.Payment{
|
||||||
ID: "f32d71f4-214b-464b-94bb-f7b4d5299af0",
|
ID: "f32d71f4-214b-464b-94bb-f7b4d5299af0",
|
||||||
@ -82,7 +96,7 @@ func (receiver *YoomoneyMockService) RegisterPayments(host string) errors.Error
|
|||||||
return errors.NewWithError(fmt.Errorf("failed to init payment mock handler: %w", err), errors.ErrInternalError)
|
return errors.NewWithError(fmt.Errorf("failed to init payment mock handler: %w", err), errors.ErrInternalError)
|
||||||
}
|
}
|
||||||
|
|
||||||
isVerified, err := mockClient.Verify(wiremock.NewRequest("post", wiremock.URLPathEqualTo(url.Path)), 0)
|
isVerified, err := mockClient.Verify(wiremock.NewRequest("post", wiremock.URLPathEqualTo(paymentsURL.Path)), 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
receiver.logger.Error("failed to verify payment mock handler on <RegisterPayment> of <YoomoneyMockService>", zap.Error(err))
|
receiver.logger.Error("failed to verify payment mock handler on <RegisterPayment> of <YoomoneyMockService>", zap.Error(err))
|
||||||
return errors.NewWithError(fmt.Errorf("failed to verify payment mock handler: %w", err), errors.ErrInternalError)
|
return errors.NewWithError(fmt.Errorf("failed to verify payment mock handler: %w", err), errors.ErrInternalError)
|
||||||
|
Loading…
Reference in New Issue
Block a user