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: headers were incorrectly set to application/x-www-form-urlencoded #362

Closed
wants to merge 1 commit into from

Conversation

bcoe
Copy link
Contributor

@bcoe bcoe commented Feb 26, 2021

This is a long standing bug that prevents us from setting content-type in
gaxios.

Refs: googleapis/google-api-nodejs-client#2003
Refs: googleapis/gaxios#263

This is a long standing bug that prevents us from setting content-type in
gaxios.

Refs: googleapis/google-api-nodejs-client#2003
Refs: googleapis/gaxios#263
@bcoe bcoe requested a review from a team as a code owner February 26, 2021 02:08
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Feb 26, 2021
@@ -610,16 +610,14 @@ describe('.getToken()', () => {
});

function createGetTokenMock(code = 200, body?: {}) {
return nock(GOOGLE_TOKEN_URLS[0])
return nock(GOOGLE_TOKEN_URLS[0], {
reqheaders: {'Content-Type': 'application/json'},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we had reqheaders in the wrong place, and it was not actually being asserted against.

application/x-www-form-urlencoded was already being replaced by gaxios with application/json.

Copy link
Contributor

@JustinBeckwith JustinBeckwith Feb 26, 2021

Choose a reason for hiding this comment

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

I see that the docs do call out that headers are specified in this outer function, but doesn't it have to have some way to define header assertions on a per-route basis? Like it makes sense to be that these could be defined at the top level for the host, but I would expect .get and .post to accept this parameter as well. I am le nervous here. If nock isn't validating headers here, when the types accept Options in InterceptorFunction, that means there's a bug in their types as well :(

@codecov
Copy link

codecov bot commented Feb 26, 2021

Codecov Report

Merging #362 (95ff1e5) into master (68c76c2) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #362   +/-   ##
=======================================
  Coverage   94.22%   94.22%           
=======================================
  Files           3        3           
  Lines         398      398           
  Branches       64       64           
=======================================
  Hits          375      375           
  Misses         23       23           
Impacted Files Coverage Δ
src/index.ts 100.00% <100.00%> (ø)

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 68c76c2...95ff1e5. Read the comment docs.

Copy link
Contributor

@JustinBeckwith JustinBeckwith left a comment

Choose a reason for hiding this comment

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

We need to make sure the documentation and this are doing the same thing. If the docs are wrong, let's reach out to those folks and verify first. Also - I would feel soooooo much better if I knew this was being properly covered with an end to end test ( I don't know that it isn't)

@@ -327,7 +327,7 @@ export class GoogleToken {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: signedJWT,
},
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
Copy link
Contributor

Choose a reason for hiding this comment

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

I am worried this is not correct. I'm reading this doc:
https://developers.google.com/identity/protocols/oauth2/service-account#httprest

It's pretty specific:

POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded

grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiI3NjEzMjY3OTgwNjktcjVtbGpsbG4xcmQ0bHJiaGc3NWVmZ2lncDM2bTc4ajVAZGV2ZWxvcGVyLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzY29wZSI6Imh0dHBzOi8vd3d3Lmdvb2dsZWFwaXMuY29tL2F1dGgvcHJlZGljdGlvbiIsImF1ZCI6Imh0dHBzOi8vYWNjb3VudHMuZ29vZ2xlLmNvbS9vL29hdXRoMi90b2tlbiIsImV4cCI6MTMyODU3MzM4MSwiaWF0IjoxMzI4NTY5NzgxfQ.ixOUGehweEVX_UKXv5BbbwVEdcz6AYS-6uQV6fGorGKrHf3LIJnyREw9evE-gs2bmMaQI5_UbabvI4k-mQE4kBqtmSpTzxYBL1TCd7Kv5nTZoUC1CmwmWCFqT9RE6D7XSgPUh_jF1qskLa2w0rxMSjwruNKbysgRNctZPln7cqQ

Do we have an end to end test checking this out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If gaxios sees an object it turns it into application/json for content-type, I'm 99% sure that we were never setting the form encoded header.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I totally believe you. I'm specifically scared that POST-ing JSON happens to work on the endpoint you're using, but that it isn't fully supported.

@@ -610,16 +610,14 @@ describe('.getToken()', () => {
});

function createGetTokenMock(code = 200, body?: {}) {
return nock(GOOGLE_TOKEN_URLS[0])
return nock(GOOGLE_TOKEN_URLS[0], {
reqheaders: {'Content-Type': 'application/json'},
Copy link
Contributor

@JustinBeckwith JustinBeckwith Feb 26, 2021

Choose a reason for hiding this comment

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

I see that the docs do call out that headers are specified in this outer function, but doesn't it have to have some way to define header assertions on a per-route basis? Like it makes sense to be that these could be defined at the top level for the host, but I would expect .get and .post to accept this parameter as well. I am le nervous here. If nock isn't validating headers here, when the types accept Options in InterceptorFunction, that means there's a bug in their types as well :(

@sofisl
Copy link
Contributor

sofisl commented Mar 2, 2021

@bcoe , is this OK to close because of #374?

@bcoe bcoe closed this Mar 3, 2021
@bcoe bcoe deleted the fix-header branch March 3, 2021 20:31
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.

3 participants