cy.request() TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["cookie"]

Viewed 808

In order to avoid logging in before each of my cypress tests, I am trying to use the oauth token endpoint. However, I must not be calling it quite right because I get an error when I make the cy.request. Can anyone tell what I'm missing?

Cypress.Commands.add('getAccessToken', (username, password) => {
  const options = {
    method: 'POST',
    url: AUTH_JWT_URL,
    form: true,
    body: {
      grant_type: 'password',
      username,
      password,
      audience: 'urn:com:xxx',
      scope: 'openid offline_access',
      client_id: AUTH_CLIENT_ID,
      client_secret: AUTH_CLIENT_SECRET,
      connection: 'xxx',
    },
  };

  cy.request(options).its('body').then(({ access_token, refresh_token }) => {
    window.currentAccessToken = access_token;
    window.currentRefreshToken = refresh_token;
    return { access_token, refresh_token };
  });
});

Cypress.Commands.add('login', (username, password) => {
  cy.log('loginViaJWT');
  cy.getAccessToken(username, password).then(({ access_token, refresh_token }) => {
    const options = {
      method: 'POST',
      url: AUTH_SIGNIN_URL,
      form: true,
      retryOnStatusCodeFailure: true,
      body: {
        access_token,
        refresh_token,
      },
    };

    cy.request(options);
  });
});

When doing the POST to the oauth/token endpoint, I get:

CypressError
cy.request() failed trying to load:

https://idp.xxx.xxx.io/oauth/token

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["cookie"]
0 Answers
Related