@@ -71,35 +71,6 @@ func TestHTTPClient_OAuthAuthorizationServerMetadata(t *testing.T) {
71
71
assert .Equal (t , "GET" , handler .Request .Method )
72
72
assert .Equal (t , "/.well-known/oauth-authorization-server/iam/123" , handler .Request .URL .Path )
73
73
})
74
- t .Run ("error - non 200 return value" , func (t * testing.T ) {
75
- handler := http2.Handler {StatusCode : http .StatusBadRequest }
76
- tlsServer , client := testServerAndClient (t , & handler )
77
- testDID := didweb .ServerURLToDIDWeb (t , tlsServer .URL )
78
-
79
- metadata , err := client .OAuthAuthorizationServerMetadata (ctx , testDID )
80
-
81
- assert .Error (t , err )
82
- assert .Nil (t , metadata )
83
- })
84
- t .Run ("error - bad contents" , func (t * testing.T ) {
85
- handler := http2.Handler {StatusCode : http .StatusOK , ResponseData : "not json" }
86
- tlsServer , client := testServerAndClient (t , & handler )
87
- testDID := didweb .ServerURLToDIDWeb (t , tlsServer .URL )
88
-
89
- metadata , err := client .OAuthAuthorizationServerMetadata (ctx , testDID )
90
-
91
- assert .Error (t , err )
92
- assert .Nil (t , metadata )
93
- })
94
- t .Run ("error - server not responding" , func (t * testing.T ) {
95
- _ , client := testServerAndClient (t , nil )
96
- testDID := didweb .ServerURLToDIDWeb (t , "https://localhost:1234" )
97
-
98
- metadata , err := client .OAuthAuthorizationServerMetadata (ctx , testDID )
99
-
100
- assert .Error (t , err )
101
- assert .Nil (t , metadata )
102
- })
103
74
}
104
75
105
76
func TestHTTPClient_PresentationDefinition (t * testing.T ) {
@@ -120,26 +91,6 @@ func TestHTTPClient_PresentationDefinition(t *testing.T) {
120
91
assert .Equal (t , definition , * response )
121
92
require .NotNil (t , handler .Request )
122
93
})
123
- t .Run ("error - not found" , func (t * testing.T ) {
124
- handler := http2.Handler {StatusCode : http .StatusNotFound }
125
- tlsServer , client := testServerAndClient (t , & handler )
126
- pdUrl := test .MustParseURL (tlsServer .URL )
127
-
128
- _ , err := client .PresentationDefinition (ctx , * pdUrl )
129
-
130
- require .Error (t , err )
131
- assert .EqualError (t , err , "server returned HTTP 404 (expected: 200)" )
132
- })
133
- t .Run ("error - invalid response" , func (t * testing.T ) {
134
- handler := http2.Handler {StatusCode : http .StatusOK , ResponseData : "}" }
135
- tlsServer , client := testServerAndClient (t , & handler )
136
- pdUrl := test .MustParseURL (tlsServer .URL )
137
-
138
- _ , err := client .PresentationDefinition (ctx , * pdUrl )
139
-
140
- require .Error (t , err )
141
- assert .EqualError (t , err , "unable to unmarshal response: invalid character '}' looking for beginning of value" )
142
- })
143
94
}
144
95
145
96
func TestHTTPClient_AccessToken (t * testing.T ) {
@@ -224,23 +175,12 @@ func TestHTTPClient_ClientMetadata(t *testing.T) {
224
175
assert .Equal (t , metadata , * response )
225
176
require .NotNil (t , handler .Request )
226
177
})
227
-
228
- t .Run ("error - incorrect url" , func (t * testing.T ) {
229
- handler := http2.Handler {StatusCode : http .StatusOK , ResponseData : metadata }
230
- _ , client := testServerAndClient (t , & handler )
231
-
232
- _ , err := client .ClientMetadata (ctx , ":" )
233
-
234
- require .Error (t , err )
235
- assert .EqualError (t , err , "parse \" :\" : missing protocol scheme" )
236
- })
237
178
}
238
179
239
180
func TestHTTPClient_PostError (t * testing.T ) {
240
181
redirectReturn := oauth.Redirect {
241
182
RedirectURI : "http://test.test" ,
242
183
}
243
- //bytes, _ := json.Marshal(redirectReturn)
244
184
t .Run ("ok" , func (t * testing.T ) {
245
185
ctx := context .Background ()
246
186
handler := http2.Handler {StatusCode : http .StatusOK , ResponseData : redirectReturn }
@@ -280,41 +220,16 @@ func TestHTTPClient_postFormExpectRedirect(t *testing.T) {
280
220
data := url.Values {}
281
221
data .Set ("test" , "test" )
282
222
283
- t .Run ("error - unknown host " , func (t * testing.T ) {
223
+ t .Run ("ok " , func (t * testing.T ) {
284
224
ctx := context .Background ()
285
225
handler := http2.Handler {StatusCode : http .StatusOK , ResponseData : redirectReturn }
286
- _ , client := testServerAndClient (t , & handler )
287
- tlsServerURL := test .MustParseURL ("http://localhost" )
288
-
289
- redirectURI , err := client .postFormExpectRedirect (ctx , data , * tlsServerURL )
290
-
291
- require .Error (t , err )
292
- assert .ErrorContains (t , err , "connection refused" )
293
- assert .Empty (t , redirectURI )
294
- })
295
- t .Run ("error - invalid response" , func (t * testing.T ) {
296
- ctx := context .Background ()
297
- handler := http2.Handler {StatusCode : http .StatusOK , ResponseData : "}" }
298
226
tlsServer , client := testServerAndClient (t , & handler )
299
227
tlsServerURL := test .MustParseURL (tlsServer .URL )
300
228
301
229
redirectURI , err := client .postFormExpectRedirect (ctx , data , * tlsServerURL )
302
230
303
- require .Error (t , err )
304
- assert .EqualError (t , err , "unable to unmarshal response: invalid character '}' looking for beginning of value" )
305
- assert .Empty (t , redirectURI )
306
- })
307
- t .Run ("error - server error" , func (t * testing.T ) {
308
- ctx := context .Background ()
309
- handler := http2.Handler {StatusCode : http .StatusBadGateway , ResponseData : "offline" }
310
- tlsServer , client := testServerAndClient (t , & handler )
311
- tlsServerURL := test .MustParseURL (tlsServer .URL )
312
-
313
- redirectURI , err := client .postFormExpectRedirect (ctx , data , * tlsServerURL )
314
-
315
- require .Error (t , err )
316
- assert .EqualError (t , err , "server returned HTTP 502 (expected: 200)" )
317
- assert .Empty (t , redirectURI )
231
+ require .NoError (t , err )
232
+ assert .Equal (t , redirectReturn .RedirectURI , redirectURI )
318
233
})
319
234
}
320
235
@@ -359,3 +274,31 @@ func testServerAndClient(t *testing.T, handler http.Handler) (*httptest.Server,
359
274
httpClient : tlsServer .Client (),
360
275
}
361
276
}
277
+
278
+ func TestHTTPClient_doGet (t * testing.T ) {
279
+ t .Run ("error - non 200 return value" , func (t * testing.T ) {
280
+ handler := http2.Handler {StatusCode : http .StatusBadRequest }
281
+ tlsServer , client := testServerAndClient (t , & handler )
282
+
283
+ err := client .doGet (context .Background (), tlsServer .URL , nil )
284
+
285
+ assert .Error (t , err )
286
+ })
287
+ t .Run ("error - bad contents" , func (t * testing.T ) {
288
+ handler := http2.Handler {StatusCode : http .StatusOK , ResponseData : "not json" }
289
+ tlsServer , client := testServerAndClient (t , & handler )
290
+
291
+ var target interface {}
292
+ err := client .doGet (context .Background (), tlsServer .URL , & target )
293
+
294
+ assert .Error (t , err )
295
+ })
296
+ t .Run ("error - server not responding" , func (t * testing.T ) {
297
+ _ , client := testServerAndClient (t , nil )
298
+
299
+ var target interface {}
300
+ err := client .doGet (context .Background (), "https://localhost:9999" , & target )
301
+
302
+ assert .Error (t , err )
303
+ })
304
+ }
0 commit comments