Repository: getmoto/moto

Issue:
cognito-identity: create identity pool does not validate identity pool name
CognitoIdentity doesnt raise a ValidationError when creating an IdentityPool with an invalid IdentityPoolName - 
```
@moto.mock_cognitoidentity
def create_identity_pool():
    cognito_identity.create_identity_pool(
        IdentityPoolName="test-with-identity-pool",
        AllowUnauthenticatedIdentities=False,
        CognitoIdentityProviders=[
            {
                "ProviderName": "x",
                "ClientId": "x",
                "ServerSideTokenCheck": True,
            }
        ],
    )
create_identity_pool()
```
"test-with-identity-pool" is not valid as an IdentityPoolName, 

In AWS this will result in a ValidationError eg;
```
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the CreateIdentityPool operation: 1 validation error detected: Value 'test-with-identity-pool' at 'identityPoolName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\w ]+
```




Discussion:
Thanks; setting as a feature request.

Resolving patch:
diff --git a/moto/cognitoidentity/exceptions.py b/moto/cognitoidentity/exceptions.py
--- a/moto/cognitoidentity/exceptions.py
+++ b/moto/cognitoidentity/exceptions.py
@@ -11,3 +11,17 @@ def __init__(self, message):
         self.description = json.dumps(
             {"message": message, "__type": "ResourceNotFoundException"}
         )
+
+
+class InvalidNameException(BadRequest):
+
+    message = "1 validation error detected: Value '{}' at 'identityPoolName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\w\\s+=,.@-]+"
+
+    def __init__(self, name):
+        super(InvalidNameException, self).__init__()
+        self.description = json.dumps(
+            {
+                "message": InvalidNameException.message.format(name),
+                "__type": "ValidationException",
+            }
+        )
diff --git a/moto/cognitoidentity/models.py b/moto/cognitoidentity/models.py
--- a/moto/cognitoidentity/models.py
+++ b/moto/cognitoidentity/models.py
@@ -2,19 +2,24 @@
 
 import datetime
 import json
+import re
 
 from boto3 import Session
 
 from collections import OrderedDict
 from moto.core import BaseBackend, BaseModel
 from moto.core.utils import iso_8601_datetime_with_milliseconds
-from .exceptions import ResourceNotFoundError
+from .exceptions import InvalidNameException, ResourceNotFoundError
 from .utils import get_random_identity_id
 
 
 class CognitoIdentity(BaseModel):
     def __init__(self, region, identity_pool_name, **kwargs):
         self.identity_pool_name = identity_pool_name
+
+        if not re.fullmatch(r"[\w\s+=,.@-]+", identity_pool_name):
+            raise InvalidNameException(identity_pool_name)
+
         self.allow_unauthenticated_identities = kwargs.get(
             "allow_unauthenticated_identities", ""
         )


Test patch:
diff --git a/tests/test_cognitoidentity/test_cognitoidentity.py b/tests/test_cognitoidentity/test_cognitoidentity.py
--- a/tests/test_cognitoidentity/test_cognitoidentity.py
+++ b/tests/test_cognitoidentity/test_cognitoidentity.py
@@ -11,6 +11,32 @@
 from uuid import UUID
 
 
+@mock_cognitoidentity
+@pytest.mark.parametrize("name", ["pool#name", "with!excl", "with?quest"])
+def test_create_identity_pool_invalid_name(name):
+    conn = boto3.client("cognito-identity", "us-west-2")
+
+    with pytest.raises(ClientError) as exc:
+        conn.create_identity_pool(
+            IdentityPoolName=name, AllowUnauthenticatedIdentities=False
+        )
+    err = exc.value.response["Error"]
+    err["Code"].should.equal("ValidationException")
+    err["Message"].should.equal(
+        f"1 validation error detected: Value '{name}' at 'identityPoolName' failed to satisfy constraint: Member must satisfy regular expression pattern: [\\w\\s+=,.@-]+"
+    )
+
+
+@mock_cognitoidentity
+@pytest.mark.parametrize("name", ["x", "pool-", "pool_name", "with space"])
+def test_create_identity_pool_valid_name(name):
+    conn = boto3.client("cognito-identity", "us-west-2")
+
+    conn.create_identity_pool(
+        IdentityPoolName=name, AllowUnauthenticatedIdentities=False
+    )
+
+
 @mock_cognitoidentity
 def test_create_identity_pool():
     conn = boto3.client("cognito-identity", "us-west-2")