This repository has been archived by the owner on Nov 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from coltdorsey/kirk/cypress_change_to_proxy_a…
…uth_header Use Proxy-Authentication header
- Loading branch information
Showing
4 changed files
with
42 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
module.exports = (on, config) => { | ||
on('task', { | ||
async getIAPToken({ url, cid }) { | ||
const { GoogleAuth } = require('google-auth-library'); | ||
const auth = new GoogleAuth(); | ||
const client = await auth.getIdTokenClient(cid); | ||
const res = await client.request({ url }); | ||
return res.config.headers.Authorization.split(" ")[1] | ||
} | ||
}) | ||
return config | ||
} | ||
on("task", { | ||
async getIAPToken({ url, cid }) { | ||
const { GoogleAuth } = require("google-auth-library"); | ||
const auth = new GoogleAuth(); | ||
const client = await auth.getIdTokenClient(cid); | ||
const res = await client.request({ url }); | ||
return res.config.headers.Authorization; | ||
}, | ||
}); | ||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
/// <reference types="cypress"> | ||
Cypress.Commands.overwrite('visit', (originalFn, subject, ...args) => { | ||
if (Cypress.config().baseUrl.indexOf('localhost') != -1) { | ||
return originalFn(subject, ...args); | ||
} else { | ||
cy.exec('curl -I ' + Cypress.config().baseUrl + " | awk '/^location/ {split($NF, a, /[=&]/); print a[2]}'").then((client_id) => { | ||
return client_id.stdout | ||
}).then(client_id => { | ||
cy.task('getIAPToken', { url: Cypress.config().baseUrl, cid: client_id }).then((token) => { | ||
console.log(token) | ||
cy.setCookie('GCP_IAAP_AUTH_TOKEN', token) | ||
.then( () => { | ||
return originalFn(subject, ...args) | ||
}) | ||
}) | ||
}) | ||
|
||
} | ||
}) | ||
Cypress.Commands.overwrite("visit", (originalFn, subject, ...args) => { | ||
if (Cypress.config().baseUrl.indexOf("localhost") != -1) { | ||
return originalFn(subject, ...args); | ||
} else { | ||
cy.exec( | ||
`curl -I ${ | ||
Cypress.config().baseUrl | ||
} | awk '/^location/ {split($NF, a, /[=&]/); print a[2]}'` | ||
) | ||
.then((client_id) => { | ||
return client_id.stdout; | ||
}) | ||
.then((client_id) => { | ||
cy.task("getIAPToken", { | ||
url: Cypress.config().baseUrl, | ||
cid: client_id, | ||
}).then((iapToken) => { | ||
cy.intercept(`${Cypress.config().baseUrl}/**`, (req) => { | ||
req.headers["Proxy-Authorization"] = `${iapToken}`; | ||
}) | ||
.as("Cypress-IAP") | ||
.then(() => { | ||
return originalFn(subject, ...args); | ||
}); | ||
}); | ||
}); | ||
} | ||
}); |