@@ -539,16 +539,16 @@ func TestAgentSpecificAppProject(t *testing.T) {
539
539
},
540
540
},
541
541
{
542
- name : "no agent name but server is wildcard" ,
542
+ name : "agent name matches wildcard destination " ,
543
543
appProject : v1alpha1.AppProject {
544
544
ObjectMeta : metav1.ObjectMeta {
545
- Name : "empty -project" ,
545
+ Name : "wildcard -project" ,
546
546
Namespace : "argocd" ,
547
547
},
548
548
Spec : v1alpha1.AppProjectSpec {
549
549
Destinations : []v1alpha1.ApplicationDestination {
550
550
{
551
- Server : "*" ,
551
+ Name : "*" ,
552
552
Namespace : "default" ,
553
553
},
554
554
},
@@ -559,7 +559,7 @@ func TestAgentSpecificAppProject(t *testing.T) {
559
559
agent : "test-agent" ,
560
560
want : v1alpha1.AppProject {
561
561
ObjectMeta : metav1.ObjectMeta {
562
- Name : "empty -project" ,
562
+ Name : "wildcard -project" ,
563
563
Namespace : "argocd" ,
564
564
},
565
565
Spec : v1alpha1.AppProjectSpec {
@@ -677,19 +677,7 @@ func TestDoesAgentMatchWithProject(t *testing.T) {
677
677
},
678
678
want : true ,
679
679
},
680
- {
681
- name : "wildcard server with a different name" ,
682
- agentName : "any-agent" ,
683
- appProject : v1alpha1.AppProject {
684
- Spec : v1alpha1.AppProjectSpec {
685
- Destinations : []v1alpha1.ApplicationDestination {
686
- {Name : "different-name" , Server : "*" , Namespace : "default" },
687
- },
688
- SourceNamespaces : []string {"*" },
689
- },
690
- },
691
- want : true , // Should match wildcard server
692
- },
680
+
693
681
{
694
682
name : "agent matches destination name with wildcard" ,
695
683
agentName : "agent-staging" ,
@@ -744,20 +732,7 @@ func TestDoesAgentMatchWithProject(t *testing.T) {
744
732
},
745
733
want : true ,
746
734
},
747
- {
748
- name : "order independence - deny first, then allow" ,
749
- agentName : "prod-agent" ,
750
- appProject : v1alpha1.AppProject {
751
- Spec : v1alpha1.AppProjectSpec {
752
- Destinations : []v1alpha1.ApplicationDestination {
753
- {Name : "!prod-*" , Namespace : "default" }, // Deny prod first
754
- {Name : "*" , Namespace : "default" }, // Allow all
755
- },
756
- SourceNamespaces : []string {"*" },
757
- },
758
- },
759
- want : false , // Same result regardless of order
760
- },
735
+
761
736
{
762
737
name : "agent matches destination but not source namespace" ,
763
738
agentName : "agent-test" ,
@@ -771,61 +746,6 @@ func TestDoesAgentMatchWithProject(t *testing.T) {
771
746
},
772
747
want : false ,
773
748
},
774
- {
775
- name : "agent matches neither destination name nor server" ,
776
- agentName : "agent-nomatch" ,
777
- appProject : v1alpha1.AppProject {
778
- Spec : v1alpha1.AppProjectSpec {
779
- Destinations : []v1alpha1.ApplicationDestination {
780
- {Name : "different-name" , Server : "different-server" , Namespace : "default" },
781
- },
782
- SourceNamespaces : []string {"agent-nomatch" },
783
- },
784
- },
785
- want : false ,
786
- },
787
- {
788
- name : "empty destination name with non-wildcard server" ,
789
- agentName : "any-agent" ,
790
- appProject : v1alpha1.AppProject {
791
- Spec : v1alpha1.AppProjectSpec {
792
- Destinations : []v1alpha1.ApplicationDestination {
793
- {Name : "" , Server : "https://kubernetes.default.svc" , Namespace : "default" },
794
- },
795
- SourceNamespaces : []string {"any-agent" },
796
- },
797
- },
798
- want : false ,
799
- },
800
- {
801
- name : "multiple deny patterns - first match wins" ,
802
- agentName : "prod-sensitive-agent" ,
803
- appProject : v1alpha1.AppProject {
804
- Spec : v1alpha1.AppProjectSpec {
805
- Destinations : []v1alpha1.ApplicationDestination {
806
- {Name : "!prod-*" , Namespace : "default" }, // This matches first
807
- {Name : "!*-sensitive-*" , Namespace : "default" }, // This would also match
808
- {Name : "*" , Namespace : "default" }, // Allow all others
809
- },
810
- SourceNamespaces : []string {"*" },
811
- },
812
- },
813
- want : false ,
814
- },
815
- {
816
- name : "wildcard with deny pattern override" ,
817
- agentName : "admin-user" ,
818
- appProject : v1alpha1.AppProject {
819
- Spec : v1alpha1.AppProjectSpec {
820
- Destinations : []v1alpha1.ApplicationDestination {
821
- {Name : "" , Server : "*" , Namespace : "default" }, // Wildcard allow
822
- {Name : "!admin-*" , Namespace : "default" }, // Deny admin
823
- },
824
- SourceNamespaces : []string {"*" },
825
- },
826
- },
827
- want : false , // Deny overrides wildcard
828
- },
829
749
{
830
750
name : "only deny patterns - no positive match" ,
831
751
agentName : "dev-agent" ,
@@ -840,76 +760,43 @@ func TestDoesAgentMatchWithProject(t *testing.T) {
840
760
want : false , // No positive pattern to match
841
761
},
842
762
{
843
- name : "deny pattern doesn't match - should continue to positive patterns " ,
844
- agentName : "dev-agent " ,
763
+ name : "server URL with exact agent name match " ,
764
+ agentName : "prod-cluster-1 " ,
845
765
appProject : v1alpha1.AppProject {
846
766
Spec : v1alpha1.AppProjectSpec {
847
767
Destinations : []v1alpha1.ApplicationDestination {
848
- {Name : "!prod-*" , Namespace : "default" }, // Deny doesn't match
849
- {Name : "dev-*" , Namespace : "default" }, // Positive matches
768
+ {Name : "" , Server : "https://resource-proxy.example.com:8080?agentName=prod-cluster-1" , Namespace : "default" },
850
769
},
851
770
SourceNamespaces : []string {"*" },
852
771
},
853
772
},
854
- want : true , // Should match positive pattern after deny doesn't match
773
+ want : true , // Agent name matches extracted query parameter
855
774
},
856
775
{
857
- name : "multiple deny patterns none match - positive pattern wins " ,
858
- agentName : "test-agent " ,
776
+ name : "server URL with agent name pattern" ,
777
+ agentName : "prod-cluster-2 " ,
859
778
appProject : v1alpha1.AppProject {
860
779
Spec : v1alpha1.AppProjectSpec {
861
780
Destinations : []v1alpha1.ApplicationDestination {
862
- {Name : "!prod-*" , Namespace : "default" }, // Doesn't match
863
- {Name : "!staging-*" , Namespace : "default" }, // Doesn't match
864
- {Name : "*" , Namespace : "default" }, // Matches
781
+ {Name : "" , Server : "https://resource-proxy.example.com:8080?agentName=prod-cluster-*" , Namespace : "default" },
865
782
},
866
783
SourceNamespaces : []string {"*" },
867
784
},
868
785
},
869
- want : true ,
786
+ want : true , // Agent name matches extracted pattern
870
787
},
871
788
{
872
- name : "mixed destinations with deny pattern " ,
873
- agentName : "dev-agent " ,
789
+ name : "server URL with non-matching agent name " ,
790
+ agentName : "dev-cluster-1 " ,
874
791
appProject : v1alpha1.AppProject {
875
792
Spec : v1alpha1.AppProjectSpec {
876
793
Destinations : []v1alpha1.ApplicationDestination {
877
- {Name : "!admin-*" , Namespace : "default" }, // Name deny (doesn't match)
878
- {Name : "" , Server : "*" , Namespace : "default" }, // Server wildcard
879
- {Name : "dev-*" , Namespace : "default" }, // Name allow (matches)
794
+ {Name : "" , Server : "https://resource-proxy.example.com:8080?agentName=prod-cluster-1" , Namespace : "default" },
880
795
},
881
796
SourceNamespaces : []string {"*" },
882
797
},
883
798
},
884
- want : true , // Should pass deny check and match positive patterns
885
- },
886
-
887
- {
888
- name : "deny pattern in first destination, positive in second" ,
889
- agentName : "prod-cluster" ,
890
- appProject : v1alpha1.AppProject {
891
- Spec : v1alpha1.AppProjectSpec {
892
- Destinations : []v1alpha1.ApplicationDestination {
893
- {Name : "!prod-cluster" , Namespace : "default" }, // Exact deny match
894
- {Name : "*" , Namespace : "default" }, // Would allow all
895
- },
896
- SourceNamespaces : []string {"*" },
897
- },
898
- },
899
- want : false , // Deny pattern matches exactly, should reject immediately
900
- },
901
- {
902
- name : "deny pattern with different namespace requirements" ,
903
- agentName : "restricted-agent" ,
904
- appProject : v1alpha1.AppProject {
905
- Spec : v1alpha1.AppProjectSpec {
906
- Destinations : []v1alpha1.ApplicationDestination {
907
- {Name : "!restricted-*" , Namespace : "default" }, // Deny pattern matches
908
- },
909
- SourceNamespaces : []string {"restricted-agent" }, // Namespace would match
910
- },
911
- },
912
- want : false , // Should be denied even though namespace matches
799
+ want : false , // Agent name doesn't match extracted query parameter
913
800
},
914
801
}
915
802
0 commit comments