Skip to content

Commit e1f005e

Browse files
author
Jonathan
committed
Release 1.0.0-alpha.21.1 🐜
- Fixed bug on ACL Group verificatio- Fixed bug on ACL Group verificationn
1 parent 1d77a54 commit e1f005e

File tree

7 files changed

+105
-11
lines changed

7 files changed

+105
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onixjs/core",
3-
"version": "1.0.0-alpha.22",
3+
"version": "1.0.0-alpha.22.1",
44
"description": "An Enterprise Grade NodeJS Platform that implements Industry Standards and Patterns in order to provide Connectivity, Stability, High-Availability and High-Performance.",
55
"main": "dist/src/index.js",
66
"scripts": {

src/core/app.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class AppServer {
169169
case OperationType.ONIX_REMOTE_CALL_PROCEDURE:
170170
// Register Stream Request
171171
if (operation.message.request.metadata.stream) {
172-
this.streamer.register(operation, chunk => {
172+
await this.streamer.register(operation, chunk => {
173173
if (process.send)
174174
process.send({
175175
uuid: operation.uuid,

src/core/call.responser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class CallResponser {
4444
}
4545
// Declare executable endpoint method and hooks references
4646
let scope,
47+
systemcall: boolean = false,
4748
method: Function | null = null,
4849
mainHook: Function = () => null,
4950
slaveHook: Function | null = null,
@@ -54,6 +55,7 @@ export class CallResponser {
5455
scope = this.factory.app;
5556
method = this.factory.app[segments[1]];
5657
mainHook = this.lifecycle.onAppMethodCall;
58+
systemcall = true;
5759
}
5860
// Module level call (System only, not exposed)
5961
if (segments.length > 2) {
@@ -90,7 +92,10 @@ export class CallResponser {
9092
return;
9193
}
9294
// Verify the call request matches the ACL Rules
93-
if (GroupMatch.verify(method.name, operation, config)) {
95+
if (
96+
(await GroupMatch.verify(method.name, operation, config)) ||
97+
systemcall
98+
) {
9499
// Execute main hook, might be app/system or module level.
95100
const result = await mainHook(
96101
(name: string) => this.factory.scopes[segments[1]].get(name),

src/core/call.streamer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class CallStreamer {
2323
* @description This method will register an incoming call in order
2424
* to send back an answer.
2525
*/
26-
register(operation: IAppOperation, handler) {
26+
async register(operation: IAppOperation, handler) {
2727
// Get segments from rpc endpoint
2828
let scope,
2929
method: Function | null = null,
@@ -73,7 +73,7 @@ export class CallStreamer {
7373
}
7474

7575
// Verify the call request matches the ACL Rules
76-
if (GroupMatch.verify(method.name, operation, config)) {
76+
if (await GroupMatch.verify(method.name, operation, config)) {
7777
// Default handler
7878
const def = data => data;
7979
// Execute main hook, might be app/system or module level.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class OnixJS {
4040
* @description Current Onix Version.
4141
*/
4242
get version(): string {
43-
return '1.0.0-alpha.22';
43+
return '1.0.0-alpha.22.1';
4444
}
4545
/**
4646
* @property router

test/onixjs.acceptance.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ test('Onix app greeter', async t => {
5050
// a bidimentional array of booleans representing every app
5151
// Answering between each others.
5252
const results: boolean[][] = await onix.greet();
53+
console.log(results);
5354
// Both apps should communicate each other and say they are alive (true x 2)
5455
t.deepEqual(results.reduce((a, b) => a.concat(b)), [true, true]);
5556
});

test/onixjs.core.unit.ts

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,45 @@ test('Core: CallResponser invalid call.', async t => {
177177
'OnixJS Error: RPC Call is invalid "something.really.weird.to.call.which.is.invalid"',
178178
);
179179
});
180+
// Test CallResponser not authorized call
181+
test('Core: CallResponser not authorized call.', async t => {
182+
@Component({})
183+
class MyComponent {
184+
@RPC()
185+
testRPC() {
186+
return 'ALO WORLD';
187+
}
188+
@Stream()
189+
testSTREAM() {}
190+
}
191+
@Module({
192+
models: [],
193+
renderers: [],
194+
services: [],
195+
components: [MyComponent],
196+
})
197+
class MyModule {}
198+
class MyApp extends Application {}
199+
const factory: AppFactory = new AppFactory(MyApp);
200+
factory.config = {network: {disabled: true}, modules: [MyModule]};
201+
factory.notifier = new AppNotifier();
202+
await factory.setup();
203+
const responser: CallResponser = new CallResponser(factory);
204+
const result = await responser.process({
205+
uuid: Utils.uuid(),
206+
type: OperationType.ONIX_REMOTE_CALL_PROCEDURE,
207+
message: {
208+
rpc: 'MyApp.MyModule.MyComponent.testRPC',
209+
request: <IRequest>{},
210+
},
211+
});
212+
t.is(result.code, 401);
213+
});
180214
// Test CallResponser valid call
181215
test('Core: CallResponser valid call.', async t => {
182-
@Component({})
216+
@Component({
217+
acl: [AllowEveryone],
218+
})
183219
class MyComponent {
184220
@RPC()
185221
testRPC() {
@@ -250,6 +286,7 @@ test('Core: CallResponser invalid call.', async t => {
250286
// Test CallResponser Hooks
251287
test('Core: CallResponser Hooks.', async t => {
252288
@Component({
289+
acl: [AllowEveryone],
253290
lifecycle: async function(app, metadata, method) {
254291
const methodResult = await method();
255292
return methodResult;
@@ -290,9 +327,10 @@ test('Core: CallResponser Hooks.', async t => {
290327
t.is(result.text, 'Hello Responser');
291328
});
292329

293-
// Test CallResponser Hooks
294-
test('Core: CallResponser Hooks.', async t => {
330+
// Test CallStreamer Valid
331+
test('Core: CallStreamer Valid.', async t => {
295332
@Component({
333+
acl: [AllowEveryone],
296334
lifecycle: async function(app, metadata, method) {
297335
const methodResult = await method();
298336
return methodResult;
@@ -319,7 +357,7 @@ test('Core: CallResponser Hooks.', async t => {
319357
factory.notifier = new AppNotifier();
320358
await factory.setup();
321359
const streamer: CallStreamer = new CallStreamer(factory);
322-
streamer.register(
360+
await streamer.register(
323361
{
324362
uuid: Utils.uuid(),
325363
type: OperationType.ONIX_REMOTE_CALL_PROCEDURE,
@@ -339,6 +377,56 @@ test('Core: CallResponser Hooks.', async t => {
339377
);
340378
});
341379

380+
// Test CallStreamer Not Authorized
381+
test('Core: CallStreamer Not Authorized.', async t => {
382+
@Component({
383+
lifecycle: async function(app, metadata, method) {
384+
const methodResult = await method();
385+
return methodResult;
386+
},
387+
})
388+
class MyComponent {
389+
@Stream()
390+
test(stream) {
391+
return stream({
392+
text: 'Hello Streamer',
393+
});
394+
}
395+
}
396+
@Module({
397+
models: [],
398+
renderers: [],
399+
services: [],
400+
components: [MyComponent],
401+
})
402+
class MyModule {}
403+
class MyApp extends Application {}
404+
const factory: AppFactory = new AppFactory(MyApp);
405+
factory.config = {network: {disabled: true}, modules: [MyModule]};
406+
factory.notifier = new AppNotifier();
407+
await factory.setup();
408+
const streamer: CallStreamer = new CallStreamer(factory);
409+
await streamer.register(
410+
{
411+
uuid: Utils.uuid(),
412+
type: OperationType.ONIX_REMOTE_CALL_PROCEDURE,
413+
message: {
414+
rpc: 'MyApp.MyModule.MyComponent.test',
415+
request: <IRequest>{
416+
metadata: {stream: true},
417+
payload: {},
418+
},
419+
},
420+
},
421+
result => {
422+
console.log('SOME GOD DAMN RESULT: ', result);
423+
if (result) {
424+
t.is(result.code, 401);
425+
}
426+
},
427+
);
428+
});
429+
342430
// Test CallStreamer invalid call
343431
test('Core: CallStreamer invalid call.', async t => {
344432
class MyComponent {}
@@ -355,7 +443,7 @@ test('Core: CallStreamer invalid call.', async t => {
355443
factory.notifier = new AppNotifier();
356444
await factory.setup();
357445
const streamer: CallStreamer = new CallStreamer(factory);
358-
streamer.register(
446+
await streamer.register(
359447
{
360448
uuid: Utils.uuid(),
361449
type: OperationType.ONIX_REMOTE_CALL_PROCEDURE,

0 commit comments

Comments
 (0)