Hi,

I am getting 403 error code response while creating node from one site to another through functional test case. Below are the steps:

  1. Setup a multi-site that have single codebase with multiple databases e.g Site A and Site B.
  2. Enabled POST and PATCH rest service under entity:node on Site B.
  3. Created a test script which extend WebTestBase under custom module into Site A and run it. Below is the snippet
  4. public function testSimpleNodeSync() {
         $admin_user = $this->drupalCreateUser(array('administer users'));
        $this->drupalLogin($admin_user);
        $node = Node::create(['type' => 'page', 'title' => 'test', 'uid' => 1]);
        $node->save();
        $filtered_node_json = $this->filterNodeFields($node);
        $client = \Drupal::httpClient();
        try {
        $response = $client->post('http://site-b.com/entity/node', [
          'auth' => ['admin', 'admin123'],
          'headers' => [
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
          ],
          'body' => $filtered_node_json,
        ]);
        }
        catch (\Exception $e) {
          $this->fail($e->getMessage());
        }
       }
  5. It always fall under catch clause and gives 403 error.

Comments

anil.gangwal created an issue. See original summary.

Wim Leers’s picture

Category: Bug report » Support request
Status: Active » Fixed
Issue tags: -REST, -REST API, -rest services, -multi-site, -Simpletest

You forgot the X-CSRF-Token request header.

Wim Leers’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.