Merge branch 'sdk-2.12.x'
This commit is contained in:
commit
926ab3fabc
4 changed files with 64 additions and 35 deletions
|
@ -20,7 +20,7 @@
|
|||
* Updated validate to 3.0.0
|
||||
* Added and updated json_god 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 angel_jael to 3.0.0 (Issue with 2 dependencies)
|
||||
* Added pub_sub and updated to 3.0.0
|
||||
|
|
|
@ -3,23 +3,23 @@ import 'package:pub_sub/pub_sub.dart';
|
|||
import 'package:pub_sub/isolate.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
void main() {
|
||||
Server server;
|
||||
Client client1, client2, client3;
|
||||
IsolateClient trustedClient;
|
||||
IsolateAdapter adapter;
|
||||
|
||||
setUp(() async {
|
||||
adapter = new IsolateAdapter();
|
||||
adapter = IsolateAdapter();
|
||||
client1 =
|
||||
new IsolateClient('isolate_test::secret', adapter.receivePort.sendPort);
|
||||
client2 = new IsolateClient(
|
||||
'isolate_test::secret2', adapter.receivePort.sendPort);
|
||||
client3 = new IsolateClient(
|
||||
'isolate_test::secret3', adapter.receivePort.sendPort);
|
||||
trustedClient = new IsolateClient(null, adapter.receivePort.sendPort);
|
||||
IsolateClient('isolate_test::secret', adapter.receivePort.sendPort);
|
||||
client2 =
|
||||
IsolateClient('isolate_test::secret2', adapter.receivePort.sendPort);
|
||||
client3 =
|
||||
IsolateClient('isolate_test::secret3', 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::secret2'))
|
||||
..registerClient(const ClientInfo('isolate_test::secret3'))
|
||||
|
@ -88,7 +88,7 @@ main() {
|
|||
group('isolate_server', () {
|
||||
test('reject unknown client id', () async {
|
||||
try {
|
||||
var client = new IsolateClient(
|
||||
var client = IsolateClient(
|
||||
'isolate_test::invalid', adapter.receivePort.sendPort);
|
||||
await client.publish('foo', 'bar');
|
||||
throw 'Invalid client ID\'s should throw an error, but they do not.';
|
||||
|
@ -99,7 +99,7 @@ main() {
|
|||
|
||||
test('reject unprivileged publish', () async {
|
||||
try {
|
||||
var client = new IsolateClient(
|
||||
var client = IsolateClient(
|
||||
'isolate_test::no_publish', adapter.receivePort.sendPort);
|
||||
await client.publish('foo', 'bar');
|
||||
throw 'Unprivileged publishes should throw an error, but they do not.';
|
||||
|
@ -110,7 +110,7 @@ main() {
|
|||
|
||||
test('reject unprivileged subscribe', () async {
|
||||
try {
|
||||
var client = new IsolateClient(
|
||||
var client = IsolateClient(
|
||||
'isolate_test::no_subscribe', adapter.receivePort.sendPort);
|
||||
await client.subscribe('foo');
|
||||
throw 'Unprivileged subscribes should throw an error, but they do not.';
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:pub_sub/json_rpc_2.dart';
|
|||
import 'package:stream_channel/stream_channel.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
void main() {
|
||||
ServerSocket serverSocket;
|
||||
Server server;
|
||||
Client client1, client2, client3;
|
||||
|
@ -16,7 +16,7 @@ main() {
|
|||
setUp(() async {
|
||||
serverSocket = await ServerSocket.bind(InternetAddress.loopbackIPv4, 0);
|
||||
|
||||
adapter = new JsonRpc2Adapter(
|
||||
adapter = JsonRpc2Adapter(
|
||||
serverSocket.map<StreamChannel<String>>(streamSocket),
|
||||
isTrusted: true);
|
||||
|
||||
|
@ -29,15 +29,12 @@ main() {
|
|||
var socket4 =
|
||||
await Socket.connect(InternetAddress.loopbackIPv4, serverSocket.port);
|
||||
|
||||
client1 =
|
||||
new JsonRpc2Client('json_rpc_2_test::secret', streamSocket(socket1));
|
||||
client2 =
|
||||
new JsonRpc2Client('json_rpc_2_test::secret2', streamSocket(socket2));
|
||||
client3 =
|
||||
new JsonRpc2Client('json_rpc_2_test::secret3', streamSocket(socket3));
|
||||
trustedClient = new JsonRpc2Client(null, streamSocket(socket4));
|
||||
client1 = JsonRpc2Client('json_rpc_2_test::secret', streamSocket(socket1));
|
||||
client2 = JsonRpc2Client('json_rpc_2_test::secret2', streamSocket(socket2));
|
||||
client3 = JsonRpc2Client('json_rpc_2_test::secret3', streamSocket(socket3));
|
||||
trustedClient = 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::secret2'))
|
||||
..registerClient(const ClientInfo('json_rpc_2_test::secret3'))
|
||||
|
@ -54,8 +51,12 @@ main() {
|
|||
});
|
||||
|
||||
tearDown(() {
|
||||
Future.wait(
|
||||
[server.close(), client1.close(), client2.close(), client3.close()]);
|
||||
Future.wait([
|
||||
server?.close(),
|
||||
client1?.close(),
|
||||
client2?.close(),
|
||||
client3?.close()
|
||||
]);
|
||||
});
|
||||
|
||||
group('trusted', () {
|
||||
|
@ -104,7 +105,7 @@ main() {
|
|||
var sock = await Socket.connect(
|
||||
InternetAddress.loopbackIPv4, serverSocket.port);
|
||||
var client =
|
||||
new JsonRpc2Client('json_rpc_2_test::invalid', streamSocket(sock));
|
||||
JsonRpc2Client('json_rpc_2_test::invalid', streamSocket(sock));
|
||||
await client.publish('foo', 'bar');
|
||||
throw 'Invalid client ID\'s should throw an error, but they do not.';
|
||||
} on PubSubException catch (e) {
|
||||
|
@ -116,8 +117,8 @@ main() {
|
|||
try {
|
||||
var sock = await Socket.connect(
|
||||
InternetAddress.loopbackIPv4, serverSocket.port);
|
||||
var client = new JsonRpc2Client(
|
||||
'json_rpc_2_test::no_publish', streamSocket(sock));
|
||||
var client =
|
||||
JsonRpc2Client('json_rpc_2_test::no_publish', streamSocket(sock));
|
||||
await client.publish('foo', 'bar');
|
||||
throw 'Unprivileged publishes should throw an error, but they do not.';
|
||||
} on PubSubException catch (e) {
|
||||
|
@ -129,8 +130,8 @@ main() {
|
|||
try {
|
||||
var sock = await Socket.connect(
|
||||
InternetAddress.loopbackIPv4, serverSocket.port);
|
||||
var client = new JsonRpc2Client(
|
||||
'json_rpc_2_test::no_subscribe', streamSocket(sock));
|
||||
var client =
|
||||
JsonRpc2Client('json_rpc_2_test::no_subscribe', streamSocket(sock));
|
||||
await client.subscribe('foo');
|
||||
throw 'Unprivileged subscribes should throw an error, but they do not.';
|
||||
} on PubSubException catch (e) {
|
||||
|
@ -141,8 +142,9 @@ main() {
|
|||
}
|
||||
|
||||
StreamChannel<String> streamSocket(Socket socket) {
|
||||
var channel = new _SocketStreamChannel(socket);
|
||||
return channel.transform(new StreamChannelTransformer.fromCodec(utf8));
|
||||
var channel = _SocketStreamChannel(socket);
|
||||
var transfomer = StreamChannelTransformer.fromCodec(utf8);
|
||||
return channel.cast<List<int>>().transform(transfomer);
|
||||
}
|
||||
|
||||
class _SocketStreamChannel extends StreamChannelMixin<List<int>> {
|
||||
|
@ -152,7 +154,7 @@ class _SocketStreamChannel extends StreamChannelMixin<List<int>> {
|
|||
_SocketStreamChannel(this.socket);
|
||||
|
||||
@override
|
||||
StreamSink<List<int>> get sink => _sink ??= new _SocketSink(socket);
|
||||
StreamSink<List<int>> get sink => _sink ??= _SocketSink(socket);
|
||||
|
||||
@override
|
||||
Stream<List<int>> get stream => socket;
|
||||
|
|
|
@ -95,10 +95,37 @@ class AngelWebSocket {
|
|||
deserializer ??= (params) => params;
|
||||
}
|
||||
|
||||
HookedServiceEventListener serviceHook(String path) {
|
||||
/*
|
||||
* Deprecated as the return type caused compile time failure.
|
||||
*/
|
||||
HookedServiceEventListener _serviceHookOriginal(String path) {
|
||||
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);
|
||||
event.eventName = '$path::${event.eventName}';
|
||||
|
||||
|
|
Loading…
Reference in a new issue