Merge branch 'dev' into 'staging'
feat: yoomoney host validate See merge request external/treasurer!11
This commit is contained in:
commit
984b1d6568
@ -41,7 +41,7 @@ func (receiver *YoomoneyMockService) Register(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 {
|
||||
receiver.logger.Error("failed to parse payment url on <RegisterPayment> of <YoomoneyMockService>",
|
||||
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)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
if hostURL.Scheme != paymentsURL.Scheme {
|
||||
return errors.NewWithMessage("yoomoney scheme not equal", errors.ErrInternalError)
|
||||
}
|
||||
|
||||
mockClient := wiremock.NewClient(host)
|
||||
|
||||
rule := wiremock.
|
||||
Post(wiremock.URLPathEqualTo(url.Path)).
|
||||
Post(wiremock.URLPathEqualTo(paymentsURL.Path)).
|
||||
WillReturnJSON(
|
||||
&yandex.Payment{
|
||||
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)
|
||||
}
|
||||
|
||||
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 {
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user