| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | import boto3 | 
					
						
							|  |  |  | import pytest | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from moto import mock_iot | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_create_domain_configuration_only_name(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     domain_config = client.create_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert domain_config["domainConfigurationName"] == "testConfig" | 
					
						
							|  |  |  |     assert domain_config["domainConfigurationArn"] is not None | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_create_duplicate_domain_configuration_fails(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     domain_config = client.create_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert domain_config["domainConfigurationName"] == "testConfig" | 
					
						
							|  |  |  |     assert domain_config["domainConfigurationArn"] is not None | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  |     with pytest.raises(client.exceptions.ResourceAlreadyExistsException) as exc: | 
					
						
							|  |  |  |         client.create_domain_configuration(domainConfigurationName="testConfig") | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert err["Code"] == "ResourceAlreadyExistsException" | 
					
						
							|  |  |  |     assert err["Message"] == "Domain configuration with given name already exists." | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_create_domain_configuration_full_params(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     domain_config = client.create_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig", | 
					
						
							|  |  |  |         domainName="example.com", | 
					
						
							|  |  |  |         serverCertificateArns=["ARN1", "ARN2"], | 
					
						
							|  |  |  |         validationCertificateArn="VARN", | 
					
						
							|  |  |  |         authorizerConfig={ | 
					
						
							|  |  |  |             "defaultAuthorizerName": "name", | 
					
						
							|  |  |  |             "allowAuthorizerOverride": True, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         serviceType="DATA", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert domain_config["domainConfigurationName"] == "testConfig" | 
					
						
							|  |  |  |     assert domain_config["domainConfigurationArn"] is not None | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_create_domain_configuration_invalid_service_type(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     with pytest.raises(client.exceptions.InvalidRequestException) as exc: | 
					
						
							|  |  |  |         client.create_domain_configuration( | 
					
						
							|  |  |  |             domainConfigurationName="testConfig", serviceType="INVALIDTYPE" | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert err["Code"] == "InvalidRequestException" | 
					
						
							|  |  |  |     assert ( | 
					
						
							|  |  |  |         err["Message"] | 
					
						
							|  |  |  |         == "An error occurred (InvalidRequestException) when calling the DescribeDomainConfiguration operation: Service type INVALIDTYPE not recognized." | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_describe_nonexistent_domain_configuration(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     with pytest.raises(client.exceptions.ResourceNotFoundException) as exc: | 
					
						
							|  |  |  |         client.describe_domain_configuration(domainConfigurationName="doesntExist") | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert err["Code"] == "ResourceNotFoundException" | 
					
						
							|  |  |  |     assert err["Message"] == "The specified resource does not exist." | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_describe_domain_configuration(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     client.create_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig", | 
					
						
							|  |  |  |         domainName="example.com", | 
					
						
							|  |  |  |         serverCertificateArns=["ARN1", "ARN2"], | 
					
						
							|  |  |  |         validationCertificateArn="VARN", | 
					
						
							|  |  |  |         authorizerConfig={ | 
					
						
							|  |  |  |             "defaultAuthorizerName": "name", | 
					
						
							|  |  |  |             "allowAuthorizerOverride": True, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         serviceType="DATA", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     described_config = client.describe_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig" | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert described_config["domainConfigurationName"] == "testConfig" | 
					
						
							|  |  |  |     assert described_config["domainConfigurationArn"] | 
					
						
							|  |  |  |     assert described_config["serverCertificates"] | 
					
						
							|  |  |  |     assert described_config["authorizerConfig"] | 
					
						
							|  |  |  |     assert described_config["domainConfigurationStatus"] == "ENABLED" | 
					
						
							|  |  |  |     assert described_config["serviceType"] == "DATA" | 
					
						
							|  |  |  |     assert described_config["domainType"] | 
					
						
							|  |  |  |     assert described_config["lastStatusChangeDate"] | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_update_domain_configuration(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig", | 
					
						
							|  |  |  |         domainName="example.com", | 
					
						
							|  |  |  |         serverCertificateArns=["ARN1", "ARN2"], | 
					
						
							|  |  |  |         validationCertificateArn="VARN", | 
					
						
							|  |  |  |         authorizerConfig={ | 
					
						
							|  |  |  |             "defaultAuthorizerName": "name", | 
					
						
							|  |  |  |             "allowAuthorizerOverride": True, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         serviceType="DATA", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     client.update_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig", | 
					
						
							|  |  |  |         authorizerConfig={ | 
					
						
							|  |  |  |             "defaultAuthorizerName": "updatedName", | 
					
						
							|  |  |  |             "allowAuthorizerOverride": False, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         domainConfigurationStatus="DISABLED", | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     updated = client.describe_domain_configuration(domainConfigurationName="testConfig") | 
					
						
							|  |  |  |     assert updated["authorizerConfig"]["defaultAuthorizerName"] == "updatedName" | 
					
						
							|  |  |  |     assert updated["authorizerConfig"]["allowAuthorizerOverride"] is False | 
					
						
							|  |  |  |     assert updated["domainConfigurationStatus"] == "DISABLED" | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_update_domain_configuration_remove_authorizer_type(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig", | 
					
						
							|  |  |  |         domainName="example.com", | 
					
						
							|  |  |  |         serverCertificateArns=["ARN1", "ARN2"], | 
					
						
							|  |  |  |         validationCertificateArn="VARN", | 
					
						
							|  |  |  |         authorizerConfig={ | 
					
						
							|  |  |  |             "defaultAuthorizerName": "name", | 
					
						
							|  |  |  |             "allowAuthorizerOverride": True, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         serviceType="DATA", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     client.update_domain_configuration( | 
					
						
							|  |  |  |         domainConfigurationName="testConfig", removeAuthorizerConfig=True | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     config = client.describe_domain_configuration(domainConfigurationName="testConfig") | 
					
						
							|  |  |  |     assert "authorizerConfig" not in config | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_update_nonexistent_domain_configuration(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     with pytest.raises(client.exceptions.ResourceNotFoundException) as exc: | 
					
						
							|  |  |  |         client.update_domain_configuration(domainConfigurationName="doesntExist") | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert err["Code"] == "ResourceNotFoundException" | 
					
						
							|  |  |  |     assert err["Message"] == "The specified resource does not exist." | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_list_domain_configuration(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_domain_configuration(domainConfigurationName="testConfig1") | 
					
						
							|  |  |  |     client.create_domain_configuration(domainConfigurationName="testConfig2") | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     domain_configs = client.list_domain_configurations()["domainConfigurations"] | 
					
						
							|  |  |  |     assert len(domain_configs) == 2 | 
					
						
							|  |  |  |     assert domain_configs[0]["domainConfigurationName"] == "testConfig1" | 
					
						
							|  |  |  |     assert domain_configs[1]["domainConfigurationName"] == "testConfig2" | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_delete_domain_configuration(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     client.create_domain_configuration(domainConfigurationName="testConfig") | 
					
						
							|  |  |  |     domain_configs = client.list_domain_configurations() | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert len(domain_configs["domainConfigurations"]) == 1 | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  |     client.delete_domain_configuration(domainConfigurationName="testConfig") | 
					
						
							|  |  |  |     domain_configs = client.list_domain_configurations() | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert len(domain_configs["domainConfigurations"]) == 0 | 
					
						
							| 
									
										
										
										
											2021-12-22 14:41:34 -01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_iot | 
					
						
							|  |  |  | def test_delete_nonexistent_domain_configuration(): | 
					
						
							|  |  |  |     client = boto3.client("iot", region_name="us-east-1") | 
					
						
							|  |  |  |     with pytest.raises(client.exceptions.ResourceNotFoundException) as exc: | 
					
						
							|  |  |  |         client.delete_domain_configuration(domainConfigurationName="doesntExist") | 
					
						
							|  |  |  |     err = exc.value.response["Error"] | 
					
						
							| 
									
										
										
										
											2023-07-31 21:50:24 +00:00
										 |  |  |     assert err["Code"] == "ResourceNotFoundException" | 
					
						
							|  |  |  |     assert err["Message"] == "The specified resource does not exist." |