| 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:unittest/unittest.dart' as unittest; |
| 11 import 'package:googleapis/common/common.dart' as common; | |
| 12 import 'package:googleapis/src/common_internal.dart' as common_internal; | |
| 13 import '../common/common_internal_test.dart' as common_test; | |
| 14 | 11 |
| 15 import 'package:googleapis/oauth2/v2.dart' as api; | 12 import 'package:googleapis/oauth2/v2.dart' as api; |
| 16 | 13 |
| 14 class HttpServerMock extends http.BaseClient { |
| 15 core.Function _callback; |
| 16 core.bool _expectJson; |
| 17 | 17 |
| 18 void register(core.Function callback, core.bool expectJson) { |
| 19 _callback = callback; |
| 20 _expectJson = expectJson; |
| 21 } |
| 22 |
| 23 async.Future<http.StreamedResponse> send(http.BaseRequest request) { |
| 24 if (_expectJson) { |
| 25 return request.finalize() |
| 26 .transform(convert.UTF8.decoder) |
| 27 .join('') |
| 28 .then((core.String jsonString) { |
| 29 if (jsonString.isEmpty) { |
| 30 return _callback(request, null); |
| 31 } else { |
| 32 return _callback(request, convert.JSON.decode(jsonString)); |
| 33 } |
| 34 }); |
| 35 } else { |
| 36 var stream = request.finalize(); |
| 37 if (stream == null) { |
| 38 return _callback(request, []); |
| 39 } else { |
| 40 return stream.toBytes().then((data) { |
| 41 return _callback(request, data); |
| 42 }); |
| 43 } |
| 44 } |
| 45 } |
| 46 } |
| 47 |
| 48 http.StreamedResponse stringResponse( |
| 49 core.int status, core.Map headers, core.String body) { |
| 50 var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); |
| 51 return new http.StreamedResponse(stream, status, headers: headers); |
| 52 } |
| 18 | 53 |
| 19 core.int buildCounterJwkKeys = 0; | 54 core.int buildCounterJwkKeys = 0; |
| 20 buildJwkKeys() { | 55 buildJwkKeys() { |
| 21 var o = new api.JwkKeys(); | 56 var o = new api.JwkKeys(); |
| 22 buildCounterJwkKeys++; | 57 buildCounterJwkKeys++; |
| 23 if (buildCounterJwkKeys < 3) { | 58 if (buildCounterJwkKeys < 3) { |
| 24 o.alg = "foo"; | 59 o.alg = "foo"; |
| 25 o.e = "foo"; | 60 o.e = "foo"; |
| 26 o.kid = "foo"; | 61 o.kid = "foo"; |
| 27 o.kty = "foo"; | 62 o.kty = "foo"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 38 unittest.expect(o.alg, unittest.equals('foo')); | 73 unittest.expect(o.alg, unittest.equals('foo')); |
| 39 unittest.expect(o.e, unittest.equals('foo')); | 74 unittest.expect(o.e, unittest.equals('foo')); |
| 40 unittest.expect(o.kid, unittest.equals('foo')); | 75 unittest.expect(o.kid, unittest.equals('foo')); |
| 41 unittest.expect(o.kty, unittest.equals('foo')); | 76 unittest.expect(o.kty, unittest.equals('foo')); |
| 42 unittest.expect(o.n, unittest.equals('foo')); | 77 unittest.expect(o.n, unittest.equals('foo')); |
| 43 unittest.expect(o.use, unittest.equals('foo')); | 78 unittest.expect(o.use, unittest.equals('foo')); |
| 44 } | 79 } |
| 45 buildCounterJwkKeys--; | 80 buildCounterJwkKeys--; |
| 46 } | 81 } |
| 47 | 82 |
| 48 buildUnnamed1383() { | 83 buildUnnamed1233() { |
| 49 var o = new core.List<api.JwkKeys>(); | 84 var o = new core.List<api.JwkKeys>(); |
| 50 o.add(buildJwkKeys()); | 85 o.add(buildJwkKeys()); |
| 51 o.add(buildJwkKeys()); | 86 o.add(buildJwkKeys()); |
| 52 return o; | 87 return o; |
| 53 } | 88 } |
| 54 | 89 |
| 55 checkUnnamed1383(core.List<api.JwkKeys> o) { | 90 checkUnnamed1233(core.List<api.JwkKeys> o) { |
| 56 unittest.expect(o, unittest.hasLength(2)); | 91 unittest.expect(o, unittest.hasLength(2)); |
| 57 checkJwkKeys(o[0]); | 92 checkJwkKeys(o[0]); |
| 58 checkJwkKeys(o[1]); | 93 checkJwkKeys(o[1]); |
| 59 } | 94 } |
| 60 | 95 |
| 61 core.int buildCounterJwk = 0; | 96 core.int buildCounterJwk = 0; |
| 62 buildJwk() { | 97 buildJwk() { |
| 63 var o = new api.Jwk(); | 98 var o = new api.Jwk(); |
| 64 buildCounterJwk++; | 99 buildCounterJwk++; |
| 65 if (buildCounterJwk < 3) { | 100 if (buildCounterJwk < 3) { |
| 66 o.keys = buildUnnamed1383(); | 101 o.keys = buildUnnamed1233(); |
| 67 } | 102 } |
| 68 buildCounterJwk--; | 103 buildCounterJwk--; |
| 69 return o; | 104 return o; |
| 70 } | 105 } |
| 71 | 106 |
| 72 checkJwk(api.Jwk o) { | 107 checkJwk(api.Jwk o) { |
| 73 buildCounterJwk++; | 108 buildCounterJwk++; |
| 74 if (buildCounterJwk < 3) { | 109 if (buildCounterJwk < 3) { |
| 75 checkUnnamed1383(o.keys); | 110 checkUnnamed1233(o.keys); |
| 76 } | 111 } |
| 77 buildCounterJwk--; | 112 buildCounterJwk--; |
| 78 } | 113 } |
| 79 | 114 |
| 80 core.int buildCounterTokeninfo = 0; | 115 core.int buildCounterTokeninfo = 0; |
| 81 buildTokeninfo() { | 116 buildTokeninfo() { |
| 82 var o = new api.Tokeninfo(); | 117 var o = new api.Tokeninfo(); |
| 83 buildCounterTokeninfo++; | 118 buildCounterTokeninfo++; |
| 84 if (buildCounterTokeninfo < 3) { | 119 if (buildCounterTokeninfo < 3) { |
| 85 o.accessType = "foo"; | 120 o.accessType = "foo"; |
| 86 o.audience = "foo"; | 121 o.audience = "foo"; |
| 87 o.email = "foo"; | 122 o.email = "foo"; |
| 88 o.expiresIn = 42; | 123 o.expiresIn = 42; |
| 89 o.issuedTo = "foo"; | 124 o.issuedTo = "foo"; |
| 90 o.scope = "foo"; | 125 o.scope = "foo"; |
| 126 o.tokenHandle = "foo"; |
| 91 o.userId = "foo"; | 127 o.userId = "foo"; |
| 92 o.verifiedEmail = true; | 128 o.verifiedEmail = true; |
| 93 } | 129 } |
| 94 buildCounterTokeninfo--; | 130 buildCounterTokeninfo--; |
| 95 return o; | 131 return o; |
| 96 } | 132 } |
| 97 | 133 |
| 98 checkTokeninfo(api.Tokeninfo o) { | 134 checkTokeninfo(api.Tokeninfo o) { |
| 99 buildCounterTokeninfo++; | 135 buildCounterTokeninfo++; |
| 100 if (buildCounterTokeninfo < 3) { | 136 if (buildCounterTokeninfo < 3) { |
| 101 unittest.expect(o.accessType, unittest.equals('foo')); | 137 unittest.expect(o.accessType, unittest.equals('foo')); |
| 102 unittest.expect(o.audience, unittest.equals('foo')); | 138 unittest.expect(o.audience, unittest.equals('foo')); |
| 103 unittest.expect(o.email, unittest.equals('foo')); | 139 unittest.expect(o.email, unittest.equals('foo')); |
| 104 unittest.expect(o.expiresIn, unittest.equals(42)); | 140 unittest.expect(o.expiresIn, unittest.equals(42)); |
| 105 unittest.expect(o.issuedTo, unittest.equals('foo')); | 141 unittest.expect(o.issuedTo, unittest.equals('foo')); |
| 106 unittest.expect(o.scope, unittest.equals('foo')); | 142 unittest.expect(o.scope, unittest.equals('foo')); |
| 143 unittest.expect(o.tokenHandle, unittest.equals('foo')); |
| 107 unittest.expect(o.userId, unittest.equals('foo')); | 144 unittest.expect(o.userId, unittest.equals('foo')); |
| 108 unittest.expect(o.verifiedEmail, unittest.isTrue); | 145 unittest.expect(o.verifiedEmail, unittest.isTrue); |
| 109 } | 146 } |
| 110 buildCounterTokeninfo--; | 147 buildCounterTokeninfo--; |
| 111 } | 148 } |
| 112 | 149 |
| 113 core.int buildCounterUserinfoplus = 0; | 150 core.int buildCounterUserinfoplus = 0; |
| 114 buildUserinfoplus() { | 151 buildUserinfoplus() { |
| 115 var o = new api.Userinfoplus(); | 152 var o = new api.Userinfoplus(); |
| 116 buildCounterUserinfoplus++; | 153 buildCounterUserinfoplus++; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 var o = buildUserinfoplus(); | 220 var o = buildUserinfoplus(); |
| 184 var od = new api.Userinfoplus.fromJson(o.toJson()); | 221 var od = new api.Userinfoplus.fromJson(o.toJson()); |
| 185 checkUserinfoplus(od); | 222 checkUserinfoplus(od); |
| 186 }); | 223 }); |
| 187 }); | 224 }); |
| 188 | 225 |
| 189 | 226 |
| 190 unittest.group("resource-Oauth2Api", () { | 227 unittest.group("resource-Oauth2Api", () { |
| 191 unittest.test("method--getCertForOpenIdConnect", () { | 228 unittest.test("method--getCertForOpenIdConnect", () { |
| 192 | 229 |
| 193 var mock = new common_test.HttpServerMock(); | 230 var mock = new HttpServerMock(); |
| 194 api.Oauth2Api res = new api.Oauth2Api(mock); | 231 api.Oauth2Api res = new api.Oauth2Api(mock); |
| 195 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 232 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 196 var path = (req.url).path; | 233 var path = (req.url).path; |
| 197 var pathOffset = 0; | 234 var pathOffset = 0; |
| 198 var index; | 235 var index; |
| 199 var subPart; | 236 var subPart; |
| 200 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 237 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 201 pathOffset += 1; | 238 pathOffset += 1; |
| 202 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")); |
| 203 pathOffset += 15; | 240 pathOffset += 15; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 217 var keyvalue = part.split("="); | 254 var keyvalue = part.split("="); |
| 218 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 255 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 219 } | 256 } |
| 220 } | 257 } |
| 221 | 258 |
| 222 | 259 |
| 223 var h = { | 260 var h = { |
| 224 "content-type" : "application/json; charset=utf-8", | 261 "content-type" : "application/json; charset=utf-8", |
| 225 }; | 262 }; |
| 226 var resp = convert.JSON.encode(buildJwk()); | 263 var resp = convert.JSON.encode(buildJwk()); |
| 227 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 264 return new async.Future.value(stringResponse(200, h, resp)); |
| 228 }), true); | 265 }), true); |
| 229 res.getCertForOpenIdConnect().then(unittest.expectAsync(((api.Jwk response
) { | 266 res.getCertForOpenIdConnect().then(unittest.expectAsync(((api.Jwk response
) { |
| 230 checkJwk(response); | 267 checkJwk(response); |
| 231 }))); | 268 }))); |
| 232 }); | 269 }); |
| 233 | 270 |
| 234 unittest.test("method--tokeninfo", () { | 271 unittest.test("method--tokeninfo", () { |
| 235 | 272 |
| 236 var mock = new common_test.HttpServerMock(); | 273 var mock = new HttpServerMock(); |
| 237 api.Oauth2Api res = new api.Oauth2Api(mock); | 274 api.Oauth2Api res = new api.Oauth2Api(mock); |
| 238 var arg_accessToken = "foo"; | 275 var arg_accessToken = "foo"; |
| 239 var arg_idToken = "foo"; | 276 var arg_idToken = "foo"; |
| 277 var arg_tokenHandle = "foo"; |
| 240 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 278 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 241 var path = (req.url).path; | 279 var path = (req.url).path; |
| 242 var pathOffset = 0; | 280 var pathOffset = 0; |
| 243 var index; | 281 var index; |
| 244 var subPart; | 282 var subPart; |
| 245 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 283 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 246 pathOffset += 1; | 284 pathOffset += 1; |
| 247 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")); |
| 248 pathOffset += 19; | 286 pathOffset += 19; |
| 249 | 287 |
| 250 var query = (req.url).query; | 288 var query = (req.url).query; |
| 251 var queryOffset = 0; | 289 var queryOffset = 0; |
| 252 var queryMap = {}; | 290 var queryMap = {}; |
| 253 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | 291 addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); |
| 254 parseBool(n) { | 292 parseBool(n) { |
| 255 if (n == "true") return true; | 293 if (n == "true") return true; |
| 256 if (n == "false") return false; | 294 if (n == "false") return false; |
| 257 if (n == null) return null; | 295 if (n == null) return null; |
| 258 throw new core.ArgumentError("Invalid boolean: $n"); | 296 throw new core.ArgumentError("Invalid boolean: $n"); |
| 259 } | 297 } |
| 260 if (query.length > 0) { | 298 if (query.length > 0) { |
| 261 for (var part in query.split("&")) { | 299 for (var part in query.split("&")) { |
| 262 var keyvalue = part.split("="); | 300 var keyvalue = part.split("="); |
| 263 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 301 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 264 } | 302 } |
| 265 } | 303 } |
| 266 unittest.expect(queryMap["access_token"].first, unittest.equals(arg_acce
ssToken)); | 304 unittest.expect(queryMap["access_token"].first, unittest.equals(arg_acce
ssToken)); |
| 267 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)); |
| 268 | 307 |
| 269 | 308 |
| 270 var h = { | 309 var h = { |
| 271 "content-type" : "application/json; charset=utf-8", | 310 "content-type" : "application/json; charset=utf-8", |
| 272 }; | 311 }; |
| 273 var resp = convert.JSON.encode(buildTokeninfo()); | 312 var resp = convert.JSON.encode(buildTokeninfo()); |
| 274 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 313 return new async.Future.value(stringResponse(200, h, resp)); |
| 275 }), true); | 314 }), true); |
| 276 res.tokeninfo(accessToken: arg_accessToken, idToken: arg_idToken).then(uni
ttest.expectAsync(((api.Tokeninfo response) { | 315 res.tokeninfo(accessToken: arg_accessToken, idToken: arg_idToken, tokenHan
dle: arg_tokenHandle).then(unittest.expectAsync(((api.Tokeninfo response) { |
| 277 checkTokeninfo(response); | 316 checkTokeninfo(response); |
| 278 }))); | 317 }))); |
| 279 }); | 318 }); |
| 280 | 319 |
| 281 }); | 320 }); |
| 282 | 321 |
| 283 | 322 |
| 284 unittest.group("resource-UserinfoResourceApi", () { | 323 unittest.group("resource-UserinfoResourceApi", () { |
| 285 unittest.test("method--get", () { | 324 unittest.test("method--get", () { |
| 286 | 325 |
| 287 var mock = new common_test.HttpServerMock(); | 326 var mock = new HttpServerMock(); |
| 288 api.UserinfoResourceApi res = new api.Oauth2Api(mock).userinfo; | 327 api.UserinfoResourceApi res = new api.Oauth2Api(mock).userinfo; |
| 289 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 328 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 290 var path = (req.url).path; | 329 var path = (req.url).path; |
| 291 var pathOffset = 0; | 330 var pathOffset = 0; |
| 292 var index; | 331 var index; |
| 293 var subPart; | 332 var subPart; |
| 294 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 333 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 295 pathOffset += 1; | 334 pathOffset += 1; |
| 296 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")); |
| 297 pathOffset += 18; | 336 pathOffset += 18; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 311 var keyvalue = part.split("="); | 350 var keyvalue = part.split("="); |
| 312 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 351 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 313 } | 352 } |
| 314 } | 353 } |
| 315 | 354 |
| 316 | 355 |
| 317 var h = { | 356 var h = { |
| 318 "content-type" : "application/json; charset=utf-8", | 357 "content-type" : "application/json; charset=utf-8", |
| 319 }; | 358 }; |
| 320 var resp = convert.JSON.encode(buildUserinfoplus()); | 359 var resp = convert.JSON.encode(buildUserinfoplus()); |
| 321 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 360 return new async.Future.value(stringResponse(200, h, resp)); |
| 322 }), true); | 361 }), true); |
| 323 res.get().then(unittest.expectAsync(((api.Userinfoplus response) { | 362 res.get().then(unittest.expectAsync(((api.Userinfoplus response) { |
| 324 checkUserinfoplus(response); | 363 checkUserinfoplus(response); |
| 325 }))); | 364 }))); |
| 326 }); | 365 }); |
| 327 | 366 |
| 328 }); | 367 }); |
| 329 | 368 |
| 330 | 369 |
| 331 unittest.group("resource-UserinfoV2MeResourceApi", () { | 370 unittest.group("resource-UserinfoV2MeResourceApi", () { |
| 332 unittest.test("method--get", () { | 371 unittest.test("method--get", () { |
| 333 | 372 |
| 334 var mock = new common_test.HttpServerMock(); | 373 var mock = new HttpServerMock(); |
| 335 api.UserinfoV2MeResourceApi res = new api.Oauth2Api(mock).userinfo.v2.me; | 374 api.UserinfoV2MeResourceApi res = new api.Oauth2Api(mock).userinfo.v2.me; |
| 336 mock.register(unittest.expectAsync((http.BaseRequest req, json) { | 375 mock.register(unittest.expectAsync((http.BaseRequest req, json) { |
| 337 var path = (req.url).path; | 376 var path = (req.url).path; |
| 338 var pathOffset = 0; | 377 var pathOffset = 0; |
| 339 var index; | 378 var index; |
| 340 var subPart; | 379 var subPart; |
| 341 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); | 380 unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
als("/")); |
| 342 pathOffset += 1; | 381 pathOffset += 1; |
| 343 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")); |
| 344 pathOffset += 14; | 383 pathOffset += 14; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 358 var keyvalue = part.split("="); | 397 var keyvalue = part.split("="); |
| 359 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); | 398 addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
ecodeQueryComponent(keyvalue[1])); |
| 360 } | 399 } |
| 361 } | 400 } |
| 362 | 401 |
| 363 | 402 |
| 364 var h = { | 403 var h = { |
| 365 "content-type" : "application/json; charset=utf-8", | 404 "content-type" : "application/json; charset=utf-8", |
| 366 }; | 405 }; |
| 367 var resp = convert.JSON.encode(buildUserinfoplus()); | 406 var resp = convert.JSON.encode(buildUserinfoplus()); |
| 368 return new async.Future.value(common_test.stringResponse(200, h, resp)); | 407 return new async.Future.value(stringResponse(200, h, resp)); |
| 369 }), true); | 408 }), true); |
| 370 res.get().then(unittest.expectAsync(((api.Userinfoplus response) { | 409 res.get().then(unittest.expectAsync(((api.Userinfoplus response) { |
| 371 checkUserinfoplus(response); | 410 checkUserinfoplus(response); |
| 372 }))); | 411 }))); |
| 373 }); | 412 }); |
| 374 | 413 |
| 375 }); | 414 }); |
| 376 | 415 |
| 377 | 416 |
| 378 } | 417 } |
| 379 | 418 |
| OLD | NEW |