| OLD | NEW |
| 1 library googleapis.oauth2.v2.test; | 1 library googleapis.oauth2.v2.test; |
| 2 | 2 |
| 3 import "dart:core" as core; | 3 import "dart:core" as core; |
| 4 import "dart:collection" as collection; | 4 import "dart:collection" as collection; |
| 5 import "dart:async" as async; | 5 import "dart:async" as async; |
| 6 import "dart:convert" as convert; | 6 import "dart:convert" as convert; |
| 7 | 7 |
| 8 import 'package:http/http.dart' as http; | 8 import 'package:http/http.dart' as http; |
| 9 import 'package:http/testing.dart' as http_testing; | 9 import 'package:http/testing.dart' as http_testing; |
| 10 import 'package:unittest/unittest.dart' as unittest; | 10 import 'package:test/test.dart' as unittest; |
| 11 | 11 |
| 12 import 'package:googleapis/oauth2/v2.dart' as api; | 12 import 'package:googleapis/oauth2/v2.dart' as api; |
| 13 | 13 |
| 14 class HttpServerMock extends http.BaseClient { | 14 class HttpServerMock extends http.BaseClient { |
| 15 core.Function _callback; | 15 core.Function _callback; |
| 16 core.bool _expectJson; | 16 core.bool _expectJson; |
| 17 | 17 |
| 18 void register(core.Function callback, core.bool expectJson) { | 18 void register(core.Function callback, core.bool expectJson) { |
| 19 _callback = callback; | 19 _callback = callback; |
| 20 _expectJson = expectJson; | 20 _expectJson = expectJson; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 } else { | 39 } else { |
| 40 return stream.toBytes().then((data) { | 40 return stream.toBytes().then((data) { |
| 41 return _callback(request, data); | 41 return _callback(request, data); |
| 42 }); | 42 }); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 http.StreamedResponse stringResponse( | 48 http.StreamedResponse stringResponse( |
| 49 core.int status, core.Map headers, core.String body) { | 49 core.int status, core.Map<core.String, core.String> headers, core.String bod
y) { |
| 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
| 51 return new http.StreamedResponse(stream, status, headers: headers); | 51 return new http.StreamedResponse(stream, status, headers: headers); |
| 52 } | 52 } |
| 53 | 53 |
| 54 core.int buildCounterJwkKeys = 0; | 54 core.int buildCounterJwkKeys = 0; |
| 55 buildJwkKeys() { | 55 buildJwkKeys() { |
| 56 var o = new api.JwkKeys(); | 56 var o = new api.JwkKeys(); |
| 57 buildCounterJwkKeys++; | 57 buildCounterJwkKeys++; |
| 58 if (buildCounterJwkKeys < 3) { | 58 if (buildCounterJwkKeys < 3) { |
| 59 o.alg = "foo"; | 59 o.alg = "foo"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 73 unittest.expect(o.alg, unittest.equals('foo')); | 73 unittest.expect(o.alg, unittest.equals('foo')); |
| 74 unittest.expect(o.e, unittest.equals('foo')); | 74 unittest.expect(o.e, unittest.equals('foo')); |
| 75 unittest.expect(o.kid, unittest.equals('foo')); | 75 unittest.expect(o.kid, unittest.equals('foo')); |
| 76 unittest.expect(o.kty, unittest.equals('foo')); | 76 unittest.expect(o.kty, unittest.equals('foo')); |
| 77 unittest.expect(o.n, unittest.equals('foo')); | 77 unittest.expect(o.n, unittest.equals('foo')); |
| 78 unittest.expect(o.use, unittest.equals('foo')); | 78 unittest.expect(o.use, unittest.equals('foo')); |
| 79 } | 79 } |
| 80 buildCounterJwkKeys--; | 80 buildCounterJwkKeys--; |
| 81 } | 81 } |
| 82 | 82 |
| 83 buildUnnamed2889() { | 83 buildUnnamed2359() { |
| 84 var o = new core.List<api.JwkKeys>(); | 84 var o = new core.List<api.JwkKeys>(); |
| 85 o.add(buildJwkKeys()); | 85 o.add(buildJwkKeys()); |
| 86 o.add(buildJwkKeys()); | 86 o.add(buildJwkKeys()); |
| 87 return o; | 87 return o; |
| 88 } | 88 } |
| 89 | 89 |
| 90 checkUnnamed2889(core.List<api.JwkKeys> o) { | 90 checkUnnamed2359(core.List<api.JwkKeys> o) { |
| 91 unittest.expect(o, unittest.hasLength(2)); | 91 unittest.expect(o, unittest.hasLength(2)); |
| 92 checkJwkKeys(o[0]); | 92 checkJwkKeys(o[0]); |
| 93 checkJwkKeys(o[1]); | 93 checkJwkKeys(o[1]); |
| 94 } | 94 } |
| 95 | 95 |
| 96 core.int buildCounterJwk = 0; | 96 core.int buildCounterJwk = 0; |
| 97 buildJwk() { | 97 buildJwk() { |
| 98 var o = new api.Jwk(); | 98 var o = new api.Jwk(); |
| 99 buildCounterJwk++; | 99 buildCounterJwk++; |
| 100 if (buildCounterJwk < 3) { | 100 if (buildCounterJwk < 3) { |
| 101 o.keys = buildUnnamed2889(); | 101 o.keys = buildUnnamed2359(); |
| 102 } | 102 } |
| 103 buildCounterJwk--; | 103 buildCounterJwk--; |
| 104 return o; | 104 return o; |
| 105 } | 105 } |
| 106 | 106 |
| 107 checkJwk(api.Jwk o) { | 107 checkJwk(api.Jwk o) { |
| 108 buildCounterJwk++; | 108 buildCounterJwk++; |
| 109 if (buildCounterJwk < 3) { | 109 if (buildCounterJwk < 3) { |
| 110 checkUnnamed2889(o.keys); | 110 checkUnnamed2359(o.keys); |
| 111 } | 111 } |
| 112 buildCounterJwk--; | 112 buildCounterJwk--; |
| 113 } | 113 } |
| 114 | 114 |
| 115 core.int buildCounterTokeninfo = 0; | 115 core.int buildCounterTokeninfo = 0; |
| 116 buildTokeninfo() { | 116 buildTokeninfo() { |
| 117 var o = new api.Tokeninfo(); | 117 var o = new api.Tokeninfo(); |
| 118 buildCounterTokeninfo++; | 118 buildCounterTokeninfo++; |
| 119 if (buildCounterTokeninfo < 3) { | 119 if (buildCounterTokeninfo < 3) { |
| 120 o.accessType = "foo"; | 120 o.accessType = "foo"; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 checkUserinfoplus(od); | 222 checkUserinfoplus(od); |
| 223 }); | 223 }); |
| 224 }); | 224 }); |
| 225 | 225 |
| 226 | 226 |
| 227 unittest.group("resource-Oauth2Api", () { | 227 unittest.group("resource-Oauth2Api", () { |
| 228 unittest.test("method--getCertForOpenIdConnect", () { | 228 unittest.test("method--getCertForOpenIdConnect", () { |
| 229 | 229 |
| 230 var mock = new HttpServerMock(); | 230 var mock = new HttpServerMock(); |
| 231 api.Oauth2Api res = new api.Oauth2Api(mock); | 231 api.Oauth2Api res = new api.Oauth2Api(mock); |
| 232 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 232 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 233 var path = (req.url).path; | 233 var path = (req.url).path; |
| 234 var pathOffset = 0; | 234 var pathOffset = 0; |
| 235 var index; | 235 var index; |
| 236 var subPart; | 236 var subPart; |
| 237 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 237 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 238 pathOffset += 1; | 238 pathOffset += 1; |
| 239 unittest.expect(path.substring(pathOffset, pathOffset + 15), unittest.eq
uals("oauth2/v2/certs")); | 239 unittest.expect(path.substring(pathOffset, pathOffset + 15), unittest.eq
uals("oauth2/v2/certs")); |
| 240 pathOffset += 15; | 240 pathOffset += 15; |
| 241 | 241 |
| 242 var query = (req.url).query; | 242 var query = (req.url).query; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 | 259 |
| 260 var h = { | 260 var h = { |
| 261 "content-type" : "application/json; charset=utf-8", | 261 "content-type" : "application/json; charset=utf-8", |
| 262 }; | 262 }; |
| 263 var resp = convert.JSON.encode(buildJwk()); | 263 var resp = convert.JSON.encode(buildJwk()); |
| 264 return new async.Future.value(stringResponse(200, h, resp)); | 264 return new async.Future.value(stringResponse(200, h, resp)); |
| 265 }), true); | 265 }), true); |
| 266 res.getCertForOpenIdConnect().then(unittest.expectAsync(((api.Jwk response
) { | 266 res.getCertForOpenIdConnect().then(unittest.expectAsync1(((api.Jwk respons
e) { |
| 267 checkJwk(response); | 267 checkJwk(response); |
| 268 }))); | 268 }))); |
| 269 }); | 269 }); |
| 270 | 270 |
| 271 unittest.test("method--tokeninfo", () { | 271 unittest.test("method--tokeninfo", () { |
| 272 | 272 |
| 273 var mock = new HttpServerMock(); | 273 var mock = new HttpServerMock(); |
| 274 api.Oauth2Api res = new api.Oauth2Api(mock); | 274 api.Oauth2Api res = new api.Oauth2Api(mock); |
| 275 var arg_accessToken = "foo"; | 275 var arg_accessToken = "foo"; |
| 276 var arg_idToken = "foo"; | 276 var arg_idToken = "foo"; |
| 277 var arg_tokenHandle = "foo"; | 277 var arg_tokenHandle = "foo"; |
| 278 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 278 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 279 var path = (req.url).path; | 279 var path = (req.url).path; |
| 280 var pathOffset = 0; | 280 var pathOffset = 0; |
| 281 var index; | 281 var index; |
| 282 var subPart; | 282 var subPart; |
| 283 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 283 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 284 pathOffset += 1; | 284 pathOffset += 1; |
| 285 unittest.expect(path.substring(pathOffset, pathOffset + 19), unittest.eq
uals("oauth2/v2/tokeninfo")); | 285 unittest.expect(path.substring(pathOffset, pathOffset + 19), unittest.eq
uals("oauth2/v2/tokeninfo")); |
| 286 pathOffset += 19; | 286 pathOffset += 19; |
| 287 | 287 |
| 288 var query = (req.url).query; | 288 var query = (req.url).query; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 305 unittest.expect(queryMap["id_token"].first, unittest.equals(arg_idToken)
); | 305 unittest.expect(queryMap["id_token"].first, unittest.equals(arg_idToken)
); |
| 306 unittest.expect(queryMap["token_handle"].first, unittest.equals(arg_toke
nHandle)); | 306 unittest.expect(queryMap["token_handle"].first, unittest.equals(arg_toke
nHandle)); |
| 307 | 307 |
| 308 | 308 |
| 309 var h = { | 309 var h = { |
| 310 "content-type" : "application/json; charset=utf-8", | 310 "content-type" : "application/json; charset=utf-8", |
| 311 }; | 311 }; |
| 312 var resp = convert.JSON.encode(buildTokeninfo()); | 312 var resp = convert.JSON.encode(buildTokeninfo()); |
| 313 return new async.Future.value(stringResponse(200, h, resp)); | 313 return new async.Future.value(stringResponse(200, h, resp)); |
| 314 }), true); | 314 }), true); |
| 315 res.tokeninfo(accessToken: arg_accessToken, idToken: arg_idToken, tokenHan
dle: arg_tokenHandle).then(unittest.expectAsync(((api.Tokeninfo response) { | 315 res.tokeninfo(accessToken: arg_accessToken, idToken: arg_idToken, tokenHan
dle: arg_tokenHandle).then(unittest.expectAsync1(((api.Tokeninfo response) { |
| 316 checkTokeninfo(response); | 316 checkTokeninfo(response); |
| 317 }))); | 317 }))); |
| 318 }); | 318 }); |
| 319 | 319 |
| 320 }); | 320 }); |
| 321 | 321 |
| 322 | 322 |
| 323 unittest.group("resource-UserinfoResourceApi", () { | 323 unittest.group("resource-UserinfoResourceApi", () { |
| 324 unittest.test("method--get", () { | 324 unittest.test("method--get", () { |
| 325 | 325 |
| 326 var mock = new HttpServerMock(); | 326 var mock = new HttpServerMock(); |
| 327 api.UserinfoResourceApi res = new api.Oauth2Api(mock).userinfo; | 327 api.UserinfoResourceApi res = new api.Oauth2Api(mock).userinfo; |
| 328 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 328 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 329 var path = (req.url).path; | 329 var path = (req.url).path; |
| 330 var pathOffset = 0; | 330 var pathOffset = 0; |
| 331 var index; | 331 var index; |
| 332 var subPart; | 332 var subPart; |
| 333 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 333 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 334 pathOffset += 1; | 334 pathOffset += 1; |
| 335 unittest.expect(path.substring(pathOffset, pathOffset + 18), unittest.eq
uals("oauth2/v2/userinfo")); | 335 unittest.expect(path.substring(pathOffset, pathOffset + 18), unittest.eq
uals("oauth2/v2/userinfo")); |
| 336 pathOffset += 18; | 336 pathOffset += 18; |
| 337 | 337 |
| 338 var query = (req.url).query; | 338 var query = (req.url).query; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 | 355 |
| 356 var h = { | 356 var h = { |
| 357 "content-type" : "application/json; charset=utf-8", | 357 "content-type" : "application/json; charset=utf-8", |
| 358 }; | 358 }; |
| 359 var resp = convert.JSON.encode(buildUserinfoplus()); | 359 var resp = convert.JSON.encode(buildUserinfoplus()); |
| 360 return new async.Future.value(stringResponse(200, h, resp)); | 360 return new async.Future.value(stringResponse(200, h, resp)); |
| 361 }), true); | 361 }), true); |
| 362 res.get().then(unittest.expectAsync(((api.Userinfoplus response) { | 362 res.get().then(unittest.expectAsync1(((api.Userinfoplus response) { |
| 363 checkUserinfoplus(response); | 363 checkUserinfoplus(response); |
| 364 }))); | 364 }))); |
| 365 }); | 365 }); |
| 366 | 366 |
| 367 }); | 367 }); |
| 368 | 368 |
| 369 | 369 |
| 370 unittest.group("resource-UserinfoV2MeResourceApi", () { | 370 unittest.group("resource-UserinfoV2MeResourceApi", () { |
| 371 unittest.test("method--get", () { | 371 unittest.test("method--get", () { |
| 372 | 372 |
| 373 var mock = new HttpServerMock(); | 373 var mock = new HttpServerMock(); |
| 374 api.UserinfoV2MeResourceApi res = new api.Oauth2Api(mock).userinfo.v2.me; | 374 api.UserinfoV2MeResourceApi res = new api.Oauth2Api(mock).userinfo.v2.me; |
| 375 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 375 mock.register(unittest.expectAsync2((http.BaseRequest req, json) { |
| 376 var path = (req.url).path; | 376 var path = (req.url).path; |
| 377 var pathOffset = 0; | 377 var pathOffset = 0; |
| 378 var index; | 378 var index; |
| 379 var subPart; | 379 var subPart; |
| 380 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 380 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 381 pathOffset += 1; | 381 pathOffset += 1; |
| 382 unittest.expect(path.substring(pathOffset, pathOffset + 14), unittest.eq
uals("userinfo/v2/me")); | 382 unittest.expect(path.substring(pathOffset, pathOffset + 14), unittest.eq
uals("userinfo/v2/me")); |
| 383 pathOffset += 14; | 383 pathOffset += 14; |
| 384 | 384 |
| 385 var query = (req.url).query; | 385 var query = (req.url).query; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 | 402 |
| 403 var h = { | 403 var h = { |
| 404 "content-type" : "application/json; charset=utf-8", | 404 "content-type" : "application/json; charset=utf-8", |
| 405 }; | 405 }; |
| 406 var resp = convert.JSON.encode(buildUserinfoplus()); | 406 var resp = convert.JSON.encode(buildUserinfoplus()); |
| 407 return new async.Future.value(stringResponse(200, h, resp)); | 407 return new async.Future.value(stringResponse(200, h, resp)); |
| 408 }), true); | 408 }), true); |
| 409 res.get().then(unittest.expectAsync(((api.Userinfoplus response) { | 409 res.get().then(unittest.expectAsync1(((api.Userinfoplus response) { |
| 410 checkUserinfoplus(response); | 410 checkUserinfoplus(response); |
| 411 }))); | 411 }))); |
| 412 }); | 412 }); |
| 413 | 413 |
| 414 }); | 414 }); |
| 415 | 415 |
| 416 | 416 |
| 417 } | 417 } |
| 418 | 418 |
| OLD | NEW |