internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: getmoto/moto

Issue:
S3: PUT request should fail when no 'Content-Length' header is present, but doesn't
I've discovered an inconsistency between the AWS behaviour and the moto one when trying to upload an empty file to S3 with a PUT request: as stated in http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html#RESTObjectPUT-requests, the Content-Length header is required in such request, and should fail with a 411 Length Required response if not provided. This is happening if I contact the "real" AWS API using the requests Python library (which, for some reason, is not setting this header when the file is empty), but the moto mocked one just returns 200 OK.

My version of moto is 0.4.27.



Discussion:

Resolving patch:
diff --git a/moto/s3/responses.py b/moto/s3/responses.py
--- a/moto/s3/responses.py
+++ b/moto/s3/responses.py
@@ -294,6 +294,8 @@ def _handle_list_objects_v2(self, bucket_name, querystring):
         )
 
     def _bucket_response_put(self, request, body, region_name, bucket_name, querystring, headers):
+        if not request.headers.get('Content-Length'):
+            return 411, {}, "Content-Length required"
         if 'versioning' in querystring:
             ver = re.search('<Status>([A-Za-z]+)</Status>', body)
             if ver:
@@ -355,6 +357,8 @@ def _bucket_response_delete(self, body, bucket_name, querystring, headers):
             return 409, {}, template.render(bucket=removed_bucket)
 
     def _bucket_response_post(self, request, body, bucket_name, headers):
+        if not request.headers.get('Content-Length'):
+            return 411, {}, "Content-Length required"
         path = request.path if hasattr(request, 'path') else request.path_url
         if self.is_delete_keys(request, path, bucket_name):
             return self._bucket_response_delete_keys(request, body, bucket_name, headers)


Test patch:
diff --git a/tests/test_s3/test_server.py b/tests/test_s3/test_server.py
--- a/tests/test_s3/test_server.py
+++ b/tests/test_s3/test_server.py
@@ -66,3 +66,14 @@ def test_s3_server_post_to_bucket():
     res = test_client.get('/the-key', 'http://tester.localhost:5000/')
     res.status_code.should.equal(200)
     res.data.should.equal(b"nothing")
+
+
+def test_s3_server_post_without_content_length():
+    backend = server.create_backend_app("s3")
+    test_client = backend.test_client()
+
+    res = test_client.put('/', 'http://tester.localhost:5000/', environ_overrides={'CONTENT_LENGTH': ''})
+    res.status_code.should.equal(411)
+
+    res = test_client.post('/', "https://tester.localhost:5000/", environ_overrides={'CONTENT_LENGTH': ''})
+    res.status_code.should.equal(411)
Repository: getmoto/moto

Issue:
Fixes: Stand-alone Server Mode: EC2 get_all_instances not implemented
Stand-alone Server Mode: EC2 get_all_instances not implemented?
https://github.com/spulec/moto/issues/74

Future TODO: Write unittest(s) for the server-mode.



Discussion:
Closing since it looks like this has been incorporated in #76 

Oops, I looked over this too carefully. It should definitely be it's own pull request. Merged with https://github.com/spulec/moto/commit/d58f406de4c5adcf482ba0ee1e4a91a3b02ed3dc


Resolving patch:
diff --git a/moto/iam/models.py b/moto/iam/models.py
--- a/moto/iam/models.py
+++ b/moto/iam/models.py
@@ -177,7 +177,7 @@ def __init__(self, user_name):
         self.status = 'Active'
         self.create_date = datetime.strftime(
             datetime.utcnow(),
-            "%Y-%m-%d-%H-%M-%S"
+            "%Y-%m-%dT%H:%M:%SZ"
         )
 
     def get_cfn_attribute(self, attribute_name):
diff --git a/moto/iam/responses.py b/moto/iam/responses.py
--- a/moto/iam/responses.py
+++ b/moto/iam/responses.py
@@ -900,6 +900,7 @@ def get_credential_report(self):
             <UserName>{{ user_name }}</UserName>
             <AccessKeyId>{{ key.access_key_id }}</AccessKeyId>
             <Status>{{ key.status }}</Status>
+            <CreateDate>{{ key.create_date }}</CreateDate>
          </member>
         {% endfor %}
       </AccessKeyMetadata>


