diff --git a/vitrage/tests/functional/api/v1/test_auth.py b/vitrage/tests/functional/api/v1/test_auth.py index 0461fb559..0200e3daf 100644 --- a/vitrage/tests/functional/api/v1/test_auth.py +++ b/vitrage/tests/functional/api/v1/test_auth.py @@ -1,4 +1,4 @@ -# Copyright 2016 - Nokia Corporation +# Copyright 2017 - Nokia Corporation # Copyright 2014 OpenStack Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,8 +15,32 @@ # limitations under the License. # noinspection PyPackageRequirements +from datetime import datetime +import uuid + + +from keystonemiddleware import fixture as ksm_fixture +from mock import mock from vitrage.tests.functional.api.v1 import FunctionalTest +EVENT_DETAILS = { + 'hostname': 'host123', + 'source': 'sample_monitor', + 'cause': 'another alarm', + 'severity': 'critical', + 'status': 'down', + 'monitor_id': 'sample monitor', + 'monitor_event_id': '456', +} + +VALID_TOKEN = uuid.uuid4().hex + +HEADERS = { + 'X-Auth-Token': VALID_TOKEN, + 'X-Project-Id': 'admin', + 'X-Roles': 'admin' +} + class AuthTest(FunctionalTest): @@ -24,6 +48,32 @@ class AuthTest(FunctionalTest): super(AuthTest, self).__init__(*args, **kwds) self.auth = 'keystone' + def setUp(self): + super(AuthTest, self).setUp() + self.auth_token_fixture = self.useFixture( + ksm_fixture.AuthTokenFixture()) + self.auth_token_fixture.add_token_data( + token_id=VALID_TOKEN, + project_id='admin', + role_list=['admin'], + user_name='user_name', + user_id='user_id', + is_v2=True + ) + def test_in_keystone_mode_not_authenticated(self): resp = self.post_json('/topology/', params=None, expect_errors=True) self.assertEqual('401 Unauthorized', resp.status) + + def test_in_keystone_mode_auth_success(self): + with mock.patch('pecan.request') as request: + resp = self.post_json('/event/', + params={ + 'time': datetime.now().isoformat(), + 'type': 'compute.host.down', + 'details': EVENT_DETAILS + }, + headers=HEADERS) + + self.assertEqual(1, request.client.call.call_count) + self.assertEqual('200 OK', resp.status)