# Request failed with status code 403 in test environment

**URL:** <https://community.forestadmin.com/t/request-failed-with-status-code-403-in-test-environment/3648>\
**Category:** Help me!\
**Created:** [October 29, 2021, 9:18pm UTC](https://community.forestadmin.com/t/request-failed-with-status-code-403-in-test-environment/3648 "2021-10-29T21:18:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathieu\_Breton](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mathieu_breton/32/63_2.png) [@Mathieu\_Breton](https://community.forestadmin.com/u/Mathieu_Breton)\
**Post date:** [October 29, 2021, 9:18pm UTC](https://community.forestadmin.com/t/request-failed-with-status-code-403-in-test-environment/3648/1 "2021-10-29T21:18:31Z")

</div>

## Expected behavior

When I run an integration test which calls my Forest Admin backend to check if routes work, I should be able to call them correctly.

## Actual behavior

Since we updated the forest-express-sequelize dependency in our Nodejs project from 8.2.8 to 8.4.7, these are broken we got a 403 error.  
Despite of the error message below saying envSecret is missing, is actually wrong. I added a log in “forest-server-requester.js” (in the node\_modules) to check if I didn’t make mistake to pass the env variable.

## Failure Logs

```javascript
[forest] 🌳🌳🌳 Permissions error: Cannot retrieve the data from the Forest server. Can you check that you properly copied the Forest envSecret in the Liana initializer?
 FAIL test/integration/features/document.integration.spec.ts (18.089 s)
  Document
    ✓ should create document (851 ms)
    ✓ should update document (153 ms)
    Forest Display
      ✕ should get all Documents (210 ms)
      ✕ should get a single Document (151 ms)

  ● Document › Forest Display › should get all Documents

    Request failed with status code 403

      at createError (node_modules/axios/lib/core/createError.js:16:15)
      at settle (node_modules/axios/lib/core/settle.js:17:12)
      at IncomingMessage.handleStreamEnd (node_modules/axios/lib/adapters/http.js:260:11)

```

## Context

// test.ts

```javascript
describe("Forest Display", () => {
    let forestToken = "";

    beforeAll(async () => {
      forestToken = await getForestToken();
    });

    it("should get all Documents", async () => {
      const result = await callForestRoute("http://localhost:6009/forest/Document", forestToken);
      expect(result.data.data).toHaveLength(3);
    });

```

// utils.ts

```javascript
export const getForestToken = async () => {
  const FOREST_AUTH_SECRET = env().FOREST_AUTH_SECRET;
  const user = {
    id: "44907",
    email: "toto.toto@swan.io",
    firstName: "toto",
    lastName: "toto",
    team: "Banking Operations",
    renderingId: 80198,
  };
  return jwt.sign(user, FOREST_AUTH_SECRET, {
    expiresIn: "30 minutes",
  });
};

export const callForestRoute = async (url: string, forestToken: string, params?: object) => {
  const config = {
    method: "get",
    url,
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${forestToken}`,
    },
    params: {
      timezone: "Europe/Paris",
      ...params,
    },
  } as AxiosRequestConfig;

  return axios(config);
};

```

- Package Version: 8.4.7
- Express Version: 4.17.1
- Sequelize Version: 5.22.3
- Database Dialect: PG
- Database Version: 11
- Project Name: Swan backoffice

---

<div class="post-metadata">

**Author:** ![anon79585656](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@anon79585656](https://community.forestadmin.com/u/anon79585656)\
**Post date:** [November 2, 2021, 10:50am UTC](https://community.forestadmin.com/t/request-failed-with-status-code-403-in-test-environment/3648/2 "2021-11-02T10:50:11Z")

</div>

Hello @Mathieu_Breton

Thank you for reporting this, and sorry for the inconvenience.

I’m looking into the code changes now, but would you mind helping me by narrowing which intermediate version broke the test on your end?

Here is the full list of minor versions from `8.2.8` to `8.4.7`:

- v8.2.8
- v8.2.9
- v8.3.0
- v8.3.1
- v8.3.2
- v8.3.3
- v8.4.0
- v8.4.1
- v8.4.2
- v8.4.3
- v8.4.4
- v8.4.5
- v8.4.6
- v8.4.7

Maybe try `8.3.0` and `8.4.0` first?

Thank you.

---

<div class="post-metadata">

**Author:** ![Mathieu\_Breton](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mathieu_breton/32/63_2.png) [@Mathieu\_Breton](https://community.forestadmin.com/u/Mathieu_Breton)\
**Post date:** [November 9, 2021, 12:10pm UTC](https://community.forestadmin.com/t/request-failed-with-status-code-403-in-test-environment/3648/3 "2021-11-09T12:10:52Z")

</div>

Hello,

Finally, I figured out the problem. It’s not related to the versions. The problem still occurred on v8.2.8.  
By digging in the forest-express-sequelize code, we found the property `role` was mandatory in the JWT sent to the forest endpoints. So If I update the code shown before, the code looks like that:

```javascript
export const getForestToken = async () => {
  const FOREST_AUTH_SECRET = env().FOREST_AUTH_SECRET;
  const user = {
    id: "44907",
    email: "toto.toto@swan.io",
    firstName: "toto",
    lastName: "toto",
    team: 62937,
    renderingId: 105033,
    role: 957,
  };
  return jwt.sign(user, FOREST_AUTH_SECRET, {
    expiresIn: "30 minutes",
  });
};

```

I don’t know why it appears now but it solved our problem.  
You should update your doc : [Run automated tests - Woodshop](https://docs.forestadmin.com/woodshop/how-tos/run-automated-tests)  
It doesn’t mention this property.

---

<div class="post-metadata">

**Author:** ![Arnaud\_Moncel](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud_moncel/32/24_2.png) [@Arnaud\_Moncel](https://community.forestadmin.com/u/Arnaud_Moncel)\
**Post date:** [November 9, 2021, 1:31pm UTC](https://community.forestadmin.com/t/request-failed-with-status-code-403-in-test-environment/3648/4 "2021-11-09T13:31:56Z")

</div>

Hi @Mathieu_Breton👋 Thank a lot for your feedback 🙏  
I will update the documentation.  
Can I solved this thread ?

---

<div class="post-metadata">

**Author:** ![Mathieu\_Breton](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mathieu_breton/32/63_2.png) [@Mathieu\_Breton](https://community.forestadmin.com/u/Mathieu_Breton)\
**Post date:** [November 9, 2021, 2:06pm UTC](https://community.forestadmin.com/t/request-failed-with-status-code-403-in-test-environment/3648/5 "2021-11-09T14:06:11Z")

</div>

Yes, you can mark it as solved.
