Example #1
0
    def test_containers_with_expired_secrets_are_deleted(self):
        """Containers with expired secrets are deleted"""
        current_time = utils.create_timestamp_w_tz_and_offset(seconds=10)

        project_a_delete_containers = self._create_container_uuid_list(
            user=admin_a,
            delete_container=True,
            secret_expiration=current_time)
        project_b_delete_containers = self._create_container_uuid_list(
            user=admin_b,
            delete_container=True,
            secret_expiration=current_time)

        time.sleep(10)

        os.system("python barbican/cmd/db_manage.py clean -m 0 -p -e")

        results = self.conn.execute("select * from containers")
        container_list = []
        for row in results:
            container_list.append(str(row[0]))

        for container in project_a_delete_containers:
            container_uuid = self._get_uuid(container)
            self.assertNotIn(container_uuid, container_list)

        for container in project_b_delete_containers:
            container_uuid = self._get_uuid(container)
            self.assertNotIn(container_uuid, container_list)
Example #2
0
    def test_containers_with_expired_secrets_are_deleted(self):
        """Containers with expired secrets are deleted"""
        current_time = utils.create_timestamp_w_tz_and_offset(seconds=10)

        project_a_delete_containers = self._create_container_uuid_list(
            user=admin_a,
            delete_container=True,
            secret_expiration=current_time)
        project_b_delete_containers = self._create_container_uuid_list(
            user=admin_b,
            delete_container=True,
            secret_expiration=current_time)

        time.sleep(10)

        os.system("python barbican/cmd/db_manage.py clean -m 0 -p -e")

        results = self.conn.execute("select * from containers")
        container_list = []
        for row in results:
            container_list.append(str(row[0]))

        for container in project_a_delete_containers:
            container_uuid = self._get_uuid(container)
            self.assertNotIn(container_uuid, container_list)

        for container in project_b_delete_containers:
            container_uuid = self._get_uuid(container)
            self.assertNotIn(container_uuid, container_list)
Example #3
0
    def test_expired_secrets_are_not_removed_from_db(self):
        """Test expired secrests are left in soft deleted state.

        Currently this clean will set the threshold at the start
        of the test. Expired secrets will be deleted and the
        deleted at date will now be later then the threshold
        date.
        """

        current_time = utils.create_timestamp_w_tz_and_offset(seconds=10)
        project_a_secrets = self._create_secret_list(user=admin_a,
                                                     expiration=current_time)
        project_b_secrets = self._create_secret_list(user=admin_b,
                                                     expiration=current_time)

        time.sleep(10)

        os.system("python barbican/cmd/db_manage.py clean -m 0 -p -e")

        results = self.conn.execute("select * from secrets")
        secret_list = []
        for row in results:
            secret_list.append(str(row[0]))

        for secret in project_a_secrets:
            secret_uuid = self._get_uuid(secret)
            self.assertIn(secret_uuid, secret_list)

        for secret in project_b_secrets:
            secret_uuid = self._get_uuid(secret)
            self.assertIn(secret_uuid, secret_list)
Example #4
0
    def test_secret_create_then_expire_then_check(self):
        """Covers case where you try to retrieve a secret that is expired.

        This test creates a secret that will soon expire.
        After it expires, check it and verify that it is no longer
        a valid secret.
        """

        # create a secret that expires in 5 seconds
        timestamp = utils.create_timestamp_w_tz_and_offset(seconds=5)

        test_model = secret_models.SecretModel(**self.default_secret_create_data)
        test_model.expiration = timestamp

        resp, secret_ref = self.behaviors.create_secret(test_model)
        self.assertEqual(resp.status_code, 201)

        # now get the secret - will be still valid
        get_resp = self.behaviors.get_secret_metadata(secret_ref)
        self.assertEqual(get_resp.status_code, 200)

        # now wait 10 seconds
        time.sleep(10)

        # now get the secret - should be invalid (expired)
        resp = self.behaviors.get_secret_metadata(secret_ref)
        self.assertEqual(resp.status_code, 404)
Example #5
0
    def test_secret_create_defaults_then_expire_then_check(self):
        """Covers case where you try to retrieve a secret that is expired.

        This test creates a secret that will soon expire.
        After it expires, check it and verify that it is no longer
        a valid secret.
        """

        # create a secret that expires in 5 seconds
        timestamp = utils.create_timestamp_w_tz_and_offset(seconds=5)

        test_model = secret_models.SecretModel(**secret_create_defaults_data)
        overrides = {"expiration": timestamp}
        test_model.override_values(**overrides)

        resp, secret_ref = self.behaviors.create_secret(test_model)
        self.assertEqual(resp.status_code, 201)

        # now get the secret - will be still valid
        get_resp = self.behaviors.get_secret_metadata(secret_ref)
        self.assertEqual(get_resp.status_code, 200)

        # now wait 10 seconds
        time.sleep(10)

        # now get the secret - should be invalid (expired)
        resp = self.behaviors.get_secret_metadata(secret_ref)
        self.assertEqual(resp.status_code, 404)
