Skip to content

Commit 6667018

Browse files
Ryan Kohlercodyoss
authored andcommitted
google: Changes required to get AWS working in manual testing
• Subject Token needs to be query escaped • Null options need to be omitted (like they are in other languages) Change-Id: I67d1ed3ba96a35283a8928f196bc7e912084d1ab GitHub-Last-Rev: 1aae076 GitHub-Pull-Request: #474 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/290513 Reviewed-by: Cody Oss <codyoss@google.com> Trust: Cody Oss <codyoss@google.com> Trust: Tyler Bui-Palsulich <tbp@google.com> Run-TryBot: Cody Oss <codyoss@google.com> TryBot-Result: Go Bot <gobot@golang.org>
1 parent 0101308 commit 6667018

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

google/internal/externalaccount/aws.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"io"
1717
"io/ioutil"
1818
"net/http"
19+
"net/url"
1920
"os"
2021
"path"
2122
"sort"
@@ -334,7 +335,7 @@ func (cs awsCredentialSource) subjectToken() (string, error) {
334335
if err != nil {
335336
return "", err
336337
}
337-
return string(result), nil
338+
return url.QueryEscape(string(result)), nil
338339
}
339340

340341
func (cs *awsCredentialSource) getRegion() (string, error) {

google/internal/externalaccount/aws_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"net/http"
1212
"net/http/httptest"
13+
neturl "net/url"
1314
"reflect"
1415
"strings"
1516
"testing"
@@ -527,7 +528,7 @@ func getExpectedSubjectToken(url, region, accessKeyID, secretAccessKey, security
527528
})
528529

529530
str, _ := json.Marshal(result)
530-
return string(str)
531+
return neturl.QueryEscape(string(str))
531532
}
532533

533534
func TestAwsCredential_BasicRequest(t *testing.T) {

google/internal/externalaccount/basecredentials_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var testConfig = Config{
2929
}
3030

3131
var (
32-
baseCredsRequestBody = "audience=32555940559.apps.googleusercontent.com&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&options=null&requested_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&subject_token=street123&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
32+
baseCredsRequestBody = "audience=32555940559.apps.googleusercontent.com&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&requested_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&subject_token=street123&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
3333
baseCredsResponseBody = `{"access_token":"Sample.Access.Token","issued_token_type":"urn:ietf:params:oauth:token-type:access_token","token_type":"Bearer","expires_in":3600,"scope":"https://www.googleapis.com/auth/cloud-platform"}`
3434
correctAT = "Sample.Access.Token"
3535
expiry int64 = 234852

google/internal/externalaccount/impersonate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var testImpersonateConfig = Config{
2323
}
2424

2525
var (
26-
baseImpersonateCredsReqBody = "audience=32555940559.apps.googleusercontent.com&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&options=null&requested_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&subject_token=street123&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
26+
baseImpersonateCredsReqBody = "audience=32555940559.apps.googleusercontent.com&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&requested_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform&subject_token=street123&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
2727
baseImpersonateCredsRespBody = `{"accessToken":"Second.Access.Token","expireTime":"2020-12-28T15:01:23Z"}`
2828
)
2929

google/internal/externalaccount/sts_exchange.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
3232
data.Set("subject_token_type", request.SubjectTokenType)
3333
data.Set("subject_token", request.SubjectToken)
3434
data.Set("scope", strings.Join(request.Scope, " "))
35-
opts, err := json.Marshal(options)
36-
if err != nil {
37-
return nil, fmt.Errorf("oauth2/google: failed to marshal additional options: %v", err)
35+
if options != nil {
36+
opts, err := json.Marshal(options)
37+
if err != nil {
38+
return nil, fmt.Errorf("oauth2/google: failed to marshal additional options: %v", err)
39+
}
40+
data.Set("options", string(opts))
3841
}
39-
data.Set("options", string(opts))
4042

4143
authentication.InjectAuthentication(data, headers)
4244
encodedData := data.Encode()

google/internal/externalaccount/sts_exchange_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var tokenRequest = STSTokenExchangeRequest{
3535
SubjectTokenType: "urn:ietf:params:oauth:token-type:jwt",
3636
}
3737

38-
var requestbody = "audience=32555940559.apps.googleusercontent.com&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&options=null&requested_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&subject_token=Sample.Subject.Token&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
38+
var requestbody = "audience=32555940559.apps.googleusercontent.com&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&requested_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&subject_token=Sample.Subject.Token&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
3939
var responseBody = `{"access_token":"Sample.Access.Token","issued_token_type":"urn:ietf:params:oauth:token-type:access_token","token_type":"Bearer","expires_in":3600,"scope":"https://www.googleapis.com/auth/cloud-platform"}`
4040
var expectedToken = STSTokenExchangeResponse{
4141
AccessToken: "Sample.Access.Token",

0 commit comments

Comments
 (0)