Example #1
0
    def test_recreate_consumer_defaults(self):
        """Covers consumer recreation."""
        test_model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref)

        self.assertEqual(200, resp.status_code)
        self.assertIsNotNone(consumer_data)

        # Delete the consumer
        resp, consumer_data = self.consumer_behaviors.delete_consumer(
            test_model, self.container_ref
        )
        self.assertEqual(200, resp.status_code)
        self.assertIsNotNone(consumer_data)
        self.assertNotIn(test_model.name, consumer_data)
        self.assertNotIn(test_model.URL, consumer_data)

        # Register the consumer again
        test_model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref)

        self.assertEqual(200, resp.status_code)
        self.assertIsNotNone(consumer_data)
Example #2
0
    def test_get_consumer_defaults(self):
        """Tests getting a list of consumers for a container."""
        # Create first consumer
        test_model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref)

        self.assertEqual(resp.status_code, 200)
        self.assertIsNotNone(consumer_data)

        # Create second consumer
        test_model.name = "consumername2"
        test_model.URL = "consumerURL2"

        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref)

        self.assertEqual(resp.status_code, 200)
        self.assertIsNotNone(consumer_data)

        # Get list of consumers
        resp, consumers, nref, pref = self.consumer_behaviors.get_consumers(
            self.container_ref)
        self.assertEqual(resp.status_code, 200)
        self.assertIn("consumername", consumers[0].name)
        self.assertIn("consumername2", consumers[1].name)
Example #3
0
def get_consumer_model():
    test_consumer_model = consumer_model.ConsumerModel(
        name="consumername",
        URL="consumerURL"
    )

    return test_consumer_model
 def create_consumers(self, count=1, expected_return=200):
     """Utility function to create consumers"""
     for _ in range(count):
         container_ref = self.create_containers()
         model = consumer_model.ConsumerModel(
             **self.get_default_consumer_data())
         resp, consumer_dat = self.consumer_behaviors.create_consumer(
             model, container_ref, user_name=admin_b)
         self.assertEqual(expected_return, resp.status_code)
Example #5
0
    def _create_consumer(self, container_ref):
        self.consumer_test_model = consumer_model.ConsumerModel(
            **self.consumer_default_data)
        resp, consumer_data = self.consumer_behaviors.create_consumer(
            self.consumer_test_model, container_ref)

        self.assertEqual(200, resp.status_code)
        self.assertIsNotNone(consumer_data)
        return consumer_data
Example #6
0
    def test_consumer_create_unauthed_no_proj_id(self):
        """Attempt to create a consumer without a token or project id

        Should return 401
        """

        model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_dat = self.consumer_behaviors.create_consumer(
            model, self.generic_container_ref, use_auth=False)
        self.assertEqual(401, resp.status_code)
Example #7
0
    def test_consumer_create_authed(self):
        """Create a consumer as an authenticated user

        Should return 200
        """

        model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_dat = self.consumer_behaviors.create_consumer(
            model, self.generic_container_ref, use_auth=True)
        self.assertEqual(200, resp.status_code)
Example #8
0
    def test_consumer_create_fail_empty_url(self):
        """Attempt to create invalid consumer (Empty URL)

        Should return 400
        """
        data = {"name": "consumername", "URL": ""}
        model = consumer_model.ConsumerModel(**data)
        resp, consumer_dat = self.consumer_behaviors.create_consumer(
            model, self.generic_container_ref, use_auth=True)
        self.assertEqual(400, resp.status_code)
Example #9
0
    def test_consumer_create_pass(self):
        """Create a valid consumer

        Should return 200
        """
        data = {"name": "consumername", "URL": "consumerURL"}
        model = consumer_model.ConsumerModel(**data)
        resp, consumer_dat = self.consumer_behaviors.create_consumer(
            model, self.generic_container_ref, use_auth=True)
        self.assertEqual(200, resp.status_code)
Example #10
0
    def test_create_consumer_defaults(self):
        """Covers consumer creation.

        All of the data needed to create the consumer is provided in a
        single POST.
        """
        test_model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref)

        self.assertEqual(resp.status_code, 200)
        self.assertIsNotNone(consumer_data)
Example #11
0
    def test_create_consumer_defaults_is_idempotent(self):
        """Covers checking that create consumer is idempotent."""
        # Register the consumer once
        test_model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref)

        self.assertEqual(resp.status_code, 200)
        self.assertIsNotNone(consumer_data)

        # Register the consumer again, without deleting it first
        test_model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref)

        count = consumer_data.count(self.consumer_data)

        self.assertEqual(resp.status_code, 200)
        self.assertIsNotNone(consumer_data)
        self.assertIn(self.consumer_data, consumer_data)
        self.assertEqual(1, count)
Example #12
0
    def test_consumer_create_unauthed_with_proj_id(self):
        """Attempt to create a consumer with a project id, but no token

        Should return 401
        """

        model = consumer_model.ConsumerModel(**self.consumer_data)
        headers = {'X-Project-Id': dummy_project_id}
        resp, consumer_dat = self.consumer_behaviors.create_consumer(
            model, self.container_ref, extra_headers=headers, use_auth=False
        )

        self.assertEqual(401, resp.status_code)
Example #13
0
    def test_create_consumer_change_host_header(self, **kwargs):
        """Create a consumer with a (possibly) malicious host name header."""

        test_model = consumer_model.ConsumerModel(**self.consumer_data)

        malicious_hostname = 'some.bad.server.com'
        changed_host_header = {'Host': malicious_hostname}

        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref, extra_headers=changed_host_header)

        self.assertEqual(resp.status_code, 200)
        self.assertIsNotNone(consumer_data)

        # get Location field from result and assert that it is NOT the
        # malicious one.
        regex = '.*{0}.*'.format(malicious_hostname)
        self.assertNotRegexpMatches(resp.headers['location'], regex)
Example #14
0
    def test_delete_consumer_defaults(self):
        """Covers consumer deletion.

        A consumer is first created, and then the consumer is deleted and
        verified to no longer exist.
        """
        test_model = consumer_model.ConsumerModel(**self.consumer_data)
        resp, consumer_data = self.consumer_behaviors.create_consumer(
            test_model, self.container_ref)

        self.assertEqual(resp.status_code, 200)
        self.assertIsNotNone(consumer_data)

        # Delete the consumer
        resp, consumer_data = self.consumer_behaviors.delete_consumer(
            test_model, self.container_ref)
        self.assertEqual(resp.status_code, 200)
        self.assertIsNotNone(consumer_data)
        self.assertNotIn(test_model.name, consumer_data)
        self.assertNotIn(test_model.URL, consumer_data)