Exemple #1
0
    def test_logout_not_authenticated(self):
        from wirecloud.keycloak import views
        reload(views)

        views.wirecloud_logout = MagicMock()

        request = MagicMock(META=(), user=MagicMock(is_authenticated=False))
        response = views.logout(request)

        views.wirecloud_logout.assert_called_once_with(request)
        self.assertEqual(views.wirecloud_logout(), response)
Exemple #2
0
    def test_logout(self):
        from wirecloud.keycloak import views
        reload(views)

        views.wirecloud_logout = MagicMock()

        request = MagicMock()
        request.META = ()
        response = views.logout(request)

        views.wirecloud_logout.assert_called_once_with(request)
        self.assertEqual(views.wirecloud_logout(), response)
Exemple #3
0
    def test_logout_unauthorized(self):
        from wirecloud.keycloak import views
        reload(views)

        response_mock = MagicMock()
        views.build_error_response = MagicMock(return_value=response_mock)

        request = MagicMock()
        request.META = {'HTTP_ORIGIN': 'http://keycloak.com'}
        response = views.logout(request)

        self.assertEqual(response_mock, response)
        views.build_error_response.assert_called_once_with(request, 403, '')
Exemple #4
0
    def test_logout(self):
        from wirecloud.keycloak import views
        reload(views)

        views.build_backend = MagicMock()
        views.build_backend().end_session_url.return_value = 'https://accounts.example.com/logout'
        views.wirecloud_logout = MagicMock()
        views.get_absolute_reverse_url = MagicMock(return_value='https://example.com/')
        views.settings.LOGOUT_REDIRECT_URL = '/'
        views.quote = MagicMock(return_value='https:%2F%2Fexample.com%2F')

        request = MagicMock(META=())
        response = views.logout(request)

        views.wirecloud_logout.assert_called_once_with(request, next_page='https://accounts.example.com/logout?redirect_uri=https:%2F%2Fexample.com%2F')
        self.assertEqual(views.wirecloud_logout(), response)
Exemple #5
0
    def test_logout_external_domain(self):
        from wirecloud.keycloak import views
        reload(views)

        views.wirecloud_logout = MagicMock(return_value={})

        request = MagicMock()
        request.META = {'HTTP_ORIGIN': 'http://keycloak.com'}
        response = views.logout(request)

        self.assertEqual(
            {
                'Access-Control-Allow-Origin': 'http://keycloak.com',
                'Access-Control-Allow-Credentials': 'true'
            }, response)

        views.wirecloud_logout.assert_called_once_with(request, next_page=None)