def test_get_url_private_expired(self):
        # this is creating a bucket in the moto/mock s3 service
        s3conn = boto3.resource('s3')
        s3conn.create_bucket(Bucket='castletest')

        fileOb = upload_file_to_castle(self)
        aws.move_file(fileOb)
        fileOb = api.content.get(path='/file-repository/foobar.bin')

        # move the generated further into the past
        annotations = IAnnotations(fileOb)
        info = annotations.get(aws.STORAGE_KEY, PersistentMapping())
        newgeneratedon = time() - aws.EXPIRES_IN - 1000
        info.update({
            'generated_on': newgeneratedon,
        })
        annotations[aws.STORAGE_KEY] = info

        resulturl = aws.get_url(fileOb)
        self.assertTrue(resulturl.startswith(self.test_base_url))

        fileOb = api.content.get(path='/file-repository/foobar.bin')
        annotations = IAnnotations(fileOb)
        info = annotations.get(aws.STORAGE_KEY, PersistentMapping())
        self.assertNotEqual(info["generated_on"], newgeneratedon)
        self.assertEqual(info["expires_in"], aws.EXPIRES_IN)
Exemple #2
0
    def __call__(self):
        if not aws.uploaded(self.context):
            try:
                return self.serve_file()
            except (POSKeyError, SystemError):
                # if there is no blob file, just give out 404
                raise NotFound

        url = aws.get_url(self.context)
        self.request.response.redirect(url)
    def test_get_url_public_or_notexpired(self):
        # this is creating a bucket in the moto/mock s3 service
        s3conn = boto3.resource('s3')
        s3conn.create_bucket(Bucket='castletest')

        fileOb = upload_file_to_castle(self)
        api.content.transition(fileOb, 'publish')
        aws.move_file(fileOb)
        fileOb = api.content.get(path='/file-repository/foobar.bin')

        resulturl = aws.get_url(fileOb)
        self.assertTrue(resulturl.startswith(self.test_base_url))
Exemple #4
0
    def __call__(self):
        if not aws.uploaded(self.context):
            return self.serve_file()

        url = aws.get_url(self.context)
        self.request.response.redirect(url)