NIFIREG-295 - change canActivate guards to use promises
This closes #211.
Signed-off-by: Bryan Bende <bbende@apache.org>
diff --git a/nifi-registry-core/nifi-registry-web-ui/src/main/webapp/services/nf-registry.auth-guard.service.js b/nifi-registry-core/nifi-registry-web-ui/src/main/webapp/services/nf-registry.auth-guard.service.js
index ca3c1d0..e04bf4e 100644
--- a/nifi-registry-core/nifi-registry-web-ui/src/main/webapp/services/nf-registry.auth-guard.service.js
+++ b/nifi-registry-core/nifi-registry-web-ui/src/main/webapp/services/nf-registry.auth-guard.service.js
@@ -54,72 +54,85 @@
checkLogin: function (url) {
var self = this;
- if (this.nfRegistryService.currentUser.resourcePermissions.tenants.canRead) { return true; }
+ return new Promise((resolve) => {
+ if (this.nfRegistryService.currentUser.resourcePermissions.tenants.canRead) {
+ resolve(true);
+ return true;
+ }
- // Store the attempted URL for redirecting
- this.nfRegistryService.redirectUrl = url;
+ // Store the attempted URL for redirecting
+ this.nfRegistryService.redirectUrl = url;
- // attempt kerberos authentication
- this.nfRegistryApi.ticketExchange().subscribe(function (jwt) {
- self.nfRegistryApi.loadCurrentUser().subscribe(function (currentUser) {
- // there is no anonymous access and we don't know this user - open the login page which handles login/registration/etc
- if (currentUser.error) {
- if (currentUser.error.status === 401) {
- self.nfStorage.removeItem('jwt');
- self.router.navigateByUrl('login');
- }
- } else {
- self.nfRegistryService.currentUser = currentUser;
- if (currentUser.anonymous === false) {
- // render the logout button if there is a token locally
- if (self.nfStorage.getItem('jwt') !== null) {
- self.nfRegistryService.currentUser.canLogout = true;
+ // attempt kerberos authentication
+ this.nfRegistryApi.ticketExchange().subscribe(function (jwt) {
+ self.nfRegistryApi.loadCurrentUser().subscribe(function (currentUser) {
+ // there is no anonymous access and we don't know this user - open the login page which handles login/registration/etc
+ if (currentUser.error) {
+ if (currentUser.error.status === 401) {
+ self.nfStorage.removeItem('jwt');
+ self.router.navigateByUrl('login');
+ resolve(false);
}
-
- // redirect to explorer perspective if not admin
- if (!currentUser.resourcePermissions.anyTopLevelResource.canRead) {
- self.dialogService.openConfirm({
- title: 'Access denied',
- message: 'Please contact your system administrator.',
- acceptButton: 'Ok',
- acceptButtonColor: 'fds-warn'
- });
- self.router.navigateByUrl('explorer');
- } else if (currentUser.resourcePermissions.tenants.canRead) {
- self.router.navigateByUrl(url);
- } else {
- self.dialogService.openConfirm({
- title: 'Access denied',
- message: 'Please contact your system administrator.',
- acceptButton: 'Ok',
- acceptButtonColor: 'fds-warn'
- });
- self.router.navigateByUrl('explorer');
- }
- } else if (location.protocol === 'http:') {
- // user is anonymous and we are NOT secure, redirect to workflow perspective
- self.dialogService.openConfirm({
- title: 'Not Applicable',
- message: 'User administration is not configured for this registry.',
- acceptButton: 'Ok',
- acceptButtonColor: 'fds-warn'
- });
- self.router.navigateByUrl('administration/workflow');
} else {
- // user is anonymous and we are secure so don't allow the url, navigate to the main page
- self.dialogService.openConfirm({
- title: 'Access denied',
- message: 'Please contact your system administrator.',
- acceptButton: 'Ok',
- acceptButtonColor: 'fds-warn'
- });
- self.router.navigateByUrl('explorer');
+ self.nfRegistryService.currentUser = currentUser;
+ if (currentUser.anonymous === false) {
+ // render the logout button if there is a token locally
+ if (self.nfStorage.getItem('jwt') !== null) {
+ self.nfRegistryService.currentUser.canLogout = true;
+ }
+
+ // redirect to explorer perspective if not admin
+ if (!currentUser.resourcePermissions.anyTopLevelResource.canRead) {
+ self.dialogService.openConfirm({
+ title: 'Access denied',
+ message: 'Please contact your system administrator.',
+ acceptButton: 'Ok',
+ acceptButtonColor: 'fds-warn'
+ });
+ self.router.navigateByUrl('explorer');
+ resolve(false);
+ } else if (currentUser.resourcePermissions.tenants.canRead) {
+ resolve(true);
+ } else {
+ self.dialogService.openConfirm({
+ title: 'Access denied',
+ message: 'Please contact your system administrator.',
+ acceptButton: 'Ok',
+ acceptButtonColor: 'fds-warn'
+ });
+ self.router.navigateByUrl('explorer');
+ resolve(false);
+ }
+ } else if (location.protocol === 'http:') {
+ // user is anonymous and we are NOT secure, redirect to workflow perspective
+ self.dialogService.openConfirm({
+ title: 'Not Applicable',
+ message: 'User administration is not configured for this registry.',
+ acceptButton: 'Ok',
+ acceptButtonColor: 'fds-warn'
+ });
+ self.router.navigateByUrl('administration/workflow');
+ resolve(false);
+ } else {
+ if (self.nfRegistryService.currentUser.resourcePermissions.tenants.canRead) {
+ resolve(true);
+ return true;
+ }
+
+ // user is anonymous and we are secure so don't allow the url, navigate to the main page
+ self.dialogService.openConfirm({
+ title: 'Access denied',
+ message: 'Please contact your system administrator.',
+ acceptButton: 'Ok',
+ acceptButtonColor: 'fds-warn'
+ });
+ self.router.navigateByUrl('explorer');
+ resolve(false);
+ }
}
- }
+ });
});
});
-
- return false;
}
};
@@ -164,30 +177,65 @@
checkLogin: function (url) {
var self = this;
- if (this.nfRegistryService.currentUser.resourcePermissions.buckets.canRead) { return true; }
+ return new Promise((resolve) => {
+ if (this.nfRegistryService.currentUser.resourcePermissions.buckets.canRead) {
+ resolve(true);
+ return;
+ }
- // Store the attempted URL for redirecting
- this.nfRegistryService.redirectUrl = url;
+ // Store the attempted URL for redirecting
+ this.nfRegistryService.redirectUrl = url;
- // attempt kerberos authentication
- this.nfRegistryApi.ticketExchange().subscribe(function (jwt) {
- self.nfRegistryApi.loadCurrentUser().subscribe(function (currentUser) {
- // there is no anonymous access and we don't know this user - open the login page which handles login/registration/etc
- if (currentUser.error) {
- if (currentUser.error.status === 401) {
- self.nfStorage.removeItem('jwt');
- self.router.navigateByUrl('login');
- }
- } else {
- self.nfRegistryService.currentUser = currentUser;
- if (currentUser.anonymous === false) {
- // render the logout button if there is a token locally
- if (self.nfStorage.getItem('jwt') !== null) {
- self.nfRegistryService.currentUser.canLogout = true;
+ // attempt kerberos authentication
+ this.nfRegistryApi.ticketExchange().subscribe(function (jwt) {
+ self.nfRegistryApi.loadCurrentUser().subscribe(function (currentUser) {
+ // there is no anonymous access and we don't know this user - open the login page which handles login/registration/etc
+ if (currentUser.error) {
+ if (currentUser.error.status === 401) {
+ self.nfStorage.removeItem('jwt');
+ self.router.navigateByUrl('login');
+ resolve(false);
}
+ } else {
+ self.nfRegistryService.currentUser = currentUser;
+ if (currentUser.anonymous === false) {
+ // render the logout button if there is a token locally
+ if (self.nfStorage.getItem('jwt') !== null) {
+ self.nfRegistryService.currentUser.canLogout = true;
+ }
- // redirect to explorer perspective if not admin
- if (!currentUser.resourcePermissions.anyTopLevelResource.canRead) {
+ // redirect to explorer perspective if not admin
+ if (!currentUser.resourcePermissions.anyTopLevelResource.canRead) {
+ self.dialogService.openConfirm({
+ title: 'Access denied',
+ message: 'Please contact your system administrator.',
+ acceptButton: 'Ok',
+ acceptButtonColor: 'fds-warn'
+ });
+ self.router.navigateByUrl('explorer');
+ resolve(false);
+ } else if (currentUser.resourcePermissions.buckets.canRead) {
+ resolve(true);
+ } else {
+ self.dialogService.openConfirm({
+ title: 'Access denied',
+ message: 'Please contact your system administrator.',
+ acceptButton: 'Ok',
+ acceptButtonColor: 'fds-warn'
+ });
+ self.router.navigateByUrl('explorer');
+ resolve(false);
+ }
+ } else if (location.protocol === 'http:') {
+ // user is anonymous and we are NOT secure so allow the url
+ resolve(true);
+ } else {
+ if (self.nfRegistryService.currentUser.resourcePermissions.buckets.canRead) {
+ resolve(true);
+ return;
+ }
+
+ // user is anonymous and we are secure so don't allow the url, navigate to the main page
self.dialogService.openConfirm({
title: 'Access denied',
message: 'Please contact your system administrator.',
@@ -195,35 +243,12 @@
acceptButtonColor: 'fds-warn'
});
self.router.navigateByUrl('explorer');
- } else if (currentUser.resourcePermissions.buckets.canRead) {
- self.router.navigateByUrl(url);
- } else {
- self.dialogService.openConfirm({
- title: 'Access denied',
- message: 'Please contact your system administrator.',
- acceptButton: 'Ok',
- acceptButtonColor: 'fds-warn'
- });
- self.router.navigateByUrl('administration/users');
+ resolve(false);
}
- } else if (location.protocol === 'http:') {
- // user is anonymous and we are NOT secure so allow the url
- self.router.navigateByUrl(url);
- } else {
- // user is anonymous and we are secure so don't allow the url, navigate to the main page
- self.dialogService.openConfirm({
- title: 'Access denied',
- message: 'Please contact your system administrator.',
- acceptButton: 'Ok',
- acceptButtonColor: 'fds-warn'
- });
- self.router.navigateByUrl('explorer');
}
- }
+ });
});
});
-
- return false;
}
};
@@ -266,28 +291,33 @@
checkLogin: function (url) {
var self = this;
- if (this.nfRegistryService.currentUser.anonymous) { return true; }
- // attempt kerberos authentication
- this.nfRegistryApi.ticketExchange().subscribe(function (jwt) {
- self.nfRegistryApi.loadCurrentUser().subscribe(function (currentUser) {
- self.nfRegistryService.currentUser = currentUser;
- if (currentUser.anonymous === false) {
- // render the logout button if there is a token locally
- if (self.nfStorage.getItem('jwt') !== null) {
- self.nfRegistryService.currentUser.canLogout = true;
+ return new Promise((resolve) => {
+ if (this.nfRegistryService.currentUser.anonymous) {
+ resolve(true);
+ return;
+ }
+ // attempt kerberos authentication
+ this.nfRegistryApi.ticketExchange().subscribe(function (jwt) {
+ self.nfRegistryApi.loadCurrentUser().subscribe(function (currentUser) {
+ self.nfRegistryService.currentUser = currentUser;
+ if (currentUser.anonymous === false) {
+ // render the logout button if there is a token locally
+ if (self.nfStorage.getItem('jwt') !== null) {
+ self.nfRegistryService.currentUser.canLogout = true;
+ }
+ self.nfRegistryService.currentUser.canActivateResourcesAuthGuard = true;
+ resolve(false);
+ self.router.navigateByUrl(self.nfRegistryService.redirectUrl);
+ } else if (self.nfRegistryService.currentUser.anonymous && !self.nfRegistryService.currentUser.loginSupported) {
+ resolve(false);
+ self.router.navigateByUrl('/nifi-registry');
+ } else {
+ self.nfRegistryService.currentUser.anonymous = true;
+ resolve(true);
}
- self.nfRegistryService.currentUser.canActivateResourcesAuthGuard = true;
- self.router.navigateByUrl(self.nfRegistryService.redirectUrl);
- } else if (self.nfRegistryService.currentUser.anonymous && !self.nfRegistryService.currentUser.loginSupported) {
- self.router.navigateByUrl('/nifi-registry');
- } else {
- self.nfRegistryService.currentUser.anonymous = true;
- self.router.navigateByUrl(url);
- }
+ });
});
});
-
- return false;
}
};
@@ -323,49 +353,53 @@
*/
canActivate: function (route, state) {
var url = state.url;
-
return this.checkLogin(url);
},
checkLogin: function (url) {
var self = this;
- if (this.nfRegistryService.currentUser.canActivateResourcesAuthGuard === true) { return true; }
+ return new Promise((resolve) => {
+ if (this.nfRegistryService.currentUser.canActivateResourcesAuthGuard === true) {
+ resolve(true);
+ return;
+ }
- // Store the attempted URL for redirecting
- this.nfRegistryService.redirectUrl = url;
+ // Store the attempted URL for redirecting
+ this.nfRegistryService.redirectUrl = url;
- // attempt kerberos authentication
- this.nfRegistryApi.ticketExchange().subscribe(function (jwt) {
- self.nfRegistryApi.loadCurrentUser().subscribe(function (currentUser) {
- // there is no anonymous access and we don't know this user - open the login page which handles login/registration/etc
- if (currentUser.error) {
- if (currentUser.error.status === 401) {
- self.nfStorage.removeItem('jwt');
- self.router.navigateByUrl('login');
- }
- } else {
- self.nfRegistryService.currentUser = currentUser;
- if (!currentUser || currentUser.anonymous === false) {
- if (self.nfStorage.hasItem('jwt')) {
- self.nfRegistryService.currentUser.canLogout = true;
- self.nfRegistryService.currentUser.canActivateResourcesAuthGuard = true;
- self.router.navigateByUrl(url);
- } else {
+ // attempt kerberos authentication
+ this.nfRegistryApi.ticketExchange().subscribe(function (jwt) {
+ self.nfRegistryApi.loadCurrentUser().subscribe(function (currentUser) {
+ // there is no anonymous access and we don't know this user - open the login page which handles login/registration/etc
+ if (currentUser.error) {
+ if (currentUser.error.status === 401) {
+ self.nfStorage.removeItem('jwt');
self.router.navigateByUrl('login');
+ resolve(false);
}
- } else if (currentUser.anonymous === true) {
- // render the logout button if there is a token locally
- if (self.nfStorage.getItem('jwt') !== null) {
- self.nfRegistryService.currentUser.canLogout = true;
+ } else {
+ self.nfRegistryService.currentUser = currentUser;
+ if (!currentUser || currentUser.anonymous === false) {
+ if (self.nfStorage.hasItem('jwt')) {
+ self.nfRegistryService.currentUser.canLogout = true;
+ self.nfRegistryService.currentUser.canActivateResourcesAuthGuard = true;
+ resolve(true);
+ } else {
+ self.router.navigateByUrl('login');
+ resolve(false);
+ }
+ } else if (currentUser.anonymous === true) {
+ // render the logout button if there is a token locally
+ if (self.nfStorage.getItem('jwt') !== null) {
+ self.nfRegistryService.currentUser.canLogout = true;
+ }
+ self.nfRegistryService.currentUser.canActivateResourcesAuthGuard = true;
+ resolve(true);
}
- self.nfRegistryService.currentUser.canActivateResourcesAuthGuard = true;
- self.router.navigateByUrl(url);
}
- }
+ });
});
});
-
- return false;
}
};
diff --git a/nifi-registry-core/nifi-registry-web-ui/src/main/webapp/services/nf-registry.auth-guard.service.spec.js b/nifi-registry-core/nifi-registry-web-ui/src/main/webapp/services/nf-registry.auth-guard.service.spec.js
index a656518..94fbf7f 100644
--- a/nifi-registry-core/nifi-registry-web-ui/src/main/webapp/services/nf-registry.auth-guard.service.spec.js
+++ b/nifi-registry-core/nifi-registry-web-ui/src/main/webapp/services/nf-registry.auth-guard.service.spec.js
@@ -58,7 +58,7 @@
spyOn(dialogService, 'openConfirm');
});
- it('should navigate to test url (registry security not configured) ', function () {
+ it('should navigate to test url (registry security not configured) ', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: true
@@ -69,17 +69,18 @@
nfRegistryResourcesAuthGuard = new NfRegistryResourcesAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router);
// The function to test
- nfRegistryResourcesAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.currentUser.canLogout).toBe(true);
- expect(nfRegistryService.currentUser.canActivateResourcesAuthGuard).toBe(true);
- expect(nfRegistryService.currentUser.anonymous).toBe(true);
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('test');
+ nfRegistryResourcesAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(nfRegistryService.currentUser.canLogout).toBe(true);
+ expect(nfRegistryService.currentUser.canActivateResourcesAuthGuard).toBe(true);
+ expect(nfRegistryService.currentUser.anonymous).toBe(true);
+ expect(canActivate).toBe(true);
+ done();
+ });
});
- it('should navigate to test url (registry security configured and we know who you are) ', function () {
+ it('should navigate to test url (registry security configured and we know who you are) ', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false
@@ -90,16 +91,17 @@
nfRegistryResourcesAuthGuard = new NfRegistryResourcesAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router);
// The function to test
- nfRegistryResourcesAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.currentUser.canLogout).toBe(true);
- expect(nfRegistryService.currentUser.canActivateResourcesAuthGuard).toBe(true);
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('test');
+ nfRegistryResourcesAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(nfRegistryService.currentUser.canLogout).toBe(true);
+ expect(nfRegistryService.currentUser.canActivateResourcesAuthGuard).toBe(true);
+ expect(canActivate).toBe(true);
+ done();
+ });
});
- it('should navigate to login', function () {
+ it('should navigate to login', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false
@@ -108,31 +110,37 @@
nfRegistryResourcesAuthGuard = new NfRegistryResourcesAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router);
// The function to test
- nfRegistryResourcesAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('login');
+ nfRegistryResourcesAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('login');
+ done();
+ });
});
- it('should navigate to login (error loading current user)', function () {
+ it('should navigate to login (error loading current user)', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
error: {
status: 401
}
}));
- spyOn(nfStorage, 'removeItem');
+ spyOn(nfStorage, 'removeItem').and.callFake(() => {});
nfRegistryResourcesAuthGuard = new NfRegistryResourcesAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryResourcesAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfStorage.removeItem).toHaveBeenCalled();
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('login');
+ nfRegistryResourcesAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfStorage.removeItem).toHaveBeenCalled();
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('login');
+ done();
+ });
});
});
@@ -169,7 +177,7 @@
spyOn(dialogService, 'openConfirm');
});
- it('should navigate to base nifi-registry url', function () {
+ it('should navigate to base nifi-registry url', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: true
@@ -177,15 +185,18 @@
nfRegistryLoginAuthGuard = new NfRegistryLoginAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router);
// The function to test
- nfRegistryLoginAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.currentUser.anonymous).toBe(true);
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('/nifi-registry');
+ nfRegistryLoginAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.currentUser.anonymous).toBe(true);
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('/nifi-registry');
+ done();
+ });
});
- it('should navigate to test url', function () {
+ it('should navigate to test url', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false
@@ -193,12 +204,15 @@
nfRegistryLoginAuthGuard = new NfRegistryLoginAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router);
// The function to test
- nfRegistryLoginAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.currentUser.canActivateResourcesAuthGuard).toBe(true);
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('explorer/grid-list');
+ nfRegistryLoginAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.currentUser.canActivateResourcesAuthGuard).toBe(true);
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('explorer/grid-list');
+ done();
+ });
});
});
@@ -235,7 +249,7 @@
spyOn(dialogService, 'openConfirm');
});
- it('should navigate to login', function () {
+ it('should navigate to login', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
error: {
@@ -245,15 +259,18 @@
nfRegistryUsersAdministrationAuthGuard = new NfRegistryUsersAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('login');
+ nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.redirectUrl).toBe('test');
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('login');
+ done();
+ });
});
- it('should deny access (registry security not configured) and navigate to administration workflow perspective', function () {
+ it('should deny access (registry security not configured) and navigate to administration workflow perspective', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: true
@@ -261,20 +278,23 @@
nfRegistryUsersAdministrationAuthGuard = new NfRegistryUsersAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var dialogServiceCall = dialogService.openConfirm.calls.first();
- expect(dialogServiceCall.args[0].title).toBe('Not Applicable');
- expect(dialogServiceCall.args[0].message).toBe('User administration is not configured for this registry.');
- expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
- expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('administration/workflow');
+ nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.redirectUrl).toBe('test');
+ var dialogServiceCall = dialogService.openConfirm.calls.first();
+ expect(dialogServiceCall.args[0].title).toBe('Not Applicable');
+ expect(dialogServiceCall.args[0].message).toBe('User administration is not configured for this registry.');
+ expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
+ expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('administration/workflow');
+ done();
+ });
});
- it('should deny access (non-admin) and navigate to explorer perspective', function () {
+ it('should deny access (non-admin) and navigate to explorer perspective', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false,
@@ -309,20 +329,23 @@
nfRegistryUsersAdministrationAuthGuard = new NfRegistryUsersAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var dialogServiceCall = dialogService.openConfirm.calls.first();
- expect(dialogServiceCall.args[0].title).toBe('Access denied');
- expect(dialogServiceCall.args[0].message).toBe('Please contact your system administrator.');
- expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
- expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('explorer');
+ nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.redirectUrl).toBe('test');
+ var dialogServiceCall = dialogService.openConfirm.calls.first();
+ expect(dialogServiceCall.args[0].title).toBe('Access denied');
+ expect(dialogServiceCall.args[0].message).toBe('Please contact your system administrator.');
+ expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
+ expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('explorer');
+ done();
+ });
});
- it('should deny access (no tenants permissions) and navigate to explorer perspective', function () {
+ it('should deny access (no tenants permissions) and navigate to explorer perspective', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false,
@@ -357,20 +380,23 @@
nfRegistryUsersAdministrationAuthGuard = new NfRegistryUsersAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var dialogServiceCall = dialogService.openConfirm.calls.first();
- expect(dialogServiceCall.args[0].title).toBe('Access denied');
- expect(dialogServiceCall.args[0].message).toBe('Please contact your system administrator.');
- expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
- expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('explorer');
+ nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.redirectUrl).toBe('test');
+ var dialogServiceCall = dialogService.openConfirm.calls.first();
+ expect(dialogServiceCall.args[0].title).toBe('Access denied');
+ expect(dialogServiceCall.args[0].message).toBe('Please contact your system administrator.');
+ expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
+ expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('explorer');
+ done();
+ });
});
- it('should deny access (no tenants permissions) and navigate to test url', function () {
+ it('should deny access (no tenants permissions) and navigate to explorer url', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false,
@@ -386,7 +412,7 @@
canDelete: false
},
tenants: {
- canRead: true,
+ canRead: false,
canWrite: false,
canDelete: false
},
@@ -405,12 +431,15 @@
nfRegistryUsersAdministrationAuthGuard = new NfRegistryUsersAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('test');
+ nfRegistryUsersAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.redirectUrl).toBe('test');
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('explorer');
+ done();
+ });
});
});
@@ -447,7 +476,7 @@
spyOn(dialogService, 'openConfirm');
});
- it('should navigate to login', function () {
+ it('should navigate to login', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
error: {
@@ -457,15 +486,18 @@
nfRegistryWorkflowsAdministrationAuthGuard = new NfRegistryWorkflowsAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('login');
+ nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.redirectUrl).toBe('test');
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('login');
+ done();
+ });
});
- it('should (registry security not configured) navigate to test url', function () {
+ it('should (registry security not configured) navigate to test url', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: true
@@ -473,15 +505,15 @@
nfRegistryWorkflowsAdministrationAuthGuard = new NfRegistryWorkflowsAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('test');
+ nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(true);
+ done();
+ });
});
- it('should deny access (non-admin) and navigate to explorer perspective', function () {
+ it('should deny access (non-admin) and navigate to explorer perspective', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false,
@@ -516,20 +548,23 @@
nfRegistryWorkflowsAdministrationAuthGuard = new NfRegistryWorkflowsAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var dialogServiceCall = dialogService.openConfirm.calls.first();
- expect(dialogServiceCall.args[0].title).toBe('Access denied');
- expect(dialogServiceCall.args[0].message).toBe('Please contact your system administrator.');
- expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
- expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('explorer');
+ nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.redirectUrl).toBe('test');
+ var dialogServiceCall = dialogService.openConfirm.calls.first();
+ expect(dialogServiceCall.args[0].title).toBe('Access denied');
+ expect(dialogServiceCall.args[0].message).toBe('Please contact your system administrator.');
+ expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
+ expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('explorer');
+ done();
+ });
});
- it('should deny access (no buckets permissions) and navigate to users administration perspective', function () {
+ it('should deny access (no buckets permissions) and navigate to users administration perspective', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false,
@@ -564,20 +599,23 @@
nfRegistryWorkflowsAdministrationAuthGuard = new NfRegistryWorkflowsAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var dialogServiceCall = dialogService.openConfirm.calls.first();
- expect(dialogServiceCall.args[0].title).toBe('Access denied');
- expect(dialogServiceCall.args[0].message).toBe('Please contact your system administrator.');
- expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
- expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('administration/users');
+ nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(false);
+ expect(nfRegistryService.redirectUrl).toBe('test');
+ var dialogServiceCall = dialogService.openConfirm.calls.first();
+ expect(dialogServiceCall.args[0].title).toBe('Access denied');
+ expect(dialogServiceCall.args[0].message).toBe('Please contact your system administrator.');
+ expect(dialogServiceCall.args[0].acceptButton).toBe('Ok');
+ expect(dialogServiceCall.args[0].acceptButtonColor).toBe('fds-warn');
+ var navigateByUrlCall = router.navigateByUrl.calls.first();
+ expect(navigateByUrlCall.args[0]).toBe('explorer');
+ done();
+ });
});
- it('should deny access (no tenants permissions) and navigate to test url', function () {
+ it('should (no tenants permissions) navigate to test url', function (done) {
spyOn(nfRegistryApi, 'loadCurrentUser').and.callFake(function () {
}).and.returnValue(of({
anonymous: false,
@@ -612,11 +650,11 @@
nfRegistryWorkflowsAdministrationAuthGuard = new NfRegistryWorkflowsAdministrationAuthGuard(nfRegistryService, nfRegistryApi, nfStorage, router, dialogService);
// The function to test
- nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'});
-
- //assertions
- expect(nfRegistryService.redirectUrl).toBe('test');
- var navigateByUrlCall = router.navigateByUrl.calls.first();
- expect(navigateByUrlCall.args[0]).toBe('test');
+ nfRegistryWorkflowsAdministrationAuthGuard.canActivate({}, {url: 'test'})
+ .then((canActivate) => {
+ //assertions
+ expect(canActivate).toBe(true);
+ done();
+ });
});
});