Repository: getmoto/moto

Issue:
SQS - send_message should not accept the queue-name as a value
Example code:

```
queue = sqs.Queue(queue_url="queue_name")
queue.send_message(MessageBody="this is a test message")
```

This should fail, as the queue_url-parameter should be the entire URL.
Note: This error should be thrown for every operation, I'm just using `send_message` as an example



Discussion:

Resolving patch:
diff --git a/moto/sqs/exceptions.py b/moto/sqs/exceptions.py
--- a/moto/sqs/exceptions.py
+++ b/moto/sqs/exceptions.py
@@ -138,3 +138,13 @@ def __init__(self, count):
         super(OverLimit, self).__init__(
             "OverLimit", "{} Actions were found, maximum allowed is 7.".format(count)
         )
+
+
+class InvalidAddress(RESTError):
+    code = 400
+
+    def __init__(self, address):
+        super(InvalidAddress, self).__init__(
+            "InvalidAddress",
+            "The address {} is not valid for this endpoint.".format(address),
+        )
diff --git a/moto/sqs/responses.py b/moto/sqs/responses.py
--- a/moto/sqs/responses.py
+++ b/moto/sqs/responses.py
@@ -14,6 +14,7 @@
 
 from .exceptions import (
     EmptyBatchRequest,
+    InvalidAddress,
     InvalidAttributeName,
     MessageNotInflight,
     ReceiptHandleIsInvalid,
@@ -51,11 +52,14 @@ def tags(self):
 
     def _get_queue_name(self):
         try:
-            queue_name = self.querystring.get("QueueUrl")[0].split("/")[-1]
+            queue_url = self.querystring.get("QueueUrl")[0]
+            if queue_url.startswith("http://") or queue_url.startswith("https://"):
+                return queue_url.split("/")[-1]
+            else:
+                raise InvalidAddress(queue_url)
         except TypeError:
-            # Fallback to reading from the URL
-            queue_name = self.path.split("/")[-1]
-        return queue_name
+            # Fallback to reading from the URL for botocore
+            return self.path.split("/")[-1]
 
     def _get_validated_visibility_timeout(self, timeout=None):
         """


Test patch:
diff --git a/tests/test_sqs/test_sqs.py b/tests/test_sqs/test_sqs.py
--- a/tests/test_sqs/test_sqs.py
+++ b/tests/test_sqs/test_sqs.py
@@ -311,20 +311,15 @@ def test_get_queue_url_error_not_exists():
 @mock_sqs
 def test_get_nonexistent_queue():
     sqs = boto3.resource("sqs", region_name="us-east-1")
-    with pytest.raises(ClientError) as err:
-        sqs.get_queue_by_name(QueueName="non-existing-queue")
-    ex = err.value
-    ex.operation_name.should.equal("GetQueueUrl")
-    ex.response["Error"]["Code"].should.equal("AWS.SimpleQueueService.NonExistentQueue")
-    ex.response["Error"]["Message"].should.equal(
-        "The specified queue does not exist for this wsdl version."
-    )
 
     with pytest.raises(ClientError) as err:
         sqs.Queue("http://whatever-incorrect-queue-address").load()
     ex = err.value
     ex.operation_name.should.equal("GetQueueAttributes")
     ex.response["Error"]["Code"].should.equal("AWS.SimpleQueueService.NonExistentQueue")
+    ex.response["Error"]["Message"].should.equal(
+        "The specified queue does not exist for this wsdl version."
+    )
 
 
 @mock_sqs
@@ -633,8 +628,10 @@ def test_get_queue_with_prefix():
 def test_delete_queue():
     sqs = boto3.resource("sqs", region_name="us-east-1")
     conn = boto3.client("sqs", region_name="us-east-1")
-    conn.create_queue(QueueName="test-queue", Attributes={"VisibilityTimeout": "3"})
-    queue = sqs.Queue("test-queue")
+    q_resp = conn.create_queue(
+        QueueName="test-queue", Attributes={"VisibilityTimeout": "3"}
+    )
+    queue = sqs.Queue(q_resp["QueueUrl"])
 
     conn.list_queues()["QueueUrls"].should.have.length_of(1)
 
@@ -775,13 +772,15 @@ def test_get_queue_attributes_error_not_exists():
 def test_set_queue_attribute():
     sqs = boto3.resource("sqs", region_name="us-east-1")
     conn = boto3.client("sqs", region_name="us-east-1")
-    conn.create_queue(QueueName="test-queue", Attributes={"VisibilityTimeout": "3"})
+    q_resp = conn.create_queue(
+        QueueName="test-queue", Attributes={"VisibilityTimeout": "3"}
+    )
 
-    queue = sqs.Queue("test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
     queue.attributes["VisibilityTimeout"].should.equal("3")
 
     queue.set_attributes(Attributes={"VisibilityTimeout": "45"})
-    queue = sqs.Queue("test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
     queue.attributes["VisibilityTimeout"].should.equal("45")
 
 
@@ -789,8 +788,8 @@ def test_set_queue_attribute():
 def test_send_receive_message_without_attributes():
     sqs = boto3.resource("sqs", region_name="us-east-1")
     conn = boto3.client("sqs", region_name="us-east-1")
-    conn.create_queue(QueueName="test-queue")
-    queue = sqs.Queue("test-queue")
+    q_resp = conn.create_queue(QueueName="test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
 
     body_one = "this is a test message"
     body_two = "this is another test message"
@@ -819,8 +818,8 @@ def test_send_receive_message_without_attributes():
 def test_send_receive_message_with_attributes():
     sqs = boto3.resource("sqs", region_name="us-east-1")
     conn = boto3.client("sqs", region_name="us-east-1")
-    conn.create_queue(QueueName="test-queue")
-    queue = sqs.Queue("test-queue")
+    q_resp = conn.create_queue(QueueName="test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
 
     body_one = "this is a test message"
     body_two = "this is another test message"
@@ -861,8 +860,8 @@ def test_send_receive_message_with_attributes():
 def test_send_receive_message_with_attributes_with_labels():
     sqs = boto3.resource("sqs", region_name="us-east-1")
     conn = boto3.client("sqs", region_name="us-east-1")
-    conn.create_queue(QueueName="test-queue")
-    queue = sqs.Queue("test-queue")
+    q_resp = conn.create_queue(QueueName="test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
 
     body_one = "this is a test message"
     body_two = "this is another test message"
@@ -925,8 +924,8 @@ def test_change_message_visibility_than_permitted():
     conn = boto3.client("sqs", region_name="us-east-1")
 
     with freeze_time("2015-01-01 12:00:00"):
-        conn.create_queue(QueueName="test-queue-visibility")
-        queue = sqs.Queue("test-queue-visibility")
+        q_resp = conn.create_queue(QueueName="test-queue-visibility")
+        queue = sqs.Queue(q_resp["QueueUrl"])
         queue.send_message(MessageBody="derp")
         messages = conn.receive_message(QueueUrl=queue.url)
         messages.get("Messages").should.have.length_of(1)
@@ -955,8 +954,8 @@ def test_change_message_visibility_than_permitted():
 def test_send_receive_message_timestamps():
     sqs = boto3.resource("sqs", region_name="us-east-1")
     conn = boto3.client("sqs", region_name="us-east-1")
-    conn.create_queue(QueueName="test-queue")
-    queue = sqs.Queue("test-queue")
+    q_resp = conn.create_queue(QueueName="test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
 
     response = queue.send_message(MessageBody="derp")
     assert response["ResponseMetadata"]["RequestId"]
@@ -1053,8 +1052,8 @@ def test_send_receive_message_timestamps():
 def test_send_receive_message_with_attribute_name(attribute_name, expected):
     sqs = boto3.resource("sqs", region_name="us-east-1")
     client = boto3.client("sqs", region_name="us-east-1")
-    client.create_queue(QueueName="test-queue")
-    queue = sqs.Queue("test-queue")
+    q_resp = client.create_queue(QueueName="test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
 
     body_one = "this is a test message"
     body_two = "this is another test message"
@@ -1862,8 +1861,8 @@ def test_delete_message_batch_with_duplicates():
 def test_message_attributes_in_receive_message():
     sqs = boto3.resource("sqs", region_name="us-east-1")
     conn = boto3.client("sqs", region_name="us-east-1")
-    conn.create_queue(QueueName="test-queue")
-    queue = sqs.Queue("test-queue")
+    q_resp = conn.create_queue(QueueName="test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
 
     body_one = "this is a test message"
 
@@ -2918,12 +2917,40 @@ def test_fifo_send_message_when_same_group_id_is_in_dlq():
     messages.should.have.length_of(1)
 
 
+@mock_sqs
+def test_receive_message_should_not_accept_invalid_urls():
+    sqs = boto3.resource("sqs", region_name="us-east-1")
+    conn = boto3.client("sqs", region_name="us-east-1")
+    name = "test-queue"
+    q_response = conn.create_queue(QueueName=name)
+    working_url = q_response[
+        "QueueUrl"
+    ]  # https://queue.amazonaws.com/486285699788/test-queue
+
+    queue = sqs.Queue(name)
+    with pytest.raises(ClientError) as e:
+        queue.send_message(MessageBody="this is a test message")
+    err = e.value.response["Error"]
+    err["Code"].should.equal("InvalidAddress")
+    err["Message"].should.equal(
+        "The address test-queue is not valid for this endpoint."
+    )
+
+    with pytest.raises(ClientError) as e:
+        conn.receive_message(QueueUrl=name)
+    err = e.value.response["Error"]
+    err["Code"].should.equal("InvalidAddress")
+    err["Message"].should.equal(
+        "The address test-queue is not valid for this endpoint."
+    )
+
+
 @mock_sqs
 def test_message_attributes_contains_trace_header():
     sqs = boto3.resource("sqs", region_name="us-east-1")
     conn = boto3.client("sqs", region_name="us-east-1")
-    conn.create_queue(QueueName="test-queue")
-    queue = sqs.Queue("test-queue")
+    q_resp = conn.create_queue(QueueName="test-queue")
+    queue = sqs.Queue(q_resp["QueueUrl"])
     body_one = "this is a test message"
 
     queue.send_message(