From 7e83d0876ddb84a45e130eeba28bc40ef53c074b Mon Sep 17 00:00:00 2001 From: Yaron Yogev Date: Thu, 27 Jul 2017 09:02:54 +0300 Subject: Calipso initial release for OPNFV Change-Id: I7210c244b0c10fa80bfa8c77cb86c9d6ddf8bc88 Signed-off-by: Yaron Yogev --- app/test/api/responders_test/auth/__init__.py | 10 +++ app/test/api/responders_test/auth/test_tokens.py | 105 +++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 app/test/api/responders_test/auth/__init__.py create mode 100644 app/test/api/responders_test/auth/test_tokens.py (limited to 'app/test/api/responders_test/auth') diff --git a/app/test/api/responders_test/auth/__init__.py b/app/test/api/responders_test/auth/__init__.py new file mode 100644 index 0000000..1e85a2a --- /dev/null +++ b/app/test/api/responders_test/auth/__init__.py @@ -0,0 +1,10 @@ +############################################################################### +# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) # +# and others # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Apache License, Version 2.0 # +# which accompanies this distribution, and is available at # +# http://www.apache.org/licenses/LICENSE-2.0 # +############################################################################### + diff --git a/app/test/api/responders_test/auth/test_tokens.py b/app/test/api/responders_test/auth/test_tokens.py new file mode 100644 index 0000000..d7b9675 --- /dev/null +++ b/app/test/api/responders_test/auth/test_tokens.py @@ -0,0 +1,105 @@ +############################################################################### +# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) # +# and others # +# # +# All rights reserved. This program and the accompanying materials # +# are made available under the terms of the Apache License, Version 2.0 # +# which accompanies this distribution, and is available at # +# http://www.apache.org/licenses/LICENSE-2.0 # +############################################################################### +import json +from unittest.mock import patch + +from test.api.responders_test.test_data import base + +from test.api.responders_test.test_data import tokens +from test.api.test_base import TestBase + + +class TestTokens(TestBase): + + def test_create_token_without_auth_obj(self): + self.validate_post_request(tokens.URL, + body=json.dumps(tokens.AUTH_OBJ_WITHOUT_AUTH), + expected_code=base.BAD_REQUEST_CODE) + + def test_create_token_without_methods(self): + self.validate_post_request(tokens.URL, + body=json.dumps(tokens.AUTH_OBJ_WITHOUT_METHODS), + expected_code=base.BAD_REQUEST_CODE) + + def test_create_token_without_credentials_in_credentials_method(self): + self.validate_post_request(tokens.URL, + body=json.dumps(tokens.AUTH_OBJ_WITHOUT_CREDENTIALS), + expected_code=base.UNAUTHORIZED_CODE) + + def test_create_token_without_token_in_token_method(self): + self.validate_post_request(tokens.URL, + body=json.dumps(tokens.AUTH_OBJ_WITHOUT_TOKEN), + expected_code=base.UNAUTHORIZED_CODE) + + @patch(tokens.AUTH_VALIDATE_CREDENTIALS) + def test_create_token_with_wrong_credentials(self, validate_credentials): + self.validate_post_request(tokens.URL, + body=json.dumps(tokens.AUTH_OBJ_WITH_WRONG_CREDENTIALS), + mocks={ + validate_credentials: False + }, + expected_code=base.UNAUTHORIZED_CODE) + + @patch(tokens.AUTH_VALIDATE_TOKEN) + def test_create_token_with_wrong_token(self, validate_token): + self.validate_post_request(tokens.URL, + body=json.dumps(tokens.AUTH_OBJ_WITH_WRONG_TOKEN), + mocks={ + validate_token: 'token error' + }, + expected_code=base.UNAUTHORIZED_CODE) + + @patch(tokens.AUTH_WRITE_TOKEN) + @patch(tokens.AUTH_VALIDATE_CREDENTIALS) + def test_create_token_with_correct_credentials(self, validate_credentials, write_token): + self.validate_post_request(tokens.URL, + body=json.dumps(tokens.AUTH_OBJ_WITH_CORRECT_CREDENTIALS), + mocks={ + validate_credentials: True, + write_token: None + }, + expected_code=base.CREATED_CODE) + + @patch(tokens.AUTH_WRITE_TOKEN) + @patch(tokens.AUTH_VALIDATE_TOKEN) + def test_create_token_with_correct_token(self, validate_token, write_token): + self.validate_post_request(tokens.URL, + body=json.dumps(tokens.AUTH_OBJ_WITH_CORRECT_TOKEN), + mocks={ + validate_token: None, + write_token: None + }, + expected_code=base.CREATED_CODE) + + def test_delete_token_without_token(self): + self.validate_delete_request(tokens.URL, + headers=tokens.HEADER_WITHOUT_TOKEN, + expected_code=base.UNAUTHORIZED_CODE + ) + + @patch(tokens.AUTH_VALIDATE_TOKEN) + def test_delete_token_with_wrong_token(self, validate_token): + self.validate_delete_request(tokens.URL, + headers=tokens.HEADER_WITH_WRONG_TOKEN, + mocks={ + validate_token: 'token error' + }, + expected_code=base.UNAUTHORIZED_CODE) + + @patch(tokens.AUTH_VALIDATE_TOKEN) + @patch(tokens.AUTH_DELETE_TOKEN) + def test_delete_token_with_correct_token(self, delete_token, validate_token): + self.validate_delete_request(tokens.URL, + headers=tokens.HEADER_WITH_CORRECT_TOKEN, + mocks={ + validate_token: None, + delete_token: None + }, + expected_code=base.SUCCESSFUL_CODE) -- cgit 1.2.3-korg