Merge pull request #1639 from cpitchford/cpitchford/events_describe_event_bus_policy_json_string

Bugfix: describe_event_bus()['Policy'] should be JSON string, not object
This commit is contained in:
Steve Pulec 2018-05-29 22:31:27 -04:00 committed by GitHub
commit 320056e0c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -1,5 +1,6 @@
import os import os
import re import re
import json
from moto.core.exceptions import JsonRESTError from moto.core.exceptions import JsonRESTError
from moto.core import BaseBackend, BaseModel from moto.core import BaseBackend, BaseModel
@ -238,8 +239,10 @@ class EventsBackend(BaseBackend):
'Action': 'events:{0}'.format(data['action']), 'Action': 'events:{0}'.format(data['action']),
'Resource': arn 'Resource': arn
}) })
policy = {'Version': '2012-10-17', 'Statement': statements}
policy_json = json.dumps(policy)
return { return {
'Policy': {'Version': '2012-10-17', 'Statement': statements}, 'Policy': policy_json,
'Name': 'default', 'Name': 'default',
'Arn': arn 'Arn': arn
} }

View File

@ -1,6 +1,7 @@
import random import random
import boto3 import boto3
import json
from moto.events import mock_events from moto.events import mock_events
from botocore.exceptions import ClientError from botocore.exceptions import ClientError
@ -181,13 +182,15 @@ def test_permissions():
client.put_permission(Action='PutEvents', Principal='222222222222', StatementId='Account2') client.put_permission(Action='PutEvents', Principal='222222222222', StatementId='Account2')
resp = client.describe_event_bus() resp = client.describe_event_bus()
assert len(resp['Policy']['Statement']) == 2 resp_policy = json.loads(resp['Policy'])
assert len(resp_policy['Statement']) == 2
client.remove_permission(StatementId='Account2') client.remove_permission(StatementId='Account2')
resp = client.describe_event_bus() resp = client.describe_event_bus()
assert len(resp['Policy']['Statement']) == 1 resp_policy = json.loads(resp['Policy'])
assert resp['Policy']['Statement'][0]['Sid'] == 'Account1' assert len(resp_policy['Statement']) == 1
assert resp_policy['Statement'][0]['Sid'] == 'Account1'
@mock_events @mock_events