Chromium Code Reviews| 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 server; | |
| 17 setUp(() => server = new json_rpc.Server()); | |
| 18 | |
| 19 test("a non-Array/Object request is invalid", () { | |
| 20 expectErrorResponse(server, 'foo', error_code.INVALID_REQUEST, | |
| 21 'Requests must be Arrays or Objects.'); | |
|
Bob Nystrom
2014/03/20 18:25:58
I think this error message should be singular.
nweiz
2014/03/20 22:55:41
Done.
| |
| 22 }); | |
| 23 | |
| 24 test("requests must have a jsonrpc key", () { | |
| 25 expectErrorResponse(server, { | |
| 26 'method': 'foo', | |
| 27 'id': 1234 | |
| 28 }, error_code.INVALID_REQUEST, 'Requests must contain a "jsonrpc" key.'); | |
|
Bob Nystrom
2014/03/20 18:25:58
Ditto.
nweiz
2014/03/20 22:55:41
Done.
| |
| 29 }); | |
| 30 | |
| 31 test("the jsonrpc version must be 2.0", () { | |
| 32 expectErrorResponse(server, { | |
| 33 'jsonrpc': '1.0', | |
| 34 'method': 'foo', | |
| 35 'id': 1234 | |
| 36 }, | |
| 37 error_code.INVALID_REQUEST, | |
|
Bob Nystrom
2014/03/20 18:25:58
Nit: move this to the previous line? Here and belo
nweiz
2014/03/20 22:55:41
Done.
| |
| 38 'Invalid JSON-RPC version "1.0", expected "2.0".'); | |
| 39 }); | |
| 40 | |
| 41 test("requests must have a method key", () { | |
| 42 expectErrorResponse(server, { | |
| 43 'jsonrpc': '2.0', | |
| 44 'id': 1234 | |
| 45 }, error_code.INVALID_REQUEST, 'Requests must contain a "method" key.'); | |
| 46 }); | |
| 47 | |
| 48 test("request method must be a string", () { | |
| 49 expectErrorResponse(server, { | |
| 50 'jsonrpc': '2.0', | |
| 51 'method': 1234, | |
| 52 'id': 1234 | |
| 53 }, | |
| 54 error_code.INVALID_REQUEST, | |
| 55 'Request method must be a string, but was "1234".'); | |
| 56 }); | |
| 57 | |
| 58 test("request params must be an Array or Object", () { | |
| 59 expectErrorResponse(server, { | |
| 60 'jsonrpc': '2.0', | |
| 61 'method': 'foo', | |
| 62 'params': 1234, | |
| 63 'id': 1234 | |
| 64 }, | |
| 65 error_code.INVALID_REQUEST, | |
| 66 'Request params must be an Array or an Object, but was "1234".'); | |
| 67 }); | |
| 68 | |
| 69 test("request id must be an Array or Object", () { | |
|
Bob Nystrom
2014/03/20 18:25:58
Fix description.
| |
| 70 expect(server.handleRequest({ | |
| 71 'jsonrpc': '2.0', | |
| 72 'method': 'foo', | |
| 73 'id': {'bad': 'id'} | |
| 74 }), completion(equals({ | |
| 75 'jsonrpc': '2.0', | |
| 76 'id': null, | |
| 77 'error': { | |
| 78 'code': error_code.INVALID_REQUEST, | |
| 79 'message': 'Request id must be a string, number, or null, but was ' | |
| 80 '"{bad: id}".', | |
| 81 'data': {'request': { | |
| 82 'jsonrpc': '2.0', | |
| 83 'method': 'foo', | |
| 84 'id': {'bad': 'id'} | |
| 85 }} | |
| 86 } | |
| 87 }))); | |
| 88 }); | |
| 89 } | |
| OLD | NEW |