Skip to content

Commit

Permalink
Release v0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
aarranz committed Dec 16, 2019
1 parent 277178a commit 193c114
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
23 changes: 21 additions & 2 deletions wirecloud/keycloak/tests/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def test_get_platform_context_definitions(self):
},
}, plugin.get_platform_context_definitions())

def test_get_platform_context_current_values(self):
def test_get_platform_context_current_values_django1(self):
user_mock = MagicMock()
user_mock.is_authenticated.return_value = True
social_mock = MagicMock()
Expand All @@ -222,9 +222,28 @@ def test_get_platform_context_current_values(self):
user_mock.social_auth.filter.assert_called_once_with(provider='keycloak')
social_mock.exists.assert_called_once_with()

def test_get_platform_context_current_values(self):
user_mock = MagicMock()
user_mock.is_authenticated = True
social_mock = MagicMock()
social_mock.exists.return_value = True
user_mock.social_auth.filter.return_value = social_mock

import wirecloud.keycloak.plugins
reload(wirecloud.keycloak.plugins)

wirecloud.keycloak.plugins.IDM_SUPPORT_ENABLED = True
plugin = wirecloud.keycloak.plugins.KeycloakPlugin()

self.assertEqual({
'fiware_token_available': True
}, plugin.get_platform_context_current_values(user_mock))
user_mock.social_auth.filter.assert_called_once_with(provider='keycloak')
social_mock.exists.assert_called_once_with()

def test_get_platform_context_current_values_not_enabled(self):
user_mock = MagicMock()
user_mock.is_authenticated.return_value = True
user_mock.is_authenticated = True
social_mock = MagicMock()
social_mock.exists.return_value = True
user_mock.social_auth.filter.return_value = social_mock
Expand Down
25 changes: 22 additions & 3 deletions wirecloud/keycloak/tests/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_oauth_discovery(self):

@patch('django.conf.settings', new=MagicMock(FIWARE_PORTALS=()))
@patch('django.views.decorators.http.require_GET', new=get_decorator)
def test_login(self):
def test_login_django1(self):
from wirecloud.keycloak import views
reload(views)

Expand All @@ -86,6 +86,26 @@ def test_login(self):
request.GET.get.assert_called_once_with('field', '/')
views.HttpResponseRedirect.assert_called_once_with('/home')

@patch('django.conf.settings', new=MagicMock(FIWARE_PORTALS=()))
@patch('django.views.decorators.http.require_GET', new=get_decorator)
def test_login(self):
from wirecloud.keycloak import views
reload(views)

response_mock = MagicMock()
views.HttpResponseRedirect = MagicMock(return_value=response_mock)
views.REDIRECT_FIELD_NAME = 'field'

request = MagicMock()
request.user.is_authenticated = True
request.GET.get.return_value = '/home'

response = views.login(request)

self.assertEqual(response_mock, response)
request.GET.get.assert_called_once_with('field', '/')
views.HttpResponseRedirect.assert_called_once_with('/home')

@patch('django.conf.settings', new=MagicMock(FIWARE_PORTALS=()))
@patch('django.views.decorators.http.require_GET', new=get_decorator)
def test_login_not_authenticated(self):
Expand All @@ -96,14 +116,13 @@ def test_login_not_authenticated(self):
views.HttpResponseRedirect = MagicMock(return_value=response_mock)

request = MagicMock()
request.user.is_authenticated.return_value = False
request.user.is_authenticated = False
views.reverse = MagicMock(return_value='/home')
request.GET.urlencode.return_value = 'setting=test'

response = views.login(request)

self.assertEqual(response_mock, response)
request.user.is_authenticated.assert_called_once_with()
request.GET.urlencode.assert_called_once_with()
views.reverse.assert_called_once_with('social:begin', kwargs={'backend': 'keycloak'})
views.HttpResponseRedirect.assert_called_once_with('/home?setting=test')
Expand Down
2 changes: 1 addition & 1 deletion wirecloud/keycloak/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def oauth_discovery(request):

@require_GET
def login(request):
if request.user.is_authenticated():
if callable(request.user.is_authenticated) and request.user.is_authenticated() or request.user.is_authenticated is True:
url = request.GET.get(REDIRECT_FIELD_NAME, '/')
else:
url = reverse('social:begin', kwargs={'backend': 'keycloak'}) + '?' + request.GET.urlencode()
Expand Down

0 comments on commit 193c114

Please sign in to comment.