forked from juice-shop/juice-shop
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a3832e
commit b9443b5
Showing
2 changed files
with
33 additions
and
52 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 |
---|---|---|
|
@@ -5,6 +5,9 @@ describe('controllers', function () { | |
beforeEach(inject(function ($injector) { | ||
$httpBackend = $injector.get('$httpBackend') | ||
$httpBackend.whenGET(/\/i18n\/.*\.json/).respond(200, {}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
})) | ||
|
||
afterEach(function () { | ||
|
@@ -23,49 +26,37 @@ describe('controllers', function () { | |
})) | ||
|
||
it('should be defined', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(controller).toBeDefined() | ||
})) | ||
|
||
it('should hold application version', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {version: 'x.y.z'}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
$httpBackend.expectGET('/rest/admin/application-version').respond(200, {version: 'x.y.z'}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(scope.version).toBe('vx.y.z') | ||
})) | ||
|
||
it('should show nothing on missing application version', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
$httpBackend.expectGET('/rest/admin/application-version').respond(200, {}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(scope.version).toBe('') | ||
})) | ||
|
||
it('should show nothing on error retrieving application version', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(500) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
$httpBackend.expectGET('/rest/admin/application-version').respond(500) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(scope.version).toBe('') | ||
})) | ||
|
||
it('should log errors directly to browser console', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(500, 'error') | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
$httpBackend.expectGET('/rest/admin/application-version').respond(500, 'error') | ||
|
||
console.log = jasmine.createSpy('log') | ||
|
||
|
@@ -74,50 +65,31 @@ describe('controllers', function () { | |
expect(console.log).toHaveBeenCalledWith('error') | ||
})) | ||
|
||
it('should be defined', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(controller).toBeDefined() | ||
})) | ||
|
||
it('should use default application name if not customized', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(scope.applicationName).toBe('OWASP Juice Shop') | ||
})) | ||
|
||
it('should use custom application name URL if configured', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.expectGET('/rest/admin/application-configuration').respond(200, {config: {application: {name: 'name'}}}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(scope.applicationName).toBe('name') | ||
})) | ||
|
||
it('should set user email if user authenticated', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.expectGET('/rest/admin/application-configuration').respond(200, {config: {application: {name: 'name'}}}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {email: '[email protected]'}}) | ||
$httpBackend.expectGET('/rest/user/whoami').respond(200, {user: {email: '[email protected]'}}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(scope.userEmail).toBe('[email protected]') | ||
})) | ||
|
||
it('should log errors directly to browser console when getting user failed', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {config: {application: {name: 'name'}}}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(500, 'error-user') | ||
$httpBackend.expectGET('/rest/user/whoami').respond(500, 'error-user') | ||
|
||
console.log = jasmine.createSpy('log') | ||
|
||
|
@@ -127,29 +99,21 @@ describe('controllers', function () { | |
})) | ||
|
||
it('should show GitHub ribbon by default', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.whenGET('/rest/admin/application-configuration').respond(200, {config: {}}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(scope.showGitHubRibbon).toBe(true) | ||
})) | ||
|
||
it('should hide GitHub ribbon if configured as such', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.expectGET('/rest/admin/application-configuration').respond(200, {config: {application: {showGitHubRibbon: false}}}) | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
|
||
$httpBackend.flush() | ||
|
||
expect(scope.showGitHubRibbon).toBe(false) | ||
})) | ||
|
||
it('should log error while getting application configuration from backend API directly to browser console', inject(function () { | ||
$httpBackend.whenGET('/rest/admin/application-version').respond(200, {}) | ||
$httpBackend.expectGET('/rest/admin/application-configuration').respond(500, 'error') | ||
$httpBackend.whenGET('/rest/user/whoami').respond(200, {user: {}}) | ||
|
||
console.log = jasmine.createSpy('log') | ||
|
||
|
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