From 29822599d62ce43b8ed15b8c2fca1210725b235c Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Mon, 10 Jun 2019 11:15:49 -0400 Subject: [PATCH 1/3] [DEV-5492] Add basic tests for UserSession.js --- test/server/request/UserSessionTest.js | 156 +++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 test/server/request/UserSessionTest.js diff --git a/test/server/request/UserSessionTest.js b/test/server/request/UserSessionTest.js new file mode 100644 index 0000000..b727989 --- /dev/null +++ b/test/server/request/UserSessionTest.js @@ -0,0 +1,156 @@ +/** + * Manages DataAPI requests and return data + * + * Copyright (C) 2019 R-T Specialty, LLC. + * + * This file is part of the Liza Data Collection Framework. + * + * liza is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +'use strict'; + +const { Class } = require( 'easejs' ); +const { expect } = require( 'chai' ); +const Sut = require( '../../../' ).server.request.UserSession; + + +describe( 'UserSession', () => +{ + [ + { + session: null, + expects: {}, + }, + { + session: "", + expects: {}, + }, + { + session: 'foo|s:1:"a";', + expects: { "foo": "a" }, + }, + { + session: 'foo|a:1:{i:0;s:1:"a";}', + expects: { "foo": { "0": "a" } }, + }, + { + session: 'foo|a:1:{i:0;s:1:"a";}|bar|a:1:{s:1:"a";i:1;}', + expects: { "foo": { "0": "a" }, "bar": { "a": 1 } }, + }, + ].forEach( ( data ) => + { + it( "getData", () => + { + let sut = new Sut( + 1, + { + "get": function( sesion_key, callback ) + { + return callback( data.session ); + }, + } + ); + + expect( + sut.getData() + ).to.deep.equal( data.expects ); + } ); + } ); + + + [ + { + session: null, + expects: false, + }, + { + session: "", + expects: false, + }, + { + session: 'foo|s:1:"a";', + expects: false, + }, + { + session: 'agentID|s:0:"";}', + expects: true, + }, + { + session: 'agentID|s:1:"1";}', + expects: true, + }, + ].forEach( ( data ) => + { + it( "isLoggedIn", () => + { + let sut = new Sut( + 1, + { + "get": function( sesion_key, callback ) + { + return callback( data.session ); + }, + } + ); + + expect( + sut.isLoggedIn() + ).to.be.equal( data.expects ); + } ); + } ); + + + [ + { + session: null, + expects: undefined, + }, + { + session: "", + expects: undefined, + }, + { + session: 'foo|s:1:"a";', + expects: undefined, + }, + { + session: 'agentID|s:0:"";}', + expects: undefined, + }, + { + session: 'agentID|s:1:"1";}', + expects: "1", + }, + ].forEach( ( data ) => + { + it( "agentId", () => + { + let sut = new Sut( + 1, + { + "get": function( sesion_key, callback ) + { + return callback( data.session ); + }, + } + ); + + expect( + sut.agentId() + ).to.be.equal( data.expects ); + } ); + } ); +} ); + From 5b08c981c38e40b68b468c5bf680dddb8fe6190b Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Mon, 10 Jun 2019 11:19:04 -0400 Subject: [PATCH 2/3] [DEV-5492] Do not unserialize PHP objects in _sf2_attributes The PHP objects in the session from PHP7 cannot be unserialized. Since they are not needed, we can safely ignore them. Co-Authored-By: Jim Grundner --- src/server/request/UserSession.js | 16 +++++++++++----- test/server/request/UserSessionTest.js | 10 +++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/server/request/UserSession.js b/src/server/request/UserSession.js index 56a3e23..f4a0c9f 100644 --- a/src/server/request/UserSession.js +++ b/src/server/request/UserSession.js @@ -1,7 +1,7 @@ /** * UserSession class * - * Copyright (C) 2017 R-T Specialty, LLC. + * Copyright (C) 2019 R-T Specialty, LLC. * * This file is part of the Liza Data Collection Framework. * @@ -280,11 +280,17 @@ module.exports = Class.extend( require( 'events' ).EventEmitter, var key = splits[ i ], val = splits[ ++i ]; - // the values are serialized PHP data; unserialize them - val = php.unserialize( val ); + // we do not need _sf2_attributes since they are serialized PHP + // objects and cause problems unserializing when they are + // serialized in PHP7. + if ( key !== '_sf2_attributes' ) + { + // the values are serialized PHP data; unserialize them + val = php.unserialize( val ); - // add to the session data - session_data[ key ] = val; + // add to the session data + session_data[ key ] = val; + } } } diff --git a/test/server/request/UserSessionTest.js b/test/server/request/UserSessionTest.js index b727989..e0c1003 100644 --- a/test/server/request/UserSessionTest.js +++ b/test/server/request/UserSessionTest.js @@ -46,9 +46,17 @@ describe( 'UserSession', () => expects: { "foo": { "0": "a" } }, }, { - session: 'foo|a:1:{i:0;s:1:"a";}|bar|a:1:{s:1:"a";i:1;}', + session: 'foo|a:1:{i:0;s:1:"a";}bar|a:1:{s:1:"a";i:1;}', expects: { "foo": { "0": "a" }, "bar": { "a": 1 } }, }, + { + session: '_sf2_attributes|a:1:{i:0;s:1:"a";}', + expects: {}, + }, + { + session: 'foo|a:1:{i:0;s:1:"a";}_sf2_attributes|a:1:{i:0;s:1:"a";}', + expects: { "foo": { "0": "a" } }, + }, ].forEach( ( data ) => { it( "getData", () => From 2b2b3fe78ca76db442de0a88890de6ac1ffed18c Mon Sep 17 00:00:00 2001 From: Joseph Frazer Date: Mon, 10 Jun 2019 11:52:51 -0400 Subject: [PATCH 3/3] Revert "[DEV-5492] Add basic tests for UserSession.js" This reverts commit 29822599d62ce43b8ed15b8c2fca1210725b235c. --- test/server/request/UserSessionTest.js | 164 ------------------------- 1 file changed, 164 deletions(-) delete mode 100644 test/server/request/UserSessionTest.js diff --git a/test/server/request/UserSessionTest.js b/test/server/request/UserSessionTest.js deleted file mode 100644 index e0c1003..0000000 --- a/test/server/request/UserSessionTest.js +++ /dev/null @@ -1,164 +0,0 @@ -/** - * Manages DataAPI requests and return data - * - * Copyright (C) 2019 R-T Specialty, LLC. - * - * This file is part of the Liza Data Collection Framework. - * - * liza is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -'use strict'; - -const { Class } = require( 'easejs' ); -const { expect } = require( 'chai' ); -const Sut = require( '../../../' ).server.request.UserSession; - - -describe( 'UserSession', () => -{ - [ - { - session: null, - expects: {}, - }, - { - session: "", - expects: {}, - }, - { - session: 'foo|s:1:"a";', - expects: { "foo": "a" }, - }, - { - session: 'foo|a:1:{i:0;s:1:"a";}', - expects: { "foo": { "0": "a" } }, - }, - { - session: 'foo|a:1:{i:0;s:1:"a";}bar|a:1:{s:1:"a";i:1;}', - expects: { "foo": { "0": "a" }, "bar": { "a": 1 } }, - }, - { - session: '_sf2_attributes|a:1:{i:0;s:1:"a";}', - expects: {}, - }, - { - session: 'foo|a:1:{i:0;s:1:"a";}_sf2_attributes|a:1:{i:0;s:1:"a";}', - expects: { "foo": { "0": "a" } }, - }, - ].forEach( ( data ) => - { - it( "getData", () => - { - let sut = new Sut( - 1, - { - "get": function( sesion_key, callback ) - { - return callback( data.session ); - }, - } - ); - - expect( - sut.getData() - ).to.deep.equal( data.expects ); - } ); - } ); - - - [ - { - session: null, - expects: false, - }, - { - session: "", - expects: false, - }, - { - session: 'foo|s:1:"a";', - expects: false, - }, - { - session: 'agentID|s:0:"";}', - expects: true, - }, - { - session: 'agentID|s:1:"1";}', - expects: true, - }, - ].forEach( ( data ) => - { - it( "isLoggedIn", () => - { - let sut = new Sut( - 1, - { - "get": function( sesion_key, callback ) - { - return callback( data.session ); - }, - } - ); - - expect( - sut.isLoggedIn() - ).to.be.equal( data.expects ); - } ); - } ); - - - [ - { - session: null, - expects: undefined, - }, - { - session: "", - expects: undefined, - }, - { - session: 'foo|s:1:"a";', - expects: undefined, - }, - { - session: 'agentID|s:0:"";}', - expects: undefined, - }, - { - session: 'agentID|s:1:"1";}', - expects: "1", - }, - ].forEach( ( data ) => - { - it( "agentId", () => - { - let sut = new Sut( - 1, - { - "get": function( sesion_key, callback ) - { - return callback( data.session ); - }, - } - ); - - expect( - sut.agentId() - ).to.be.equal( data.expects ); - } ); - } ); -} ); -