cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.48k stars 3.14k forks source link

Override clientCertificates configuration #27302

Open lukaslebo opened 1 year ago

lukaslebo commented 1 year ago

What would you like?

The Cypress configuration for clientCertificates allows to configure one certificate per URL. This configuration is currently readonly and cannot be overridden in the tests. I would like to override the clientCertificates for some tests.

it('test as admin', () => {
  Cypress.config({
    clientCertificates: [
      {
        url: 'https://localhost:8443',
        certs: [
          {
            cert: './cypress/cert/admin.crt',
            key: './cypress/cert/admin.key',
          },
        ],
      }
    ]
  });
  cy.visit('/');
})

it('test as user', () => {
  Cypress.config({
    clientCertificates: [
      {
        url: 'https://localhost:8443',
        certs: [
          {
            cert: './cypress/cert/user.crt',
            key: './cypress/cert/user.key',
          },
        ],
      }
    ]
  });
  cy.visit('/');
})

currently results in
CypressError: Cypress.config() can never override clientCertificates because it is a read-only configuration option.

Why is this needed?

Users authenticate with their client certificates and we need to test the behaviour for users with different roles.

Other

An Alternative could be to allow the configuration of multiple clientCertificates for the same URL and then allow to select one when visiting a site.

mnormak commented 7 months ago

Will this be done at some point? If yes, when? @nagash77

lukaslebo commented 7 months ago

@nagash77 do you have any updates for this issue?

jgreer9514 commented 3 months ago

Is there a solution that allows loading a different cert within a test? Just trying to figure out if there is a better way than having different configuration files with different certs and have different directories of tests. I basically want to submit a record, change a cert and then approve it with another cert all within the same test.

manimovassagh commented 2 months ago

I have also the same issue . I need to be able to toggle between client certificates but the config object is read only and it is not possible