Esempio n. 1
0
    def test_logout_invalid_method(self):

        request = Mock()
        request.META = {}
        request.method = 'POST'
        request.session.get.return_value = None
        with patch.multiple('wirecloud.fiware.views', wirecloud_logout=DEFAULT, ALLOWED_ORIGINS=()) as mocks:
            response = logout(request)
            self.assertFalse(mocks['wirecloud_logout'].called)
        self.assertEqual(response.status_code, 405)
        self.assertFalse(request.session.flush.called)
Esempio n. 2
0
    def test_logout_from_not_allowed_origin(self):

        request = Mock()
        request.META = {'HTTP_ORIGIN': 'http://invalid_domain:666'}
        request.method = 'GET'
        request.session.get.return_value = None
        with patch.multiple('wirecloud.fiware.views', wirecloud_logout=DEFAULT, ALLOWED_ORIGINS=()) as mocks:
            response = logout(request)
            self.assertFalse(mocks['wirecloud_logout'].called)
        self.assertEqual(response.status_code, 403)
        self.assertFalse(request.session.flush.called)
Esempio n. 3
0
    def test_logout_from_not_allowed_origin(self):

        request = Mock()
        request.META = {'HTTP_ORIGIN': 'http://invalid_domain:666'}
        request.method = 'GET'
        request.session.get.return_value = None
        with patch.multiple('wirecloud.fiware.views',
                            wirecloud_logout=DEFAULT,
                            ALLOWED_ORIGINS=()) as mocks:
            response = logout(request)
            self.assertFalse(mocks['wirecloud_logout'].called)
        self.assertEqual(response.status_code, 403)
        self.assertFalse(request.session.flush.called)
Esempio n. 4
0
    def test_logout_invalid_method(self):

        request = Mock()
        request.META = {}
        request.method = 'POST'
        request.session.get.return_value = None
        with patch.multiple('wirecloud.fiware.views',
                            wirecloud_logout=DEFAULT,
                            ALLOWED_ORIGINS=()) as mocks:
            response = logout(request)
            self.assertFalse(mocks['wirecloud_logout'].called)
        self.assertEqual(response.status_code, 405)
        self.assertFalse(request.session.flush.called)
Esempio n. 5
0
    def test_logout_from_allowed_origin(self):

        request = Mock()
        request.META = {'HTTP_ORIGIN': 'http://valid_domain'}
        request.method = 'GET'
        request.session.get.return_value = None
        with patch.multiple('wirecloud.fiware.views', wirecloud_logout=DEFAULT, ALLOWED_ORIGINS=('http://valid_domain',)) as mocks:
            mocks['wirecloud_logout'].return_value = HttpResponse(status=204)
            response = logout(request)
            mocks['wirecloud_logout'].assert_called_with(request, next_page=None)
        self.assertEqual(response.status_code, 204)
        self.assertEqual(response['Access-Control-Allow-Origin'], 'http://valid_domain')
        self.assertEqual(response['Access-Control-Allow-Credentials'], 'true')
        self.assertFalse(request.session.flush.called)
Esempio n. 6
0
    def test_logout_from_server_domain(self):

        request = Mock()
        request.META = {}
        request.method = 'GET'
        request.session.get.return_value = None
        with patch.multiple('wirecloud.fiware.views', wirecloud_logout=DEFAULT, ALLOWED_ORIGINS=()) as mocks:
            mocks['wirecloud_logout'].return_value = HttpResponse(status=204)
            response = logout(request)
            mocks['wirecloud_logout'].assert_called_with(request)
        self.assertEqual(response.status_code, 204)
        self.assertNotIn('Access-Control-Allow-Origin', response)
        self.assertNotIn('Access-Control-Allow-Credentials', response)
        self.assertFalse(request.session.flush.called)
Esempio n. 7
0
    def test_logout_from_server_domain(self):

        request = Mock()
        request.META = {}
        request.method = 'GET'
        request.session.get.return_value = None
        with patch.multiple('wirecloud.fiware.views',
                            wirecloud_logout=DEFAULT,
                            ALLOWED_ORIGINS=()) as mocks:
            mocks['wirecloud_logout'].return_value = HttpResponse(status=204)
            response = logout(request)
            mocks['wirecloud_logout'].assert_called_with(request)
        self.assertEqual(response.status_code, 204)
        self.assertNotIn('Access-Control-Allow-Origin', response)
        self.assertNotIn('Access-Control-Allow-Credentials', response)
        self.assertFalse(request.session.flush.called)
Esempio n. 8
0
    def test_logout_from_allowed_origin(self):

        request = Mock()
        request.META = {'HTTP_ORIGIN': 'http://valid_domain'}
        request.method = 'GET'
        request.session.get.return_value = None
        with patch.multiple(
                'wirecloud.fiware.views',
                wirecloud_logout=DEFAULT,
                ALLOWED_ORIGINS=('http://valid_domain', )) as mocks:
            mocks['wirecloud_logout'].return_value = HttpResponse(status=204)
            response = logout(request)
            mocks['wirecloud_logout'].assert_called_with(request,
                                                         next_page=None)
        self.assertEqual(response.status_code, 204)
        self.assertEqual(response['Access-Control-Allow-Origin'],
                         'http://valid_domain')
        self.assertEqual(response['Access-Control-Allow-Credentials'], 'true')
        self.assertFalse(request.session.flush.called)