@@ -359,7 +359,7 @@ func TestUnmarshalPolicy(t *testing.T) {
359
359
],
360
360
}
361
361
` ,
362
- wantErr : `AutoGroup is invalid, got: "autogroup:invalid", must be one of [autogroup:internet autogroup:member autogroup:tagged autogroup:nonroot ]` ,
362
+ wantErr : `AutoGroup is invalid, got: "autogroup:invalid", must be one of [autogroup:internet autogroup:member autogroup:nonroot autogroup:tagged ]` ,
363
363
},
364
364
{
365
365
name : "undefined-hostname-errors-2490" ,
@@ -766,85 +766,128 @@ func TestResolvePolicy(t *testing.T) {
766
766
want : []netip.Prefix {tsaddr .AllIPv4 (), tsaddr .AllIPv6 ()},
767
767
},
768
768
{
769
- name : "autogroup-member-basic " ,
769
+ name : "autogroup-member-comprehensive " ,
770
770
toResolve : ptr .To (AutoGroup (AutoGroupMember )),
771
771
nodes : types.Nodes {
772
+ // Node with no tags (should be included)
772
773
{
773
774
User : users ["testuser" ],
774
775
IPv4 : ap ("100.100.101.1" ),
775
776
},
777
+ // Node with forced tags (should be excluded)
776
778
{
777
779
User : users ["testuser" ],
778
780
ForcedTags : []string {"tag:test" },
779
781
IPv4 : ap ("100.100.101.2" ),
780
782
},
783
+ // Node with allowed requested tag (should be excluded)
781
784
{
782
785
User : users ["testuser" ],
783
786
Hostinfo : & tailcfg.Hostinfo {
784
787
RequestTags : []string {"tag:test" },
785
788
},
786
789
IPv4 : ap ("100.100.101.3" ),
787
790
},
791
+ // Node with non-allowed requested tag (should be included)
788
792
{
789
- User : users ["notme" ],
793
+ User : users ["testuser" ],
794
+ Hostinfo : & tailcfg.Hostinfo {
795
+ RequestTags : []string {"tag:notallowed" },
796
+ },
790
797
IPv4 : ap ("100.100.101.4" ),
791
798
},
792
- },
793
- want : []netip.Prefix {mp ("100.100.101.1/32" ), mp ("100.100.101.4/32" )},
794
- },
795
- {
796
- name : "autogroup-member-multiple-users" ,
797
- toResolve : ptr .To (AutoGroup (AutoGroupMember )),
798
- nodes : types.Nodes {
799
- {
800
- User : users ["user1" ],
801
- IPv4 : ap ("100.100.101.1" ),
802
- },
803
- {
804
- User : users ["user2" ],
805
- IPv4 : ap ("100.100.101.2" ),
806
- },
799
+ // Node with multiple requested tags, one allowed (should be excluded)
807
800
{
808
- User : users ["user3" ],
809
- ForcedTags : []string {"tag:test" },
810
- IPv4 : ap ("100.100.101.3" ),
801
+ User : users ["testuser" ],
802
+ Hostinfo : & tailcfg.Hostinfo {
803
+ RequestTags : []string {"tag:test" , "tag:notallowed" },
804
+ },
805
+ IPv4 : ap ("100.100.101.5" ),
811
806
},
807
+ // Node with multiple requested tags, none allowed (should be included)
812
808
{
813
- User : users ["user4 " ],
809
+ User : users ["testuser " ],
814
810
Hostinfo : & tailcfg.Hostinfo {
815
- RequestTags : []string {"tag:test " },
811
+ RequestTags : []string {"tag:notallowed1" , "tag:notallowed2 " },
816
812
},
817
- IPv4 : ap ("100.100.101.4" ),
813
+ IPv4 : ap ("100.100.101.6" ),
814
+ },
815
+ },
816
+ pol : & Policy {
817
+ TagOwners : TagOwners {
818
+ Tag ("tag:test" ): Owners {ptr .To (Username ("testuser@" ))},
818
819
},
819
820
},
820
- want : []netip.Prefix {mp ("100.100.101.1/32" ), mp ("100.100.101.2/32" )},
821
+ want : []netip.Prefix {
822
+ mp ("100.100.101.1/32" ), // No tags
823
+ mp ("100.100.101.4/32" ), // Non-allowed requested tag
824
+ mp ("100.100.101.6/32" ), // Multiple non-allowed requested tags
825
+ },
821
826
},
822
827
{
823
828
name : "autogroup-tagged" ,
824
829
toResolve : ptr .To (AutoGroup (AutoGroupTagged )),
825
830
nodes : types.Nodes {
831
+ // Node with no tags (should be excluded)
826
832
{
827
833
User : users ["testuser" ],
828
834
IPv4 : ap ("100.100.101.1" ),
829
835
},
836
+ // Node with forced tag (should be included)
830
837
{
831
838
User : users ["testuser" ],
832
839
ForcedTags : []string {"tag:test" },
833
840
IPv4 : ap ("100.100.101.2" ),
834
841
},
842
+ // Node with allowed requested tag (should be included)
835
843
{
836
844
User : users ["testuser" ],
837
845
Hostinfo : & tailcfg.Hostinfo {
838
846
RequestTags : []string {"tag:test" },
839
847
},
840
848
IPv4 : ap ("100.100.101.3" ),
841
849
},
850
+ // Node with non-allowed requested tag (should be excluded)
842
851
{
843
- User : users ["notme" ],
852
+ User : users ["testuser" ],
853
+ Hostinfo : & tailcfg.Hostinfo {
854
+ RequestTags : []string {"tag:notallowed" },
855
+ },
844
856
IPv4 : ap ("100.100.101.4" ),
845
857
},
858
+ // Node with multiple requested tags, one allowed (should be included)
859
+ {
860
+ User : users ["testuser" ],
861
+ Hostinfo : & tailcfg.Hostinfo {
862
+ RequestTags : []string {"tag:test" , "tag:notallowed" },
863
+ },
864
+ IPv4 : ap ("100.100.101.5" ),
865
+ },
866
+ // Node with multiple requested tags, none allowed (should be excluded)
867
+ {
868
+ User : users ["testuser" ],
869
+ Hostinfo : & tailcfg.Hostinfo {
870
+ RequestTags : []string {"tag:notallowed1" , "tag:notallowed2" },
871
+ },
872
+ IPv4 : ap ("100.100.101.6" ),
873
+ },
874
+ // Node with multiple forced tags (should be included)
875
+ {
876
+ User : users ["testuser" ],
877
+ ForcedTags : []string {"tag:test" , "tag:other" },
878
+ IPv4 : ap ("100.100.101.7" ),
879
+ },
880
+ },
881
+ pol : & Policy {
882
+ TagOwners : TagOwners {
883
+ Tag ("tag:test" ): Owners {ptr .To (Username ("testuser@" ))},
884
+ },
885
+ },
886
+ want : []netip.Prefix {
887
+ mp ("100.100.101.2/31" ), // Forced tag and allowed requested tag consecutive IPs are put in 31 prefix
888
+ mp ("100.100.101.5/32" ), // Multiple requested tags, one allowed
889
+ mp ("100.100.101.7/32" ), // Multiple forced tags
846
890
},
847
- want : []netip.Prefix {mp ("100.100.101.2/31" )},
848
891
},
849
892
{
850
893
name : "autogroup-invalid" ,
@@ -1013,7 +1056,7 @@ func TestResolveAutoApprovers(t *testing.T) {
1013
1056
name : "mixed-routes-and-exit-nodes" ,
1014
1057
policy : & Policy {
1015
1058
Groups : Groups {
1016
- "group:testgroup" : Usernames {"user1" , "user2" },
1059
+ "group:testgroup" : Usernames {"user1@ " , "user2@ " },
1017
1060
},
1018
1061
AutoApprovers : AutoApproverPolicy {
1019
1062
Routes : map [netip.Prefix ]AutoApprovers {
0 commit comments