From cb88b8783de7732232522eea6f491b53156d9cde Mon Sep 17 00:00:00 2001 From: Joseph Lawson Date: Wed, 15 Oct 2014 13:43:38 -0400 Subject: [PATCH] raise NotImplementedError on unknown metadata path --- moto/core/responses.py | 2 ++ tests/test_core/test_instance_metadata.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/moto/core/responses.py b/moto/core/responses.py index ea6d66ed3..e48f7df9b 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -158,4 +158,6 @@ def metadata_response(request, full_url, headers): result = 'default-role' elif path == 'iam/security-credentials/default-role': result = json.dumps(credentials) + else: + raise NotImplementedError("The {0} metadata path has not been implemented".format(path)) return 200, headers, result diff --git a/tests/test_core/test_instance_metadata.py b/tests/test_core/test_instance_metadata.py index 5e0e76c9a..aa86b41b3 100644 --- a/tests/test_core/test_instance_metadata.py +++ b/tests/test_core/test_instance_metadata.py @@ -1,4 +1,6 @@ from __future__ import unicode_literals +import sure # noqa +from nose.tools import assert_raises import requests from moto import mock_ec2 @@ -35,3 +37,9 @@ def test_meta_data_default_role(): json_response.should.contain('SecretAccessKey') json_response.should.contain('Token') json_response.should.contain('Expiration') + + +@mock_ec2 +def test_meta_data_unknown_path(): + with assert_raises(NotImplementedError): + requests.get("http://169.254.169.254/latest/meta-data/badpath")