@@ -11,6 +11,7 @@ import (
11
11
"fmt"
12
12
"net/http"
13
13
"net/http/httptest"
14
+ "net/url"
14
15
"reflect"
15
16
"strings"
16
17
"testing"
@@ -142,9 +143,12 @@ func TestJWTFetch_BadResponseType(t *testing.T) {
142
143
143
144
func TestJWTFetch_Assertion (t * testing.T ) {
144
145
var assertion string
146
+ var extra_querystring_param string
147
+
145
148
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
146
149
r .ParseForm ()
147
150
assertion = r .Form .Get ("assertion" )
151
+ extra_querystring_param = r .Form .Get ("extra_querystring_param" )
148
152
149
153
w .Header ().Set ("Content-Type" , "application/json" )
150
154
w .Write ([]byte (`{
@@ -161,13 +165,18 @@ func TestJWTFetch_Assertion(t *testing.T) {
161
165
PrivateKey : dummyPrivateKey ,
162
166
PrivateKeyID : "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ,
163
167
TokenURL : ts .URL ,
168
+ Querystring : url.Values {"extra_querystring_param" : []string {"example_value" }},
164
169
}
165
170
166
171
_ , err := conf .TokenSource (context .Background ()).Token ()
167
172
if err != nil {
168
173
t .Fatalf ("Failed to fetch token: %v" , err )
169
174
}
170
175
176
+ if extra_querystring_param != "example_value" {
177
+ t .Fatalf ("extra_querystring_param = %v; should be \" example_value\" " , extra_querystring_param )
178
+ }
179
+
171
180
parts := strings .Split (assertion , "." )
172
181
if len (parts ) != 3 {
173
182
t .Fatalf ("assertion = %q; want 3 parts" , assertion )
@@ -316,3 +325,17 @@ func TestTokenRetrieveError(t *testing.T) {
316
325
t .Fatalf ("got %#v, expected %#v" , errStr , expected )
317
326
}
318
327
}
328
+
329
+ func TestInvalidConfigArgument (t * testing.T ) {
330
+ conf := & Config {
331
+
332
+ PrivateKey : dummyPrivateKey ,
333
+ Audience : "https://example.com" ,
334
+ Querystring : url.Values {"assertion" : []string {"Trying to override assertion" }},
335
+ }
336
+
337
+ _ , err := conf .TokenSource (context .Background ()).Token ()
338
+ if err == nil {
339
+ t .Fatalf ("got no error, expected one" )
340
+ }
341
+ }
0 commit comments