Example #6
0
    def test_expired_secrets_are_not_removed_from_db(self):
        """Test expired secrests are left in soft deleted state.

        Currently this clean will set the threshold at the start
        of the test. Expired secrets will be deleted and the
        deleted at date will now be later then the threshold
        date.
        """

        current_time = utils.create_timestamp_w_tz_and_offset(seconds=10)
        project_a_secrets = self._create_secret_list(user=admin_a,
                                                     expiration=current_time)
        project_b_secrets = self._create_secret_list(user=admin_b,
                                                     expiration=current_time)

        time.sleep(10)

        os.system("python barbican/cmd/db_manage.py clean -m 0 -p -e")

        results = self.conn.execute("select * from secrets")
        secret_list = []
        for row in results:
            secret_list.append(str(row[0]))

        for secret in project_a_secrets:
            secret_uuid = self._get_uuid(secret)
            self.assertIn(secret_uuid, secret_list)

        for secret in project_b_secrets:
            secret_uuid = self._get_uuid(secret)
            self.assertIn(secret_uuid, secret_list)
Example #7
0
    def test_order_create_invalid_expiration(self, **kwargs):
        """Covers creating orders with various invalid expiration data."""
        timestamp = utils.create_timestamp_w_tz_and_offset(**kwargs)
        test_model = order_models.OrderModel(**self.create_default_data)
        test_model.meta['expiration'] = timestamp

        create_resp, order_ref = self.behaviors.create_order(test_model)
        self.assertEqual(400, create_resp.status_code)
Example #8
0
    def test_order_create_invalid_expiration(self, **kwargs):
        """Covers creating orders with various invalid expiration data."""
        timestamp = utils.create_timestamp_w_tz_and_offset(**kwargs)
        test_model = order_models.OrderModel(**self.create_default_data)
        test_model.meta['expiration'] = timestamp

        create_resp, order_ref = self.behaviors.create_order(test_model)
        self.assertEqual(create_resp.status_code, 400)
Example #9
0
    def test_secret_create_defaults_invalid_expiration(self, timezone, days):
        """Create secrets with various invalid expiration data."""
        timestamp = utils.create_timestamp_w_tz_and_offset(timezone=timezone, days=days)

        test_model = secret_models.SecretModel(**self.default_secret_create_data)
        test_model.expiration = timestamp

        resp, secret_ref = self.behaviors.create_secret(test_model)
        self.assertEqual(resp.status_code, 400)
Example #10
0
    def test_secret_create_defaults_invalid_expiration(self, **kwargs):
        """Create secrets with various invalid expiration data."""
        timestamp = utils.create_timestamp_w_tz_and_offset(**kwargs)

        test_model = secret_models.SecretModel(**secret_create_defaults_data)
        overrides = {"expiration": timestamp}
        test_model.override_values(**overrides)

        resp, secret_ref = self.behaviors.create_secret(test_model)
        self.assertEqual(resp.status_code, 400)
Example #11
0
    def test_secret_create_defaults_invalid_expiration(self, **kwargs):
        """Create secrets with various invalid expiration data."""
        timestamp = utils.create_timestamp_w_tz_and_offset(**kwargs)

        test_model = secret_models.SecretModel(**secret_create_defaults_data)
        overrides = {"expiration": timestamp}
        test_model.override_values(**overrides)

        resp, secret_ref = self.behaviors.create_secret(test_model)
        self.assertEqual(resp.status_code, 400)
Example #12
0
    def test_secret_create_defaults_invalid_expiration(self, timezone, days):
        """Create secrets with various invalid expiration data."""
        timestamp = utils.create_timestamp_w_tz_and_offset(timezone=timezone,
                                                           days=days)

        test_model = secret_models.SecretModel(
            **self.default_secret_create_data)
        test_model.expiration = timestamp

        resp, secret_ref = self.behaviors.create_secret(test_model)
        self.assertEqual(resp.status_code, 400)
Example #13
0
    def test_secret_create_defaults_bad_expiration_timezone(self):
        """Covers case of a malformed timezone being added to the expiration.
        - Reported in Barbican GitHub Issue #134
        """
        timestamp = utils.create_timestamp_w_tz_and_offset('-5:00', days=0)

        test_model = secret_models.SecretModel(**secret_create_defaults_data)
        overrides = {"expiration": timestamp}
        test_model.override_values(**overrides)

        resp, secret_ref = self.behaviors.create_secret(test_model)
        self.assertEqual(resp.status_code, 400)
Example #14
0
    def test_secret_create_defaults_positive_hour_short_expiration(self):
        """Covers case of a malformed timezone being added to the expiration.
        - Reported in Barbican GitHub Issue #134
        :rtype : object
        """
        timestamp = utils.create_timestamp_w_tz_and_offset('+01', days=1)

        test_model = secret_models.SecretModel(**secret_create_defaults_data)
        overrides = {"expiration": timestamp}
        test_model.override_values(**overrides)

        resp, secret_ref = self.behaviors.create_secret(test_model)
        self.assertEqual(resp.status_code, 201)