Skip to content

Commit

Permalink
issue-43 - Fix rest requests for mesh with domain specified
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanvdWest committed Apr 18, 2017
1 parent 9864bf7 commit 6bd8ed0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/modules/rest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ Rest.prototype.__authorizeAccessPoint = function ($happn, $origin, accessPoint,

var _this = this;

var name = $happn._mesh.config.domain || $happn._mesh.config.name;

accessPoint = utilities.removeLeading('/', accessPoint);
accessPoint = "/_exchange/requests/" + $happn._mesh.config.name + "/" + accessPoint;
accessPoint = "/_exchange/requests/" + name + "/" + accessPoint;

_this.__securityService.authorize($origin, accessPoint, 'set', function (e, authorized, reason) {

Expand Down
38 changes: 33 additions & 5 deletions test/f5-domain-compatibility-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var OldHappner = require('happner');
var Happner = require('../');
var expect = require('expect.js');

describe(require('path').basename(__filename), function () {
describe.only(require('path').basename(__filename), function () {

context('insecure', function () {

Expand Down Expand Up @@ -65,6 +65,17 @@ describe(require('path').basename(__filename), function () {
.then(done).catch(done);
});

it('can call component methods through rest', function (done) {
var restler = require('restler');
restler.get('http://localhost:55000/rest/method/testComponent/method', {})
.on('complete', function(result) {
if (result instanceof Error) return done(result);
expect(result.error).to.eql(null);
expect(result.data).to.equal('MESH_DOMAIN');
done();
});
});

it('can subscribe to events', function (done) {
client.event.testComponent.on('/event', function (data) {
try {
Expand Down Expand Up @@ -94,6 +105,11 @@ describe(require('path').basename(__filename), function () {

var server, client;

var user = {
username: 'username',
password: 'password'
};

before('start server', function (done) {
server = undefined;
Happner.create({
Expand Down Expand Up @@ -145,10 +161,6 @@ describe(require('path').basename(__filename), function () {
}
}
};
var user = {
username: 'username',
password: 'password'
};

Promise.all([
security.addGroup(group),
Expand Down Expand Up @@ -191,6 +203,22 @@ describe(require('path').basename(__filename), function () {
.then(done).catch(done);
});

it('can call component methods through rest', function (done) {
var restler = require('restler');
restler.postJson('http://localhost:55000/rest/login', user).on('complete', function(result){
if (result.error)
return done(new Error(result.error.message));
var token = result.data.token;
restler.get('http://localhost:55000/rest/method/testComponent/method?happn_token=' + token, {})
.on('complete', function(result) {
if (result instanceof Error) return done(result);
expect(result.error).to.eql(null);
expect(result.data).to.equal('DOMAIN_NAME');
done();
});
});
});

it('can subscribe to events', function (done) {
client.event.testComponent.on('event', function (data) {
try {
Expand Down

0 comments on commit 6bd8ed0

Please sign in to comment.