Reset content provider environment
diff --git a/views/ngXosLib/karma.conf.js b/views/ngXosLib/karma.conf.js
index d4137a0..060e7dd 100644
--- a/views/ngXosLib/karma.conf.js
+++ b/views/ngXosLib/karma.conf.js
@@ -18,8 +18,6 @@
'xosHelpers/spec/**/*.test.js'
]);
-console.log('files', files)
-
module.exports = function(config) {
/*eslint-enable*/
config.set({
@@ -79,7 +77,7 @@
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
- logLevel: config.LOG_INFO,
+ logLevel: config.LOG_ERROR,
// enable / disable watching file and executing tests whenever any file changes
diff --git a/views/ngXosLib/xosHelpers/spec/csrftoken.test.js b/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
index 443034d..200014d 100644
--- a/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
+++ b/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
@@ -1,31 +1,45 @@
'use strict';
describe('The xos.helper module', function(){
- var SetCSRFToken, httpProviderObj;
+ var SetCSRFToken, httpProviderObj, httpBackend, http, cookies;
- //beforeEach(module('xos.helpers'));
- //
- //beforeEach(inject(function($httpProvider){
- // httpProviderObj = $httpProvider;
- //}));
- //
- //beforeEach(inject(function(_SetCSRFToken_){
- // console.log('inject csrf');
- // SetCSRFToken = _SetCSRFToken_;
- //}));
+ const fakeToken = 'aiuhsnds98234ndASd';
beforeEach(function() {
- module('xos.helpers', function ($httpProvider) {
- //save our interceptor
- httpProviderObj = $httpProvider;
+ module(
+ 'xos.helpers',
+ function ($httpProvider) {
+ //save our interceptor
+ httpProviderObj = $httpProvider;
+ }
+ );
+
+ inject(function (_SetCSRFToken_, _$httpBackend_, _$http_, _$cookies_) {
+ SetCSRFToken = _SetCSRFToken_;
+ httpBackend = _$httpBackend_;
+ http = _$http_;
+ cookies = _$cookies_
+
+ // mocking $cookie service
+ spyOn(cookies, 'get').and.returnValue(fakeToken);
});
- inject(function (_SetCSRFToken_) {
- SetCSRFToken = _SetCSRFToken_;
- })
});
- it('should exist', () => {
- expect(SetCSRFToken).toBeDefined();
+ describe('the SetCSRFToken', () => {
+ it('should exist', () => {
+ expect(SetCSRFToken).toBeDefined();
+ });
+
+ it('should attach token the request', (done) => {
+ httpBackend.when('POST', 'http://example.com', null, function(headers) {
+ expect(headers['X-CSRFToken']).toBe(fakeToken);
+ done();
+ }).respond(200, {name: 'example' });
+
+ http.post('http://example.com');
+
+ httpBackend.flush();
+ });
});
it('should set SetCSRFToken interceptor', () => {
diff --git a/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
new file mode 100644
index 0000000..560f4dc
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
@@ -0,0 +1,51 @@
+/**
+ * © OpenCORD
+ *
+ * Visit http://guide.xosproject.org/devguide/addview/ for more information
+ *
+ * Created by teone on 3/24/16.
+ */
+
+(function () {
+ 'use strict';
+
+ describe('The NoHyperlinks factory', () => {
+
+ let httpProviderObj, httpBackend, http, noHyperlinks;
+
+ beforeEach(() => {
+ module(
+ 'xos.helpers',
+ ($httpProvider) => {
+ //save our interceptor
+ httpProviderObj = $httpProvider;
+ }
+ );
+
+ inject(function (_$httpBackend_, _$http_, _NoHyperlinks_) {
+ httpBackend = _$httpBackend_;
+ http = _$http_;
+ noHyperlinks = _NoHyperlinks_
+ });
+
+ httpProviderObj.interceptors.push('NoHyperlinks');
+
+ });
+
+ it('should set NoHyperlinks interceptor', () => {
+ expect(httpProviderObj.interceptors).toContain('NoHyperlinks');
+ });
+
+ it('should attach ?no_hyperlinks=1 to the request url', () => {
+ let result = noHyperlinks.request({url: 'sample.url'});
+ expect(result.url).toEqual('sample.url?no_hyperlinks=1');
+ });
+
+ it('should NOT attach ?no_hyperlinks=1 to the request url if is HTML', () => {
+ let result = noHyperlinks.request({url: 'sample.html'});
+ expect(result.url).toEqual('sample.html');
+ });
+
+ });
+})();
+
diff --git a/views/ngXosLib/xosHelpers/src/services/csrfToken.interceptor.js b/views/ngXosLib/xosHelpers/src/services/csrfToken.interceptor.js
index f3a234e..283e90d 100644
--- a/views/ngXosLib/xosHelpers/src/services/csrfToken.interceptor.js
+++ b/views/ngXosLib/xosHelpers/src/services/csrfToken.interceptor.js
@@ -1,8 +1,6 @@
(function() {
'use strict';
- console.log('SetCSRFToken');
-
angular
.module('xos.helpers')
.factory('SetCSRFToken', setCSRFToken);
diff --git a/views/ngXosViews/contentProvider/env/default.js b/views/ngXosViews/contentProvider/env/default.js
new file mode 100644
index 0000000..6370c0c
--- /dev/null
+++ b/views/ngXosViews/contentProvider/env/default.js
@@ -0,0 +1,13 @@
+// This is a default configuration for your development environment.
+// You can duplicate this configuration for any of your Backend Environments.
+// Different configurations are loaded setting a NODE_ENV variable that contain the config file name.
+// `NODE_ENV=local npm start`
+//
+// If xoscsrftoken or xossessionid are not specified the browser value are used
+// (works only for local environment as both application are served on the same domain)
+
+module.exports = {
+ host: 'http://apt020.apt.emulab.net:9999/',
+ xoscsrftoken: 'H6rV67DUIoxw9nBfWlCuUWPckyj10Hx2',
+ xossessionid: 'q7oc8zw5g2awk7n7hme7pmftukkwtf9d'
+};
diff --git a/views/ngXosViews/contentProvider/gulp/server.js b/views/ngXosViews/contentProvider/gulp/server.js
index 8eab1bf..f16d6f2 100644
--- a/views/ngXosViews/contentProvider/gulp/server.js
+++ b/views/ngXosViews/contentProvider/gulp/server.js
@@ -10,8 +10,17 @@
var httpProxy = require('http-proxy');
var del = require('del');
+const environment = process.env.NODE_ENV;
+
+if (environment){
+ var conf = require(`../env/${environment}.js`);
+}
+else{
+ var conf = require('../env/default.js')
+}
+
var proxy = httpProxy.createProxyServer({
- target: 'http://0.0.0.0:9999'
+ target: conf.host || 'http://0.0.0.0:9999'
});
@@ -49,6 +58,10 @@
req.url.indexOf('/xoslib/') !== -1 ||
req.url.indexOf('/hpcapi/') !== -1
){
+ if(conf.xoscsrftoken && conf.xossessionid){
+ req.headers.cookie = `xoscsrftoken=${conf.xoscsrftoken}; xossessionid=${conf.xossessionid}`;
+ req.headers['x-csrftoken'] = conf.xoscsrftoken;
+ }
proxy.web(req, res);
}
else{