@@ -595,3 +595,79 @@ 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" , token_sha512 = dummy_proxy_environment_token_sha512
616+ )
617+ assert "Either 'zones' must be non-empty or 'global_read_only' must be True" in str (
618+ err .value
619+ )
620+
621+
622+ def test_environment_with_empty_zones_and_no_global_read_only_fails ():
623+ """Test that explicitly providing empty zones without global_read_only fails"""
624+ with pytest .raises (ValueError ) as err :
625+ ProxyConfigEnvironment (
626+ name = "test" , token_sha512 = dummy_proxy_environment_token_sha512 , zones = []
627+ )
628+ assert "Either 'zones' must be non-empty or 'global_read_only' must be True" in str (
629+ err .value
630+ )
631+
632+
633+ def test_proxy_config_with_global_read_only_environment ():
634+ """Test that ProxyConfig works with global_read_only environment without zones"""
635+ config = ProxyConfig (
636+ pdns_api_url = "https://powerdns-api.example.com" ,
637+ pdns_api_token = "blablub" ,
638+ environments = [
639+ ProxyConfigEnvironment (
640+ name = "foo" ,
641+ token_sha512 = dummy_proxy_environment_token_sha512 ,
642+ global_read_only = True ,
643+ )
644+ ],
645+ )
646+ assert config .environments [0 ].global_read_only is True
647+ assert config .environments [0 ].zones == []
648+
649+
650+ def test_global_read_only_with_explicit_zones_keeps_zone_permissions ():
651+ """Test that global_read_only=True doesn't force explicit zones to be read_only"""
652+ # Create a zone that should remain writable
653+ writable_zone = ProxyConfigZone (name = "example.com" , read_only = False )
654+ readonly_zone = ProxyConfigZone (name = "readonly.com" , read_only = True )
655+
656+ env = ProxyConfigEnvironment (
657+ name = "Test Global Read Only with Zones" ,
658+ token_sha512 = dummy_proxy_environment_token_sha512 ,
659+ zones = [writable_zone , readonly_zone ],
660+ global_read_only = True ,
661+ )
662+
663+ # global_read_only should be True
664+ assert env .global_read_only is True
665+
666+ # But explicit zones should keep their original read_only settings
667+ assert env .zones [0 ].read_only is False # writable_zone should remain writable
668+ assert env .zones [1 ].read_only is True # readonly_zone should remain read_only
669+
670+ # Should have access to zones via lookup
671+ assert len (env ._zones_lookup ) == 2
672+ assert "example.com" in env ._zones_lookup
673+ assert "readonly.com" in env ._zones_lookup
0 commit comments