@@ -595,3 +595,52 @@ def test_tsigkeys_allowed_globally():
595595 environment = deepcopy (dummy_proxy_environment )
596596 environment .global_tsigkeys = True
597597 assert check_pdns_tsigkeys_allowed (environment ) is True
598+
599+
600+ def test_global_read_only_without_zones ():
601+ """Test that global_read_only=True allows empty zones list"""
602+ env = ProxyConfigEnvironment (
603+ name = "Test Global Read Only" ,
604+ token_sha512 = dummy_proxy_environment_token_sha512 ,
605+ global_read_only = True
606+ )
607+ assert env .global_read_only is True
608+ assert env .zones == []
609+
610+
611+ def test_environment_with_neither_zones_nor_global_read_only_fails ():
612+ """Test that providing neither zones nor global_read_only fails validation"""
613+ with pytest .raises (ValueError ) as err :
614+ ProxyConfigEnvironment (
615+ name = "test" ,
616+ token_sha512 = dummy_proxy_environment_token_sha512
617+ )
618+ assert "Either 'zones' must be non-empty or 'global_read_only' must be True" in str (err .value )
619+
620+
621+ def test_environment_with_empty_zones_and_no_global_read_only_fails ():
622+ """Test that explicitly providing empty zones without global_read_only fails"""
623+ with pytest .raises (ValueError ) as err :
624+ ProxyConfigEnvironment (
625+ name = "test" ,
626+ token_sha512 = dummy_proxy_environment_token_sha512 ,
627+ zones = []
628+ )
629+ assert "Either 'zones' must be non-empty or 'global_read_only' must be True" in str (err .value )
630+
631+
632+ def test_proxy_config_with_global_read_only_environment ():
633+ """Test that ProxyConfig works with global_read_only environment without zones"""
634+ config = ProxyConfig (
635+ pdns_api_url = "https://powerdns-api.example.com" ,
636+ pdns_api_token = "blablub" ,
637+ environments = [
638+ ProxyConfigEnvironment (
639+ name = "foo" ,
640+ token_sha512 = dummy_proxy_environment_token_sha512 ,
641+ global_read_only = True
642+ )
643+ ]
644+ )
645+ assert config .environments [0 ].global_read_only is True
646+ assert config .environments [0 ].zones == []
0 commit comments