refstack should display error message returned from openstack openid.

Closes-Bug: #1507730

Change-Id: I396f68e62b0b1ce49d9bc83c9eaf9ab35d5d8718
This commit is contained in:
david liu 2015-10-28 13:18:53 +08:00 committed by Sergey Slipushenko
parent bf25d59edb
commit e35a0e3429
5 changed files with 35 additions and 12 deletions

View File

@ -70,7 +70,7 @@
controller: 'ProfileController as ctrl'
}).
state('authFailure', {
url: '/auth_failure/:message',
url: '/auth_failure',
templateUrl: '/components/home/home.html',
controller: 'AuthFailureController as ctrl'
}).

View File

@ -19,13 +19,15 @@
.module('refstackApp')
.controller('AuthFailureController', AuthFailureController);
AuthFailureController.$inject = ['$stateParams', '$state', 'raiseAlert'];
AuthFailureController.$inject = ['$location', '$state', 'raiseAlert'];
/**
* Refstack Auth Failure Controller
* This controller handles messages from Refstack API if user auth fails.
*/
function AuthFailureController($stateParams, $state, raiseAlert) {
raiseAlert('danger', 'Authentication Failure:', $stateParams.message);
function AuthFailureController($location, $state, raiseAlert) {
var ctrl = this;
ctrl.message = $location.search().message;
raiseAlert('danger', 'Authentication Failure:', ctrl.message);
$state.go('home');
}
})();

View File

@ -627,4 +627,21 @@ describe('Refstack controllers', function () {
expect(modalInstance.close).toHaveBeenCalledWith();
});
});
describe('AuthFailureController', function() {
var $location, ctrl;
beforeEach(inject(function ($controller, _$location_) {
$location = _$location_;
$location.url('/auth_failure?message=some_error_message');
ctrl = $controller('AuthFailureController', {});
}));
it('should set the authentication failure url based on error message',
function () {
expect($location.url()).toBe('/auth_failure?message=' +
'some_error_message');
expect(ctrl.message).toBe('some_error_message');
});
});
});

View File

@ -105,8 +105,12 @@ class AuthController(rest.RestController):
}
def _auth_failure(self, message):
pecan.redirect(parse.urljoin(CONF.ui_url,
'/#/auth_failure/%s') % message)
params = {
'message': message
}
url = parse.urljoin(CONF.ui_url,
'/#/auth_failure?' + parse.urlencode(params))
pecan.redirect(url)
@pecan.expose()
def signin(self):

View File

@ -454,7 +454,7 @@ class AuthControllerTestCase(BaseControllerTestCase):
self.assertRaises(webob.exc.HTTPRedirection,
self.controller.signin_return)
mock_redirect.assert_called_once_with(
'http://127.0.0.1/#/auth_failure/foo is not bar!!!')
'http://127.0.0.1/#/auth_failure?message=foo+is+not+bar%21%21%21')
self.assertNotIn(const.CSRF_TOKEN,
self.mock_request.environ['beaker.session'])
@ -468,7 +468,7 @@ class AuthControllerTestCase(BaseControllerTestCase):
self.assertRaises(webob.exc.HTTPRedirection,
self.controller.signin_return)
mock_redirect.assert_called_once_with(
'http://127.0.0.1/#/auth_failure/Authentication canceled.')
'http://127.0.0.1/#/auth_failure?message=Authentication+canceled.')
self.assertNotIn(const.CSRF_TOKEN,
self.mock_request.environ['beaker.session'])
@ -480,8 +480,8 @@ class AuthControllerTestCase(BaseControllerTestCase):
self.assertRaises(webob.exc.HTTPRedirection,
self.controller.signin_return)
mock_redirect.assert_called_once_with(
'http://127.0.0.1/#/auth_failure/'
'Authentication failed. Please try again.')
'http://127.0.0.1/#/auth_failure'
'?message=Authentication+failed.+Please+try+again.')
self.assertNotIn(const.CSRF_TOKEN,
self.mock_request.environ['beaker.session'])
@ -494,8 +494,8 @@ class AuthControllerTestCase(BaseControllerTestCase):
self.assertRaises(webob.exc.HTTPRedirection,
self.controller.signin_return)
mock_redirect.assert_called_once_with(
'http://127.0.0.1/#/auth_failure/'
'Authentication failed. Please try again.')
'http://127.0.0.1/#/auth_failure'
'?message=Authentication+failed.+Please+try+again.')
self.assertNotIn(const.CSRF_TOKEN,
self.mock_request.environ['beaker.session'])