I come with a question because I have an application, it has IAP as a proxy before seeing the rest of the page. I want to test this page, however, IAP is standing in my way. I'm trying to wade through the docs, but I don't understand which way of authentication I may need to use.
I tried with Application Default Credentials as I have that JSON auth file and env pointing at that, and after going to the site, I get a 403 that I can't access the site. Maybe I'm doing something wrong in general?
cypress.config.ts
import { GoogleAuth } from 'google-auth-library';
const GOOGLE_PROJECT_ID = 1234567;
async setupNodeEvents(on, config): Promise<Cypress.PluginConfigOptions> {
// ... other functions, working with async/await
on('task', {
getIAPToken: async () => {
console.log(' Initialized GoogleAuth');
const auth = new GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
const client = await auth.getClient();
const projectId = GOOGLE_PROJECT_ID;
const iapUrl = `https://iap.googleapis.com/projects/${projectId}/iap_web/auth`;
console.log(' Requesting IAP');
const response = await client.request({ url: iapUrl });
return response;
},
});
return config;
},
test.cy.ts
describe('Smoke tests', () => {
it('content is not visible', () => {
cy.visit("https://some-page-behind-iap.com");
cy.contains("Content!").should(content => expect(content).to.not.be.visible;
});
it('content is visible', () => {
cy.visit("https://some-page-behind-iap.com");
cy.task('getIAPToken').then((data) => {
console.log("loaded:", data);
});
cy.contains("Content!").should(content => expect(content).to.be.visible;
});
});