Merge branch 'sdk-2.12.x'

This commit is contained in:
thomashii@dukefirehawk.com 2021-05-01 08:49:32 +08:00
commit 926ab3fabc
4 changed files with 64 additions and 35 deletions

View file

@ -20,7 +20,7 @@
* Updated validate to 3.0.0 * Updated validate to 3.0.0
* Added and updated json_god to 3.0.0 * Added and updated json_god to 3.0.0
* Updated angel_client to 3.0.0 * Updated angel_client to 3.0.0
* Updated angel_websocket to 3.0.0 (one issue to be resolved) * Updated angel_websocket to 3.0.0 (3/3 tests passed)
* Updated test to 3.0.0 * Updated test to 3.0.0
* Updated angel_jael to 3.0.0 (Issue with 2 dependencies) * Updated angel_jael to 3.0.0 (Issue with 2 dependencies)
* Added pub_sub and updated to 3.0.0 * Added pub_sub and updated to 3.0.0

View file

@ -3,23 +3,23 @@ import 'package:pub_sub/pub_sub.dart';
import 'package:pub_sub/isolate.dart'; import 'package:pub_sub/isolate.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
main() { void main() {
Server server; Server server;
Client client1, client2, client3; Client client1, client2, client3;
IsolateClient trustedClient; IsolateClient trustedClient;
IsolateAdapter adapter; IsolateAdapter adapter;
setUp(() async { setUp(() async {
adapter = new IsolateAdapter(); adapter = IsolateAdapter();
client1 = client1 =
new IsolateClient('isolate_test::secret', adapter.receivePort.sendPort); IsolateClient('isolate_test::secret', adapter.receivePort.sendPort);
client2 = new IsolateClient( client2 =
'isolate_test::secret2', adapter.receivePort.sendPort); IsolateClient('isolate_test::secret2', adapter.receivePort.sendPort);
client3 = new IsolateClient( client3 =
'isolate_test::secret3', adapter.receivePort.sendPort); IsolateClient('isolate_test::secret3', adapter.receivePort.sendPort);
trustedClient = new IsolateClient(null, adapter.receivePort.sendPort); trustedClient = IsolateClient(null, adapter.receivePort.sendPort);
server = new Server([adapter]) server = Server([adapter])
..registerClient(const ClientInfo('isolate_test::secret')) ..registerClient(const ClientInfo('isolate_test::secret'))
..registerClient(const ClientInfo('isolate_test::secret2')) ..registerClient(const ClientInfo('isolate_test::secret2'))
..registerClient(const ClientInfo('isolate_test::secret3')) ..registerClient(const ClientInfo('isolate_test::secret3'))
@ -88,7 +88,7 @@ main() {
group('isolate_server', () { group('isolate_server', () {
test('reject unknown client id', () async { test('reject unknown client id', () async {
try { try {
var client = new IsolateClient( var client = IsolateClient(
'isolate_test::invalid', adapter.receivePort.sendPort); 'isolate_test::invalid', adapter.receivePort.sendPort);
await client.publish('foo', 'bar'); await client.publish('foo', 'bar');
throw 'Invalid client ID\'s should throw an error, but they do not.'; throw 'Invalid client ID\'s should throw an error, but they do not.';
@ -99,7 +99,7 @@ main() {
test('reject unprivileged publish', () async { test('reject unprivileged publish', () async {
try { try {
var client = new IsolateClient( var client = IsolateClient(
'isolate_test::no_publish', adapter.receivePort.sendPort); 'isolate_test::no_publish', adapter.receivePort.sendPort);
await client.publish('foo', 'bar'); await client.publish('foo', 'bar');
throw 'Unprivileged publishes should throw an error, but they do not.'; throw 'Unprivileged publishes should throw an error, but they do not.';
@ -110,7 +110,7 @@ main() {
test('reject unprivileged subscribe', () async { test('reject unprivileged subscribe', () async {
try { try {
var client = new IsolateClient( var client = IsolateClient(
'isolate_test::no_subscribe', adapter.receivePort.sendPort); 'isolate_test::no_subscribe', adapter.receivePort.sendPort);
await client.subscribe('foo'); await client.subscribe('foo');
throw 'Unprivileged subscribes should throw an error, but they do not.'; throw 'Unprivileged subscribes should throw an error, but they do not.';

View file

@ -6,7 +6,7 @@ import 'package:pub_sub/json_rpc_2.dart';
import 'package:stream_channel/stream_channel.dart'; import 'package:stream_channel/stream_channel.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
main() { void main() {
ServerSocket serverSocket; ServerSocket serverSocket;
Server server; Server server;
Client client1, client2, client3; Client client1, client2, client3;
@ -16,7 +16,7 @@ main() {
setUp(() async { setUp(() async {
serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0); serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
adapter = new JsonRpc2Adapter( adapter = JsonRpc2Adapter(
serverSocket.map<StreamChannel<String>>(streamSocket), serverSocket.map<StreamChannel<String>>(streamSocket),
isTrusted: true); isTrusted: true);
@ -29,15 +29,12 @@ main() {
var socket4 = var socket4 =
await Socket.connect(InternetAddress.loopbackIPv4, serverSocket.port); await Socket.connect(InternetAddress.loopbackIPv4, serverSocket.port);
client1 = client1 = JsonRpc2Client('json_rpc_2_test::secret', streamSocket(socket1));
new JsonRpc2Client('json_rpc_2_test::secret', streamSocket(socket1)); client2 = JsonRpc2Client('json_rpc_2_test::secret2', streamSocket(socket2));
client2 = client3 = JsonRpc2Client('json_rpc_2_test::secret3', streamSocket(socket3));
new JsonRpc2Client('json_rpc_2_test::secret2', streamSocket(socket2)); trustedClient = JsonRpc2Client(null, streamSocket(socket4));
client3 =
new JsonRpc2Client('json_rpc_2_test::secret3', streamSocket(socket3));
trustedClient = new JsonRpc2Client(null, streamSocket(socket4));
server = new Server([adapter]) server = Server([adapter])
..registerClient(const ClientInfo('json_rpc_2_test::secret')) ..registerClient(const ClientInfo('json_rpc_2_test::secret'))
..registerClient(const ClientInfo('json_rpc_2_test::secret2')) ..registerClient(const ClientInfo('json_rpc_2_test::secret2'))
..registerClient(const ClientInfo('json_rpc_2_test::secret3')) ..registerClient(const ClientInfo('json_rpc_2_test::secret3'))
@ -54,8 +51,12 @@ main() {
}); });
tearDown(() { tearDown(() {
Future.wait( Future.wait([
[server.close(), client1.close(), client2.close(), client3.close()]); server?.close(),
client1?.close(),
client2?.close(),
client3?.close()
]);
}); });
group('trusted', () { group('trusted', () {
@ -104,7 +105,7 @@ main() {
var sock = await Socket.connect( var sock = await Socket.connect(
InternetAddress.loopbackIPv4, serverSocket.port); InternetAddress.loopbackIPv4, serverSocket.port);
var client = var client =
new JsonRpc2Client('json_rpc_2_test::invalid', streamSocket(sock)); JsonRpc2Client('json_rpc_2_test::invalid', streamSocket(sock));
await client.publish('foo', 'bar'); await client.publish('foo', 'bar');
throw 'Invalid client ID\'s should throw an error, but they do not.'; throw 'Invalid client ID\'s should throw an error, but they do not.';
} on PubSubException catch (e) { } on PubSubException catch (e) {
@ -116,8 +117,8 @@ main() {
try { try {
var sock = await Socket.connect( var sock = await Socket.connect(
InternetAddress.loopbackIPv4, serverSocket.port); InternetAddress.loopbackIPv4, serverSocket.port);
var client = new JsonRpc2Client( var client =
'json_rpc_2_test::no_publish', streamSocket(sock)); JsonRpc2Client('json_rpc_2_test::no_publish', streamSocket(sock));
await client.publish('foo', 'bar'); await client.publish('foo', 'bar');
throw 'Unprivileged publishes should throw an error, but they do not.'; throw 'Unprivileged publishes should throw an error, but they do not.';
} on PubSubException catch (e) { } on PubSubException catch (e) {
@ -129,8 +130,8 @@ main() {
try { try {
var sock = await Socket.connect( var sock = await Socket.connect(
InternetAddress.loopbackIPv4, serverSocket.port); InternetAddress.loopbackIPv4, serverSocket.port);
var client = new JsonRpc2Client( var client =
'json_rpc_2_test::no_subscribe', streamSocket(sock)); JsonRpc2Client('json_rpc_2_test::no_subscribe', streamSocket(sock));
await client.subscribe('foo'); await client.subscribe('foo');
throw 'Unprivileged subscribes should throw an error, but they do not.'; throw 'Unprivileged subscribes should throw an error, but they do not.';
} on PubSubException catch (e) { } on PubSubException catch (e) {
@ -141,8 +142,9 @@ main() {
} }
StreamChannel<String> streamSocket(Socket socket) { StreamChannel<String> streamSocket(Socket socket) {
var channel = new _SocketStreamChannel(socket); var channel = _SocketStreamChannel(socket);
return channel.transform(new StreamChannelTransformer.fromCodec(utf8)); var transfomer = StreamChannelTransformer.fromCodec(utf8);
return channel.cast<List<int>>().transform(transfomer);
} }
class _SocketStreamChannel extends StreamChannelMixin<List<int>> { class _SocketStreamChannel extends StreamChannelMixin<List<int>> {
@ -152,7 +154,7 @@ class _SocketStreamChannel extends StreamChannelMixin<List<int>> {
_SocketStreamChannel(this.socket); _SocketStreamChannel(this.socket);
@override @override
StreamSink<List<int>> get sink => _sink ??= new _SocketSink(socket); StreamSink<List<int>> get sink => _sink ??= _SocketSink(socket);
@override @override
Stream<List<int>> get stream => socket; Stream<List<int>> get stream => socket;

View file

@ -95,10 +95,37 @@ class AngelWebSocket {
deserializer ??= (params) => params; deserializer ??= (params) => params;
} }
HookedServiceEventListener serviceHook(String path) { /*
* Deprecated as the return type caused compile time failure.
*/
HookedServiceEventListener _serviceHookOriginal(String path) {
return (HookedServiceEvent e) async { return (HookedServiceEvent e) async {
if (e.params != null && e.params['broadcast'] == false) return; if (e.params != null && e.params['broadcast'] == false) {
return;
}
var event = await transformEvent(e);
event.eventName = '$path::${event.eventName}';
dynamic _filter(WebSocketContext socket) {
if (e.service.configuration.containsKey('ws:filter')) {
return e.service.configuration['ws:filter'](e, socket);
} else if (e.params != null && e.params.containsKey('ws:filter')) {
return e.params['ws:filter'](e, socket);
} else {
return true;
}
}
await batchEvent(event, filter: _filter);
};
}
FutureOr<dynamic> Function(HookedServiceEvent<dynamic, dynamic, Service> e)
serviceHook(String path) {
return (HookedServiceEvent e) async {
if (e.params != null && e.params['broadcast'] == false) {
return;
}
var event = await transformEvent(e); var event = await transformEvent(e);
event.eventName = '$path::${event.eventName}'; event.eventName = '$path::${event.eventName}';