0

On one side I have a remote Drupal 8 (8.8.1) served via HTTPS which has the following endpoint:

MODULENAME.get_notify:
  path: 'MODULENAME/get-notify'
  defaults:
    _controller: '\Drupal\MODULENAME\Controller\MODULENAMEApiController::get_notify'
    _title: 'Get notification'
  methods:  [POST]
  requirements:
    _access: 'TRUE'

On the client side I have a Drupal 8 (8.8.2) served via HTTPS which sends a notification using Guzzle library. This Drupal is local to my machine and is served via DDEV. Here is the Guzzle petition which is located in a custom module:

$options = [
  'headers' => ['Content-Type' => 'application/json'],
  'json' => $jsonArray,
  'timeout' => 15,
];
$response = $this->httpClient->post($url, $options);

The system works well except that when running PHPUnit tests (BrowserTestBase) of the involved module the POST query always return the following error:

Client error: `POST https://SERVER_DOMAIN/MODULENAME/get-notify` resulted in a `403 Forbidden` response'

Any idea why I get this error message?

2
  • Are you sure SERVER_DOMAIN resolves to the remote host address and not somewhere else in your containerized DDEV environment? Is there a reason you're not mocking your HTTP client/requests for the unit test? What's being tested in the unit test?
    – Shawn Conn
    Mar 4, 2020 at 19:39
  • Yes, If i do a ping inside DDEV machine or in host machine the result is the same: the server side responds. Also, If I do the same POST request which is done in tested function via terminal curl request, it works fine in both DDEV and host machine. In this unit test I send a notification with some data and I expect an OK response from the server side. The code which sends the POST request is inside a function which is part of a service declared on MODULENAME.services.yml.
    – Roger
    Mar 17, 2020 at 21:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.