getmoto / moto

A library that allows you to easily mock out tests based on AWS infrastructure.
http://docs.getmoto.org/en/latest/
Apache License 2.0
7.6k stars 2.03k forks source link

API Gateway: query ignored in get_api_keys #8161

Open jbsilva opened 2 days ago

jbsilva commented 2 days ago

As stated in the get_api_keys documentation, the parameter nameQuery is used to filter API Keys by name.

Moto is completely ignoring the query and returning all the keys independently of value passed.

In the following example, the second assert fails because all keys are returned when only the second should match the nameQuery.

Even if nameQuery does not guarantee an exact match, Moto should have a similar behavior to AWS.

import boto3
import pytest
from moto import mock_aws

@pytest.fixture()
def api_gateway_mock():
    with mock_aws():
        ag_client = boto3.client("apigateway")

        ag_client.create_api_key(
            name="123-456",
            description="Mock API key 123-456",
            enabled=True,
            tags={"user": "123"},
        )

        ag_client.create_api_key(
            name="654-321",
            description="Mock API key 654-321",
            enabled=True,
            tags={"user": "654"},
        )

        yield ag_client

def test_get_api_keys(api_gateway_mock):
    all_keys = api_gateway_mock.get_api_keys(limit=10).get("items", [])
    assert len(all_keys) == 2
    key_123 = api_gateway_mock.get_api_keys(nameQuery="123-456", limit=10).get("items", [])
    assert len(key_123) == 1

Moto version: 5.0.15

get_api_keys is marked as implemented in https://docs.getmoto.org/en/latest/docs/services/apigateway.html

DavideRodo commented 1 day ago

same for get_usage_plans for me