@@ -517,6 +517,107 @@ def test_topic_get_attributes_with_fifo_false(self, sns_create_topic, aws_client
517517 )
518518 snapshot .match ("set-fifo-false-after-creation" , e .value .response )
519519
520+ @markers .aws .validated
521+ def test_topic_add_permission (self , sns_create_topic , aws_client , snapshot , account_id ):
522+ topic_arn = sns_create_topic ()["TopicArn" ]
523+ resp = aws_client .sns .add_permission (
524+ TopicArn = topic_arn , Label = "test" , AWSAccountId = [account_id ], ActionName = ["Publish" ]
525+ )
526+ snapshot .match ("add-permission-response" , resp )
527+
528+ attributes_resp = aws_client .sns .get_topic_attributes (TopicArn = topic_arn )
529+ policy_str = attributes_resp ["Attributes" ]["Policy" ]
530+ policy_json = json .loads (policy_str )
531+ snapshot .match ("topic-policy-after-permission" , policy_json )
532+
533+ @markers .aws .validated
534+ def test_topic_add_multiple_permissions (
535+ self , sns_create_topic , aws_client , snapshot , account_id
536+ ):
537+ topic_arn = sns_create_topic ()["TopicArn" ]
538+ resp = aws_client .sns .add_permission (
539+ TopicArn = topic_arn ,
540+ Label = "test" ,
541+ AWSAccountId = [account_id ],
542+ ActionName = ["Publish" , "Subscribe" ],
543+ )
544+ snapshot .match ("add-permission-response" , resp )
545+
546+ attributes_resp = aws_client .sns .get_topic_attributes (TopicArn = topic_arn )
547+ policy_str = attributes_resp ["Attributes" ]["Policy" ]
548+ policy_json = json .loads (policy_str )
549+ snapshot .match ("topic-policy-after-permission" , policy_json )
550+
551+ @markers .aws .validated
552+ def test_topic_remove_permission (self , sns_create_topic , aws_client , snapshot , account_id ):
553+ topic_arn = sns_create_topic ()["TopicArn" ]
554+ label = "test"
555+ aws_client .sns .add_permission (
556+ TopicArn = topic_arn , Label = label , AWSAccountId = [account_id ], ActionName = ["Publish" ]
557+ )
558+
559+ aws_client .sns .remove_permission (TopicArn = topic_arn , Label = label )
560+ attributes_resp = aws_client .sns .get_topic_attributes (TopicArn = topic_arn )
561+ policy_str = attributes_resp ["Attributes" ]["Policy" ]
562+ policy_json = json .loads (policy_str )
563+ snapshot .match ("topic-policy" , policy_json )
564+
565+ @markers .snapshot .skip_snapshot_verify (paths = ["$..Error.Message" ], condition = is_sns_v1_provider )
566+ @markers .aws .validated
567+ def test_add_permission_errors (self , snapshot , aws_client , account_id ):
568+ topic_name = f"topic-{ short_uid ()} "
569+ topic_arn = aws_client .sns .create_topic (Name = topic_name )["TopicArn" ]
570+
571+ aws_client .sns .add_permission (
572+ TopicArn = topic_arn ,
573+ Label = "test" ,
574+ AWSAccountId = [account_id ],
575+ ActionName = ["Publish" ],
576+ )
577+
578+ with pytest .raises (ClientError ) as e :
579+ aws_client .sns .add_permission (
580+ TopicArn = topic_arn ,
581+ Label = "test" ,
582+ AWSAccountId = [account_id ],
583+ ActionName = ["AddPermission" ],
584+ )
585+ snapshot .match ("duplicate-label" , e .value .response )
586+
587+ with pytest .raises (ClientError ) as e :
588+ aws_client .sns .add_permission (
589+ TopicArn = f"{ topic_arn } -not-existing" ,
590+ Label = "test-2" ,
591+ AWSAccountId = [account_id ],
592+ ActionName = ["AddPermission" ],
593+ )
594+ snapshot .match ("topic-not-found" , e .value .response )
595+
596+ with pytest .raises (ClientError ) as e :
597+ aws_client .sns .add_permission (
598+ TopicArn = topic_arn ,
599+ Label = "test-2" ,
600+ AWSAccountId = [account_id ],
601+ ActionName = ["InvalidAction" ],
602+ )
603+ snapshot .match ("invalid-action" , e .value .response )
604+
605+ @markers .aws .validated
606+ def test_remove_permission_errors (self , snapshot , aws_client , account_id ):
607+ topic_name = f"topic-{ short_uid ()} "
608+ topic_arn = aws_client .sns .create_topic (Name = topic_name )["TopicArn" ]
609+ aws_client .sns .add_permission (
610+ TopicArn = topic_arn ,
611+ Label = "test" ,
612+ AWSAccountId = [account_id ],
613+ ActionName = ["Publish" ],
614+ )
615+
616+ with pytest .raises (ClientError ) as e :
617+ aws_client .sns .remove_permission (TopicArn = f"{ topic_arn } -not-existing" , Label = "test" )
618+
619+ snapshot .match ("topic-not-found" , e .value .response )
620+
520621
521622class TestSNSPublishCrud :
522623 """
0 commit comments