cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Override clientCertificates configuration

Open lukaslebo opened this issue 1 year ago • 4 comments

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.

lukaslebo avatar Jul 14 '23 09:07 lukaslebo

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

mnormak avatar Nov 24 '23 11:11 mnormak

@nagash77 do you have any updates for this issue?

lukaslebo avatar Dec 12 '23 16:12 lukaslebo

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.

jgreer9514 avatar Mar 20 '24 16:03 jgreer9514

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

manimovassagh avatar May 15 '24 22:05 manimovassagh