add a test for keystone

check the keystone authentication

Change-Id: I17d26aba6d373fe150120c9176c8673bb1192556
This commit is contained in:
Eyal 2017-07-31 16:24:07 +03:00
parent dbf5c610de
commit b069bad768

View File

@ -1,4 +1,4 @@
# Copyright 2016 - Nokia Corporation # Copyright 2017 - Nokia Corporation
# Copyright 2014 OpenStack Foundation # Copyright 2014 OpenStack Foundation
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
@ -15,8 +15,32 @@
# limitations under the License. # limitations under the License.
# noinspection PyPackageRequirements # 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 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): class AuthTest(FunctionalTest):
@ -24,6 +48,32 @@ class AuthTest(FunctionalTest):
super(AuthTest, self).__init__(*args, **kwds) super(AuthTest, self).__init__(*args, **kwds)
self.auth = 'keystone' 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): def test_in_keystone_mode_not_authenticated(self):
resp = self.post_json('/topology/', params=None, expect_errors=True) resp = self.post_json('/topology/', params=None, expect_errors=True)
self.assertEqual('401 Unauthorized', resp.status) 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)