Test patch:
diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py
--- a/tests/test_iam/test_iam.py
+++ b/tests/test_iam/test_iam.py
@@ -299,6 +299,8 @@ def test_create_access_key():
 
 @mock_iam_deprecated()
 def test_get_all_access_keys():
+    """If no access keys exist there should be none in the response,
+    if an access key is present it should have the correct fields present"""
     conn = boto.connect_iam()
     conn.create_user('my-user')
     response = conn.get_all_access_keys('my-user')
@@ -309,10 +311,10 @@ def test_get_all_access_keys():
     )
     conn.create_access_key('my-user')
     response = conn.get_all_access_keys('my-user')
-    assert_not_equals(
-        response['list_access_keys_response'][
-            'list_access_keys_result']['access_key_metadata'],
-        []
+    assert_equals(
+        sorted(response['list_access_keys_response'][
+            'list_access_keys_result']['access_key_metadata'][0].keys()),
+        sorted(['status', 'create_date', 'user_name', 'access_key_id'])
     )
Repository: getmoto/moto

Issue:
can't use responses
with v1, since moto vendors in `responses`, it's impossible to use `responses` for mocking non-aws calls. example:

```py
with _responses.RequestsMock() as rsps:
    rsps.add(rsps.GET, 'http://foo')
    with moto.mock_sns():
       requests.get('http://foo')
```

this used to work on < v1, on v1 it raises a connection refused error because basically requests is patched twice by two different modules


Discussion:
Hmmmm, sorry about that.

I can't think of a great solution for this.... any ideas?
I think I've come across this as well using v1.0.1. I basically can't hit any websites that are non-aws. I get connection refused errors. 
I just opened a pr on responses repo: https://github.com/getsentry/responses/pull/150

since responses is vendored in, I can open a pr that applies these modification on this repo, but it'd be nice nontheless if the changes will be applied upstream

Resolving patch:
diff --git a/moto/packages/responses/responses.py b/moto/packages/responses/responses.py
--- a/moto/packages/responses/responses.py
+++ b/moto/packages/responses/responses.py
@@ -10,6 +10,7 @@
 from collections import namedtuple, Sequence, Sized
 from functools import update_wrapper
 from cookies import Cookies
+from requests.adapters import HTTPAdapter
 from requests.utils import cookiejar_from_dict
 from requests.exceptions import ConnectionError
 from requests.sessions import REDIRECT_STATI
@@ -120,10 +121,12 @@ class RequestsMock(object):
     POST = 'POST'
     PUT = 'PUT'
 
-    def __init__(self, assert_all_requests_are_fired=True):
+    def __init__(self, assert_all_requests_are_fired=True, pass_through=True):
         self._calls = CallList()
         self.reset()
         self.assert_all_requests_are_fired = assert_all_requests_are_fired
+        self.pass_through = pass_through
+        self.original_send = HTTPAdapter.send
 
     def reset(self):
         self._urls = []
@@ -235,6 +238,9 @@ def _on_request(self, adapter, request, **kwargs):
         match = self._find_match(request)
         # TODO(dcramer): find the correct class for this
         if match is None:
+            if self.pass_through:
+                return self.original_send(adapter, request, **kwargs)
+
             error_msg = 'Connection refused: {0} {1}'.format(request.method,
                                                              request.url)
             response = ConnectionError(error_msg)
@@ -317,7 +323,7 @@ def stop(self, allow_assert=True):
 
 
 # expose default mock namespace
-mock = _default_mock = RequestsMock(assert_all_requests_are_fired=False)
+mock = _default_mock = RequestsMock(assert_all_requests_are_fired=False, pass_through=False)
 __all__ = []
 for __attr in (a for a in dir(_default_mock) if not a.startswith('_')):
     __all__.append(__attr)


Test patch:
Repository: getmoto/moto

Issue:
S3 presigned url gives 403 error
When trying to access data with a pre-signed, a 403 is returned.
Setting ACL='public-read' on the object give 200, when accessing the data.
Related to issue  #1125 

```
@mock_s3
def test_s3_object_in_public_bucket():
    s3 = boto3.resource('s3')
    bucket = s3.Bucket('test-bucket')
    bucket.create()
    bucket.put_object(Body=b'ABCD', Key='file.txt')
    params = {'Bucket': 'test-bucket','Key': 'file.txt'}
    presigned_url = boto3.client('s3').generate_presigned_url('get_object', params, ExpiresIn=900)
    response = requests.get(presigned_url)
    assert response.status_code == 200
```




Discussion:
This is now fixed in Moto 1.1.12
Tried with Moto 1.1.12 and the problem still exists.
The presigned url can't be opened if the ACL is set to 'private'
Looking into it

Resolving patch:
diff --git a/moto/s3/responses.py b/moto/s3/responses.py
--- a/moto/s3/responses.py
+++ b/moto/s3/responses.py
@@ -547,9 +547,15 @@ def _key_response(self, request, full_url, headers):
         # ACL and checking for the mere presence of an Authorization
         # header.
         if 'Authorization' not in request.headers:
+            if hasattr(request, 'url'):
+                signed_url = 'Signature=' in request.url
+            elif hasattr(request, 'requestline'):
+                signed_url = 'Signature=' in request.path
             key = self.backend.get_key(bucket_name, key_name)
-            if key and not key.acl.public_read:
-                return 403, {}, ""
+
+            if key:
+                if not key.acl.public_read and not signed_url:
+                    return 403, {}, ""
 
         if hasattr(request, 'body'):
             # Boto


Test patch:
diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py
--- a/tests/test_s3/test_s3.py
+++ b/tests/test_s3/test_s3.py
@@ -884,6 +884,10 @@ def test_s3_object_in_public_bucket():
         s3_anonymous.Object(key='file.txt', bucket_name='test-bucket').get()
     exc.exception.response['Error']['Code'].should.equal('403')
 
+    params = {'Bucket': 'test-bucket','Key': 'file.txt'}
+    presigned_url = boto3.client('s3').generate_presigned_url('get_object', params, ExpiresIn=900)
+    response = requests.get(presigned_url)
+    assert response.status_code == 200
 
 @mock_s3
 def test_s3_object_in_private_bucket():
Repository: getmoto/moto

Issue:
S3 PutBucketTagging moto bug if only 1 tag is supplied
As it turns out, if you only supply 1 tag in the `s3.put_bucket_tagging()` operation, the `_bucket_tagging_from_xml()` in S3's`responses.py` breaks because the data type is a `dict` and not a `list` apparently.

I'm going to submit a PR to fix very soon.



Discussion:

Resolving patch:
diff --git a/moto/s3/responses.py b/moto/s3/responses.py
--- a/moto/s3/responses.py
+++ b/moto/s3/responses.py
@@ -780,8 +780,13 @@ def _bucket_tagging_from_xml(self, xml):
         tags = []
         # Optional if no tags are being sent:
         if parsed_xml['Tagging'].get('TagSet'):
-            for tag in parsed_xml['Tagging']['TagSet']['Tag']:
-                tags.append(FakeTag(tag['Key'], tag['Value']))
+            # If there is only 1 tag, then it's not a list:
+            if not isinstance(parsed_xml['Tagging']['TagSet']['Tag'], list):
+                tags.append(FakeTag(parsed_xml['Tagging']['TagSet']['Tag']['Key'],
+                                    parsed_xml['Tagging']['TagSet']['Tag']['Value']))
+            else:
+                for tag in parsed_xml['Tagging']['TagSet']['Tag']:
+                    tags.append(FakeTag(tag['Key'], tag['Value']))
 
         tag_set = FakeTagSet(tags)
         tagging = FakeTagging(tag_set)


Test patch:
diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py
--- a/tests/test_s3/test_s3.py
+++ b/tests/test_s3/test_s3.py
@@ -1441,6 +1441,19 @@ def test_boto3_put_bucket_tagging():
     bucket_name = "mybucket"
     s3.create_bucket(Bucket=bucket_name)
 
+    # With 1 tag:
+    resp = s3.put_bucket_tagging(Bucket=bucket_name,
+                                 Tagging={
+                                     "TagSet": [
+                                         {
+                                             "Key": "TagOne",
+                                             "Value": "ValueOne"
+                                         }
+                                     ]
+                                 })
+    resp['ResponseMetadata']['HTTPStatusCode'].should.equal(200)
+
+    # With multiple tags:
     resp = s3.put_bucket_tagging(Bucket=bucket_name,
                                  Tagging={
                                      "TagSet": [
Repository: getmoto/moto

Issue:
Question - Authorization header parsing
Am getting an IndexError here - https://github.com/spulec/moto/blob/master/moto/core/responses.py#L171-L172

After debugging im sending `AWS xxx:PDcSm14U3qk7EHxFB01rchMDsME=` which lines up with this - https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html

In this doc - https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-auth-using-authorization-header.html - we should only check for that region part if using a V4 signature.


Discussion:

Resolving patch:
diff --git a/moto/core/responses.py b/moto/core/responses.py
--- a/moto/core/responses.py
+++ b/moto/core/responses.py
@@ -167,7 +167,7 @@ def get_region_from_url(self, request, full_url):
         match = re.search(self.region_regex, full_url)
         if match:
             region = match.group(1)
-        elif 'Authorization' in request.headers:
+        elif 'Authorization' in request.headers and 'AWS4' in request.headers['Authorization']:
             region = request.headers['Authorization'].split(",")[
                 0].split("/")[2]
         else:


Test patch:
Repository: getmoto/moto

Issue:
new PendingDeprecationWarning: Could not find AMI 
Upgrading moto to latest version 1.25

Following snippet was used to create an imageId in moto:
```
        instance = r.create_instances(ImageId='foo', MinCount=1, MaxCount=1)[0]
        c.create_image(InstanceId=instance.id, Name="foo", Description="bar")
        c.terminate_instances(InstanceIds=[instance.id])
```
Now this snippet fails with a deprecation warning:

```
exceptions.PendingDeprecationWarning: Could not find AMI with image-id:foo, in the near future this will cause an error
```
We forbid all deprecation warnings in buildbot code, so we would like to have a new way of doing it which would not trigger the warning.





Discussion:
We've now prepackaged a bunch of image id's and fixed describe_images, if your just after any old image, run [describe_images](https://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Client.describe_images) and pick one of the results.

That helpful? I'll whip up an example when i get to my pc if needed.
@terrycain Sounds good. I'll try that tomorrow. Thanks.
I'd appreciated that explaination in the deprecation message. 
@terrycain I just tried that, and now I have another issue.
The ImageLocation of all those images are equal to None.

```
        amis = list(r.images.all())
        for a in amis:
            print(a.image_location)
```
result:
1.1.24: amazon/getting-started
1.1.25: None

Resolving patch:
diff --git a/moto/ec2/models.py b/moto/ec2/models.py
--- a/moto/ec2/models.py
+++ b/moto/ec2/models.py
@@ -392,7 +392,9 @@ def __init__(self, ec2_backend, image_id, user_data, security_groups, **kwargs):
         if ami is None:
             warnings.warn('Could not find AMI with image-id:{0}, '
                           'in the near future this will '
-                          'cause an error'.format(image_id),
+                          'cause an error.\n'
+                          'Use ec2_backend.describe_images() to'
+                          'find suitable image for your test'.format(image_id),
                           PendingDeprecationWarning)
 
         self.platform = ami.platform if ami else None


Test patch:
Repository: getmoto/moto

Issue:
mock_xray_client cannot be used as a context manager
PR #1255 added support for `aws_xray_sdk` which is great.
But there is a problem with it: `moto.mock_xray_client` is *only* a function decorator, and unlike all other `mock_*` methods it cannot be used as a context manager or directly with `start()`...`stop()`.
As a result, it is not possible to write a `py.test` fixture which would add support for mocking `xray_client`.

Also, `mock_xray_client` does not return the result of the function it decorates. Given it is meant to be used to decorate test functions it is most likely not a big issue, but I think it is still worth fixing.

I will prepare a PR for the return value issue soon.
Also I am thinking about refactoring `mock_xray_client` to base it on the existing infrastructure (`BaseBackend`, `base_decorator`) but am not yet enough familiar with `moto` internals to be sure which would be the best way to implement it.

Installed version: `moto-ext==1.1.25`
The problem seemingly persists in current `master` branch.


Discussion:

Resolving patch:
diff --git a/moto/xray/mock_client.py b/moto/xray/mock_client.py
--- a/moto/xray/mock_client.py
+++ b/moto/xray/mock_client.py
@@ -51,7 +51,7 @@ def _wrapped(*args, **kwargs):
         aws_xray_sdk.core.xray_recorder._emitter = MockEmitter()
 
         try:
-            f(*args, **kwargs)
+            return f(*args, **kwargs)
         finally:
 
             if old_xray_context_var is None:


Test patch:
Repository: getmoto/moto

Issue:
Add opsworks app mocks
Add the mocks of OpsWork create_app and describe_apps calls. This is part of #1477 


Discussion:

Resolving patch:
diff --git a/moto/__init__.py b/moto/__init__.py
--- a/moto/__init__.py
+++ b/moto/__init__.py
@@ -3,7 +3,7 @@
 # logging.getLogger('boto').setLevel(logging.CRITICAL)
 
 __title__ = 'moto'
-__version__ = '1.2.0',
+__version__ = '1.2.0'
 
 from .acm import mock_acm  # flake8: noqa
 from .apigateway import mock_apigateway, mock_apigateway_deprecated  # flake8: noqa


Test patch:
Repository: getmoto/moto

Issue:
ELBv2.create_listener should associate TargetGroup with LB 
If you create a TargetGroup, associate it with a LB via create_listener, and then call describe_target_groups specifying BOTH the load balancer ARN and the target group name,  no target group is returned.  

```python
response = conn.create_target_group(
        Name='a-target',
        Protocol='HTTP',
        Port=8080,
        VpcId=vpc.id)
target_group = response.get('TargetGroups')[0]
conn.create_listener(
        LoadBalancerArn=load_balancer_arn,
        Protocol='HTTP',
        Port=80,
        DefaultActions=[{'Type': 'forward', 'TargetGroupArn': target_group.get('TargetGroupArn')}])
response = conn.describe_target_groups(LoadBalancerArn=load_balancer_arn,
                                                                      Names=['a-target'])
````

The bug is in `create_listener`, which is not adding the load balancer to the target_group's list of load_balancer_arns. I'll submit a PR for this shortly.


Discussion:

Resolving patch:
diff --git a/moto/elbv2/models.py b/moto/elbv2/models.py
--- a/moto/elbv2/models.py
+++ b/moto/elbv2/models.py
@@ -486,6 +486,10 @@ def create_listener(self, load_balancer_arn, protocol, port, ssl_policy, certifi
         arn = load_balancer_arn.replace(':loadbalancer/', ':listener/') + "/%s%s" % (port, id(self))
         listener = FakeListener(load_balancer_arn, arn, protocol, port, ssl_policy, certificate, default_actions)
         balancer.listeners[listener.arn] = listener
+        for action in default_actions:
+            if action['target_group_arn'] in self.target_groups.keys():
+                target_group = self.target_groups[action['target_group_arn']]
+                target_group.load_balancer_arns.append(load_balancer_arn)
         return listener
 
     def describe_load_balancers(self, arns, names):


Test patch:
diff --git a/tests/test_elbv2/test_elbv2.py b/tests/test_elbv2/test_elbv2.py
--- a/tests/test_elbv2/test_elbv2.py
+++ b/tests/test_elbv2/test_elbv2.py
@@ -340,6 +340,10 @@ def test_create_target_group_and_listeners():
         'Type': 'forward'}])
     http_listener_arn = listener.get('ListenerArn')
 
+    response = conn.describe_target_groups(LoadBalancerArn=load_balancer_arn,
+                                           Names=['a-target'])
+    response.get('TargetGroups').should.have.length_of(1)
+
     # And another with SSL
     response = conn.create_listener(
         LoadBalancerArn=load_balancer_arn,
Repository: getmoto/moto

Issue:
SNS does not support new regions
SNS appears to be basing its available regions off of boto2:
```
sns_backends = {}
for region in boto.sns.regions():
    sns_backends[region.name] = SNSBackend(region.name)
```
We will need to move this over to boto3 to support the new regional endpoints.

I'm going to submit a PR for this change.


Discussion:

Resolving patch:
diff --git a/moto/sns/models.py b/moto/sns/models.py
--- a/moto/sns/models.py
+++ b/moto/sns/models.py
@@ -4,11 +4,12 @@
 import uuid
 import json
 
-import boto.sns
 import requests
 import six
 import re
 
+from boto3 import Session
+
 from moto.compat import OrderedDict
 from moto.core import BaseBackend, BaseModel
 from moto.core.utils import iso_8601_datetime_with_milliseconds
@@ -410,8 +411,8 @@ def set_subscription_attributes(self, arn, name, value):
 
 
 sns_backends = {}
-for region in boto.sns.regions():
-    sns_backends[region.name] = SNSBackend(region.name)
+for region in Session().get_available_regions('sns'):
+    sns_backends[region] = SNSBackend(region)
 
 
 DEFAULT_TOPIC_POLICY = {


Test patch: