Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: feature detection to check for browser #738

Merged
merged 3 commits into from Jun 20, 2019
Merged

fix: feature detection to check for browser #738

merged 3 commits into from Jun 20, 2019

Conversation

JustinBeckwith
Copy link
Contributor

Previously, we were using the precense of window to figure out if we were running in a browser. Turns out, it causes a lot of trouble, like this:
googleapis/nodejs-storage#694 (comment)

We also see cases where window is injected in test environments for things like jest.

This uses a feature detection style approach, where we specifically check for subtle crypto availability.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jun 19, 2019
@codecov
Copy link

codecov bot commented Jun 19, 2019

Codecov Report

Merging #738 into master will increase coverage by 0.09%.
The diff coverage is 40%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #738      +/-   ##
==========================================
+ Coverage   84.42%   84.51%   +0.09%     
==========================================
  Files          18       17       -1     
  Lines         950      943       -7     
  Branches      210      210              
==========================================
- Hits          802      797       -5     
+ Misses         88       86       -2     
  Partials       60       60
Impacted Files Coverage Δ
src/auth/googleauth.ts 86.01% <ø> (ø) ⬆️
src/crypto/node/crypto.ts 100% <ø> (ø) ⬆️
src/auth/authclient.ts 100% <ø> (ø) ⬆️
src/auth/jwtaccess.ts 98.14% <ø> (ø) ⬆️
src/messages.ts 90% <0%> (+6.66%) ⬆️
src/crypto/browser/crypto.ts 9.09% <0%> (+0.26%) ⬆️
src/transporters.ts 88.88% <0%> (-0.25%) ⬇️
src/auth/oauth2client.ts 82.78% <100%> (-0.06%) ⬇️
src/crypto/crypto.ts 66.66% <50%> (-4.77%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a6c8e7...b093cbb. Read the comment docs.

Copy link
Contributor

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me. Is the only thing that changes between the browser and Node.js execution the certificate format? our hypothesis being that an environment like Jest will work with PEM?

@@ -60,7 +58,7 @@ export class DefaultTransporter {
*/
configure(opts: GaxiosOptions = {}): GaxiosOptions {
opts.headers = opts.headers || {};
if (!isBrowser()) {
if (typeof window === 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're okay to keep this check the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye. In this case, it doesn't have an impact on which browser feature we're trying to use. It's just a naive check so we can try to send the right HTTP headers (I think).

@alexander-fenster
Copy link
Member

@bcoe re: certificate formats, that's all bad bad bad. We basically need to have the same "feature detection check" there as well (not just "oh it's a browser, let's do JWK and not PEM", but "if this environment supports PEM, do PEM, if it supports JWK, do JWK, and there might be other formats to consider"). I think it's OK to leave it as is for now, until someone comes and claims that the existing logic does not work for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants