def test_s3_presigned_url_expired(self):
    bucket_name = ('test-bucket-%s' % short_uid())
    client = self._get_test_client()
    client.create_bucket(Bucket=bucket_name)
    object_key = 'key-by-hostname'
    client.put_object(Bucket=bucket_name, Key=object_key, Body='something')
    url = client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': object_key}, ExpiresIn=2)
    resp = requests.get(url, verify=False)
    self.assertEqual(resp.status_code, 200)
    self.assertEqual(to_str(resp.content), 'something')
    time.sleep(3)
    resp = requests.get(url, verify=False)
    self.assertEqual(resp.status_code, 403)
    url = client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': object_key}, ExpiresIn=120)
    resp = requests.get(url, verify=False)
    self.assertEqual(resp.status_code, 200)
    self.assertEqual(to_str(resp.content), 'something')
    self._delete_bucket(bucket_name, [object_key])
def test_s3_presigned_url_expired(self):
    bucket_name = ('test-bucket-%s' % short_uid())
    client = self._get_test_client()
    client.create_bucket(Bucket=bucket_name)
    object_key = 'key-by-hostname'
    client.put_object(Bucket=bucket_name, Key=object_key, Body='something')
    url = client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': object_key}, ExpiresIn=2)
    resp = requests.get(url, verify=False)
    self.assertEqual(resp.status_code, 200)
    self.assertEqual(to_str(resp.content), 'something')
    time.sleep(3)
    resp = requests.get(url, verify=False)
    self.assertEqual(resp.status_code, 403)
    url = client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': object_key}, ExpiresIn=120)
    resp = requests.get(url, verify=False)
    self.assertEqual(resp.status_code, 200)
    self.assertEqual(to_str(resp.content), 'something')
    self._delete_bucket(bucket_name, [object_key])