A modular, vendor-neutral API, that wraps provisioning instructions for all CDN vendors that support it.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

178 lines
7.5KB

  1. # Copyright (c) 2015 Rackspace, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. # implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import json
  16. import uuid
  17. import ddt
  18. import mock
  19. from poppy.transport.validators import helpers as validators
  20. from tests.functional.transport.pecan import base
  21. @ddt.ddt
  22. class SSLCertificateControllerTest(base.FunctionalTest):
  23. def setUp(self):
  24. super(SSLCertificateControllerTest, self).setUp()
  25. self.project_id = str(uuid.uuid1())
  26. self.service_name = str(uuid.uuid1())
  27. self.flavor_id = str(uuid.uuid1())
  28. # create a mock flavor to be used by new service creations
  29. flavor_json = {
  30. "id": self.flavor_id,
  31. "providers": [
  32. {
  33. "provider": "mock",
  34. "links": [
  35. {
  36. "href": "http://mock.cdn",
  37. "rel": "provider_url"
  38. }
  39. ]
  40. }
  41. ]
  42. }
  43. response = self.app.post('/v1.0/flavors',
  44. params=json.dumps(flavor_json),
  45. headers={
  46. "Content-Type": "application/json",
  47. "X-Project-ID": self.project_id})
  48. self.assertEqual(201, response.status_code)
  49. @ddt.file_data("data_create_ssl_certificate.json")
  50. def test_create_ssl_certificate(self, ssl_certificate_json):
  51. validators.is_valid_tld = mock.Mock(return_value=True)
  52. # override the hardcoded flavor_id in the ddt file with
  53. # a custom one defined in setUp()
  54. ssl_certificate_json['flavor_id'] = self.flavor_id
  55. # create with good data
  56. response = self.app.post('/v1.0/ssl_certificate',
  57. params=json.dumps(ssl_certificate_json),
  58. headers={
  59. 'Content-Type': 'application/json',
  60. 'X-Project-ID': self.project_id})
  61. self.assertEqual(202, response.status_code)
  62. def test_get_ssl_certificate_non_existing_domain(self):
  63. # get non existing domain
  64. domain = 'www.idontexist.com'
  65. response = self.app.get('/v1.0/ssl_certificate/{0}'.format(domain),
  66. headers={
  67. 'Content-Type': 'application/json',
  68. 'X-Project-ID': self.project_id},
  69. expect_errors=True)
  70. self.assertEqual(404, response.status_code)
  71. def test_get_ssl_certificate_existing_domain(self):
  72. validators.is_valid_tld = mock.Mock(return_value=True)
  73. domain = 'www.iexist.com'
  74. ssl_certificate_json = {
  75. "cert_type": "san",
  76. "domain_name": domain,
  77. "flavor_id": self.flavor_id,
  78. "project_id": self.project_id
  79. }
  80. response = self.app.post('/v1.0/ssl_certificate',
  81. params=json.dumps(ssl_certificate_json),
  82. headers={
  83. 'Content-Type': 'application/json',
  84. 'X-Project-ID': self.project_id})
  85. self.assertEqual(202, response.status_code)
  86. # get existing domain with same project_id
  87. response = self.app.get('/v1.0/ssl_certificate/{0}'.format(domain),
  88. headers={
  89. 'Content-Type': 'application/json',
  90. 'X-Project-ID': self.project_id})
  91. response_list = json.loads(response.body.decode("utf-8"))
  92. self.assertEqual(200, response.status_code)
  93. self.assertEqual(ssl_certificate_json["cert_type"],
  94. response_list[0]["cert_type"])
  95. self.assertEqual(ssl_certificate_json["domain_name"],
  96. response_list[0]["domain_name"])
  97. self.assertEqual(ssl_certificate_json["flavor_id"],
  98. response_list[0]["flavor_id"])
  99. self.assertEqual(ssl_certificate_json["project_id"],
  100. response_list[0]["project_id"])
  101. def test_get_ssl_certificate_existing_domain_different_project_id(self):
  102. validators.is_valid_tld = mock.Mock(return_value=True)
  103. domain = 'www.iexist.com'
  104. ssl_certificate_json = {
  105. "cert_type": "san",
  106. "domain_name": domain,
  107. "flavor_id": self.flavor_id,
  108. "project_id": self.project_id
  109. }
  110. response = self.app.post('/v1.0/ssl_certificate',
  111. params=json.dumps(ssl_certificate_json),
  112. headers={
  113. 'Content-Type': 'application/json',
  114. 'X-Project-ID': self.project_id})
  115. self.assertEqual(202, response.status_code)
  116. # get existing domain with different project_id
  117. response = self.app.get('/v1.0/ssl_certificate/{0}'.format(domain),
  118. headers={
  119. 'Content-Type': 'application/json',
  120. 'X-Project-ID': str(uuid.uuid4())})
  121. self.assertEqual(200, response.status_code)
  122. def test_create_with_invalid_json(self):
  123. # create with errorenous data: invalid json data
  124. response = self.app.post('/v1.0/ssl_certificate',
  125. params="{",
  126. headers={
  127. 'Content-Type': 'application/json',
  128. 'X-Project-ID': self.project_id},
  129. expect_errors=True)
  130. self.assertEqual(400, response.status_code)
  131. @ddt.file_data("data_create_ssl_certificate_bad_input_json.json")
  132. def test_create_with_bad_input_json(self, ssl_certificate_json):
  133. # create with errorenous data
  134. response = self.app.post('/v1.0/ssl_certificate',
  135. params=json.dumps(ssl_certificate_json),
  136. headers={'Content-Type': 'application/json',
  137. 'X-Project-ID': self.project_id},
  138. expect_errors=True)
  139. self.assertEqual(400, response.status_code)
  140. def test_delete_cert(self):
  141. # create with errorenous data: invalid json data
  142. response = self.app.delete('/v1.0/ssl_certificate/blog.test.com',
  143. headers={'X-Project-ID': self.project_id}
  144. )
  145. self.assertEqual(202, response.status_code)
  146. def test_delete_cert_non_exist(self):
  147. # create with errorenous data: invalid json data
  148. response = self.app.delete('/v1.0/ssl_certificate/blog.non_exist.com',
  149. headers={'X-Project-ID': self.project_id},
  150. expect_errors=True)
  151. self.assertEqual(400, response.status_code)
  152. def tearDown(self):
  153. super(SSLCertificateControllerTest, self).tearDown()