predicate injection not setting authorization header

30 views
Skip to first unread message

Noel Yap

unread,
Jun 27, 2024, 5:42:15 PM6/27/24
to mountebank-discuss
I have the following:
```
        {
          predicates: [
            {
              inject: "function (config) { config.request.headers.Authorization = config.state.token; config.logger.info(`********************** token=${JSON.stringify(config.request)}`); return true; }",
            },
          ],
          responses: [
            {
              proxy: {
                to: "https://www.example.net",
                mode: "proxyTransparent",
              },
              behaviors: [
                {
                  decorate: "(config) => { config.logger.info(`@@@@@@@@@@@@@@@@@@@@@ request=${JSON.stringify(config.request)}`); config.logger.info(`@@@@@@@@@@@@@@@@@@@@@ response=${JSON.stringify(config.response)}`); }",
                },
              ],
            },
          ],
        }
```

The line with `***` indicates the `Authorization` header being set correctly but the line with `@@@` doesn't reflect that setting

Using `injectHeaders` to set `Authorization` works fine but I'm not seeing a way to use that with `config.state.token`

How can I go about setting `Authorization` based on a token gotten dynamically?

Thanks,
Noel
Reply all
Reply to author
Forward
0 new messages