-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into production
- Loading branch information
Showing
11 changed files
with
200 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,9 @@ | |
"afterEach", | ||
"-event", | ||
"makeTestApp", | ||
"BACKEND_URL" | ||
"BACKEND_URL", | ||
"RAVEN_URL", | ||
"ENVIRONMENT", | ||
"GIT_COMMIT" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import angular from 'angular'; | ||
import ravenService from './raven.service'; | ||
|
||
const ravenUrl = window.ushahidi.ravenUrl || false; | ||
let ravenModule; | ||
// Load raven if configured | ||
if (ravenUrl) { | ||
let Raven = require('raven-js'); | ||
|
||
Raven | ||
.config(ravenUrl, { | ||
release: GIT_COMMIT, | ||
environment: window.ushahidi.environment || ENVIRONMENT, | ||
tags: { | ||
git_commit: GIT_COMMIT | ||
}, | ||
sanitizeKeys: [/Authorization/i, /password/i, /accessToken/i, /api_key/i, /client_secret/i], | ||
dataCallback: (data) => { | ||
// Replace stringified sensitive info | ||
if (data.message) { | ||
data.message = data.message.replace(/"(Authorization|client_secret|password|accessToken)":"(.*?)"/, '"$1":"****"'); | ||
} | ||
|
||
if (data.fingerprint) { | ||
data.fingerprint.forEach((value, index) => { | ||
data.fingerprint[index] = value.replace(/"(Authorization|client_secret|password|accessToken)":"(.*?)"/, '"$1":"****"'); | ||
}); | ||
} | ||
|
||
if (data.breadcrumbs && data.breadcrumbs.values) { | ||
data.breadcrumbs.values.forEach((value, index) => { | ||
if (value.message) { | ||
data.breadcrumbs.values[index].message = value.message.replace(/"(Authorization|client_secret|password|accessToken)":"(.*?)"/, '"$1":"****"'); | ||
} | ||
}); | ||
} | ||
} | ||
}) | ||
.addPlugin(require('raven-js/plugins/angular'), angular) | ||
.install(); | ||
|
||
ravenModule = angular.module('app.raven', [ | ||
'ngRaven' | ||
]) | ||
|
||
.factory('Raven', () => { | ||
return Raven; | ||
}) | ||
|
||
.service({ | ||
ravenService | ||
}) | ||
|
||
.run(['ravenService', (ravenService) => { | ||
if (ravenUrl) { | ||
ravenService.init(); | ||
} | ||
}]) | ||
|
||
.name; | ||
|
||
} else { | ||
ravenModule = angular.module('app.raven', []).name; | ||
} | ||
|
||
export default ravenModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class RavenService { | ||
constructor($rootScope, Session, Raven) { | ||
'ngInject'; | ||
this.$rootScope = $rootScope; | ||
this.Session = Session; | ||
this.Raven = Raven; | ||
} | ||
|
||
init() { | ||
this.$rootScope.$on('event:authentication:login:succeeded', this.handleLogin.bind(this)); | ||
this.$rootScope.$on('event:authentication:logout:succeeded', this.handleLogout.bind(this)); | ||
|
||
if (this.Session.getSessionDataEntry('userId')) { | ||
this.handleLogin(); | ||
} | ||
} | ||
|
||
handleLogin() { | ||
if (this.Session.getSessionDataEntry('userId')) { | ||
this.Raven.setUserContext({ | ||
id: this.Session.getSessionDataEntry('userId') | ||
}); | ||
} else { | ||
this.Raven.setUserContext({}); | ||
} | ||
} | ||
|
||
handleLogout() { | ||
this.Raven.setUserContext({}); | ||
} | ||
|
||
} | ||
|
||
export default RavenService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
RewriteEngine on | ||
RewriteCond %{REQUEST_FILENAME} !-f | ||
RewriteRule ^.*$ /index.html [PT,L] | ||
|
||
Header set X-XSS-Protection "1; mode=block" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import RavenService from 'app/common/raven/raven.service'; | ||
|
||
describe('Raven service', () => { | ||
let raven, $rootScope, Raven, Session; | ||
|
||
beforeEach(() => { | ||
$rootScope = { | ||
$emit: (ev) => {}, | ||
$on: (ev) => {} | ||
}; | ||
|
||
let mockedSessionData = { | ||
email: '[email protected]', | ||
name: 'Robbie', | ||
userId: 10 | ||
}; | ||
Session = { | ||
getSessionDataEntry: function (key) { | ||
return mockedSessionData[key]; | ||
}, | ||
setSessionDataEntry: function (key, value) { | ||
mockedSessionData[key] = value; | ||
} | ||
}; | ||
|
||
Raven = { | ||
setUserContext: jasmine.createSpy('setUserContext') | ||
}; | ||
|
||
global.RAVEN_DSN = 'http://abc123'; | ||
|
||
spyOn($rootScope, '$emit'); | ||
spyOn($rootScope, '$on'); | ||
|
||
raven = new RavenService($rootScope, Session, Raven); | ||
}); | ||
|
||
it('should listen to log in/out events', () => { | ||
raven.init(); | ||
|
||
expect($rootScope.$on).toHaveBeenCalledWith('event:authentication:login:succeeded', jasmine.any(Function)); | ||
expect($rootScope.$on).toHaveBeenCalledWith('event:authentication:logout:succeeded', jasmine.any(Function)); | ||
|
||
expect(Raven.setUserContext).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should set user at creation if logged in', () => { | ||
Session.setSessionDataEntry('userId', 10); | ||
raven.init(); | ||
|
||
expect(Raven.setUserContext).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not set user at creation if logged out', () => { | ||
Session.setSessionDataEntry('userId', false); | ||
raven.init(); | ||
|
||
|
||
expect(Raven.setUserContext).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should set user on login', () => { | ||
raven.init(); | ||
raven.handleLogin(); | ||
|
||
expect(Raven.setUserContext).toHaveBeenCalledWith({ | ||
id: 10 | ||
}); | ||
}); | ||
|
||
it('should clear user on logout', () => { | ||
raven.init(); | ||
raven.handleLogout(); | ||
|
||
expect(Raven.setUserContext).toHaveBeenCalledWith({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters