filiphric / cypress-plugin-api

Cypress plugin to show your API information in the Cypress UI runner
ISC License
250 stars 33 forks source link

Trying to hide credentials in body throws error. #122

Open nerrante opened 1 year ago

nerrante commented 1 year ago

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 commented 1 year ago

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