Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to hide credentials in body throws error. #122

Open
nerrante opened this issue May 31, 2023 · 1 comment
Open

Trying to hide credentials in body throws error. #122

nerrante opened this issue May 31, 2023 · 1 comment

Comments

@nerrante
Copy link

Hi Filip,
I'm getting a TypeError when trying to hide credentials in the body of the api request. I am running v2.11.1
Let me know if you need anything else!

Here's how my env vars are set:

hideCredentials: true,
    hideCredentialsOptions: {
      headers: ['X-Header-Id'],
      auth: ['username', 'password'],
      body: ['UserName', 'Password', 'ClinicID'],
      qs: ['accessToken'],
    }

Here's the call that is failing (with some private stuff taken out):

          cy.api({
            method: 'POST',
            url: `https://anonlineapiendpoint`,
            form: true,
            body: {
              ClinicID: Cypress.env('aClinicId'),
              UserName: Cypress.env('aUserName'),
              Password: Cypress.env('aPassword'),
            },
          })

Here's the error I'm getting:
e.requestBody.body[g].replace is not a function

@iepoch
Copy link

iepoch commented Jul 7, 2023

So I have found it's not even about the hiding the credentials in the body but actually it can not replace the Variables. I have the same issue with sending in a File Name as a variable. It can not replace the variable names in the body. Which seems a miss.


Cypress.Commands.add('formRequest', (fileName) => {
  cy.fixture(fileName, 'binary')
  .then( file => Cypress.Blob.binaryStringToBlob(file))
  .then(blob =>{

    const formData = new FormData();
    formData.append("file", blob, fileName);

    const httpOptions = {
      method: 'POST',
      url: `${Cypress.env('apiUrl')}/templates`,
      headers: {
        'Authorization': Cypress.env('authToken'),
        "content-type": "multipart/form-data",
      },
      body: formData,
      failOnStatusCode: false,
    };

    cy.api(httpOptions).then(response => {
      const dec = new TextDecoder()
      response.body = dec.decode(response.body)
      expect(response.status).to.equal(400);
      return response;
    })
  })
})

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants