| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library json_rpc_2.test.server.invalid_request_test; | |
| 6 | |
| 7 import 'dart:convert'; | |
| 8 | |
| 9 import 'package:unittest/unittest.dart'; | |
| 10 import 'package:json_rpc_2/error_code.dart' as error_code; | |
| 11 import 'package:json_rpc_2/json_rpc_2.dart' as json_rpc; | |
| 12 | |
| 13 import 'utils.dart'; | |
| 14 | |
| 15 void main() { | |
| 16 var controller; | |
| 17 setUp(() => controller = new ServerController()); | |
| 18 | |
| 19 test("a non-Array/Object request is invalid", () { | |
| 20 expectErrorResponse(controller, 'foo', error_code.INVALID_REQUEST, | |
| 21 'Request must be an Array or an Object.'); | |
| 22 }); | |
| 23 | |
| 24 test("requests must have a jsonrpc key", () { | |
| 25 expectErrorResponse(controller, { | |
| 26 'method': 'foo', | |
| 27 'id': 1234 | |
| 28 }, error_code.INVALID_REQUEST, 'Request must contain a "jsonrpc" key.'); | |
| 29 }); | |
| 30 | |
| 31 test("the jsonrpc version must be 2.0", () { | |
| 32 expectErrorResponse(controller, { | |
| 33 'jsonrpc': '1.0', | |
| 34 'method': 'foo', | |
| 35 'id': 1234 | |
| 36 }, error_code.INVALID_REQUEST, | |
| 37 'Invalid JSON-RPC version "1.0", expected "2.0".'); | |
| 38 }); | |
| 39 | |
| 40 test("requests must have a method key", () { | |
| 41 expectErrorResponse(controller, { | |
| 42 'jsonrpc': '2.0', | |
| 43 'id': 1234 | |
| 44 }, error_code.INVALID_REQUEST, 'Request must contain a "method" key.'); | |
| 45 }); | |
| 46 | |
| 47 test("request method must be a string", () { | |
| 48 expectErrorResponse(controller, { | |
| 49 'jsonrpc': '2.0', | |
| 50 'method': 1234, | |
| 51 'id': 1234 | |
| 52 }, error_code.INVALID_REQUEST, | |
| 53 'Request method must be a string, but was 1234.'); | |
| 54 }); | |
| 55 | |
| 56 test("request params must be an Array or Object", () { | |
| 57 expectErrorResponse(controller, { | |
| 58 'jsonrpc': '2.0', | |
| 59 'method': 'foo', | |
| 60 'params': 1234, | |
| 61 'id': 1234 | |
| 62 }, error_code.INVALID_REQUEST, | |
| 63 'Request params must be an Array or an Object, but was 1234.'); | |
| 64 }); | |
| 65 | |
| 66 test("request id may not be an Array or Object", () { | |
| 67 expect(controller.handleRequest({ | |
| 68 'jsonrpc': '2.0', | |
| 69 'method': 'foo', | |
| 70 'id': {'bad': 'id'} | |
| 71 }), completion(equals({ | |
| 72 'jsonrpc': '2.0', | |
| 73 'id': null, | |
| 74 'error': { | |
| 75 'code': error_code.INVALID_REQUEST, | |
| 76 'message': 'Request id must be a string, number, or null, but was ' | |
| 77 '{"bad":"id"}.', | |
| 78 'data': {'request': { | |
| 79 'jsonrpc': '2.0', | |
| 80 'method': 'foo', | |
| 81 'id': {'bad': 'id'} | |
| 82 }} | |
| 83 } | |
| 84 }))); | |
| 85 }); | |
| 86 } | |
| OLD | NEW |