55"fmt"
66"net/http"
77"net/http/httptest"
8- "net/url"
98"testing"
109
1110"github.com/gavv/httpexpect"
2625clientSecret = "11111111"
2726
2827plainChallenge = "ThisIsAFourtyThreeCharactersLongStringThing"
29- s256Challenge = "s256test"
30- // echo s256test | sha256 | base64 | tr '/+' '_-'
31- s256ChallengeHash = "W6YWc_4yHwYN-cGDgGmOMHF3l7KDy7VcRjf7q2FVF-o="
28+ s256Challenge = "s256tests256tests256tests256tests256tests256test"
29+ // sha2562 := sha256.Sum256([]byte(s256Challenge))
30+ // fmt.Printf(base64.URLEncoding.EncodeToString(sha2562[:]))
31+ s256ChallengeHash = "To2Xqv01cm16bC9Sf7KRRS8CO2SFss_HSMQOr3sdCDE="
3232)
3333
3434func init () {
@@ -107,7 +107,7 @@ func TestAuthorizeCode(t *testing.T) {
107107WithQuery ("client_id" , clientID ).
108108WithQuery ("scope" , "all" ).
109109WithQuery ("state" , "123" ).
110- WithQuery ("redirect_uri" , url . QueryEscape ( csrv .URL + "/oauth2" ) ).
110+ WithQuery ("redirect_uri" , csrv .URL + "/oauth2" ).
111111Expect ().Status (http .StatusOK )
112112}
113113
@@ -134,7 +134,7 @@ func TestAuthorizeCodeWithChallengePlain(t *testing.T) {
134134WithFormField ("grant_type" , "authorization_code" ).
135135WithFormField ("client_id" , clientID ).
136136WithFormField ("code" , code ).
137- WithBasicAuth ("code_verifier" , "testchallenge" ).
137+ WithFormField ("code_verifier" , plainChallenge ).
138138Expect ().
139139Status (http .StatusOK ).
140140JSON ().Object ()
@@ -152,13 +152,14 @@ func TestAuthorizeCodeWithChallengePlain(t *testing.T) {
152152userID = "000000"
153153return
154154})
155+ srv .SetClientInfoHandler (server .ClientFormHandler )
155156
156157e .GET ("/authorize" ).
157158WithQuery ("response_type" , "code" ).
158159WithQuery ("client_id" , clientID ).
159160WithQuery ("scope" , "all" ).
160161WithQuery ("state" , "123" ).
161- WithQuery ("redirect_uri" , url . QueryEscape ( csrv .URL + "/oauth2" ) ).
162+ WithQuery ("redirect_uri" , csrv .URL + "/oauth2" ).
162163WithQuery ("code_challenge" , plainChallenge ).
163164Expect ().Status (http .StatusOK )
164165}
@@ -186,7 +187,7 @@ func TestAuthorizeCodeWithChallengeS256(t *testing.T) {
186187WithFormField ("grant_type" , "authorization_code" ).
187188WithFormField ("client_id" , clientID ).
188189WithFormField ("code" , code ).
189- WithBasicAuth ("code_verifier" , s256Challenge ).
190+ WithFormField ("code_verifier" , s256Challenge ).
190191Expect ().
191192Status (http .StatusOK ).
192193JSON ().Object ()
@@ -204,13 +205,14 @@ func TestAuthorizeCodeWithChallengeS256(t *testing.T) {
204205userID = "000000"
205206return
206207})
208+ srv .SetClientInfoHandler (server .ClientFormHandler )
207209
208210e .GET ("/authorize" ).
209211WithQuery ("response_type" , "code" ).
210212WithQuery ("client_id" , clientID ).
211213WithQuery ("scope" , "all" ).
212214WithQuery ("state" , "123" ).
213- WithQuery ("redirect_uri" , url . QueryEscape ( csrv .URL + "/oauth2" ) ).
215+ WithQuery ("redirect_uri" , csrv .URL + "/oauth2" ).
214216WithQuery ("code_challenge" , s256ChallengeHash ).
215217WithQuery ("code_challenge_method" , "S256" ).
216218Expect ().Status (http .StatusOK )
@@ -238,7 +240,7 @@ func TestImplicit(t *testing.T) {
238240WithQuery ("client_id" , clientID ).
239241WithQuery ("scope" , "all" ).
240242WithQuery ("state" , "123" ).
241- WithQuery ("redirect_uri" , url . QueryEscape ( csrv .URL + "/oauth2" ) ).
243+ WithQuery ("redirect_uri" , csrv .URL + "/oauth2" ).
242244Expect ().Status (http .StatusOK )
243245}
244246
@@ -384,7 +386,7 @@ func TestRefreshing(t *testing.T) {
384386WithQuery ("client_id" , clientID ).
385387WithQuery ("scope" , "all" ).
386388WithQuery ("state" , "123" ).
387- WithQuery ("redirect_uri" , url . QueryEscape ( csrv .URL + "/oauth2" ) ).
389+ WithQuery ("redirect_uri" , csrv .URL + "/oauth2" ).
388390Expect ().Status (http .StatusOK )
389391}
390392
0 commit comments