@@ -585,55 +585,60 @@ var CheckDeny = check.Or(
585
585
func TestAuthorizationL4 (t * testing.T ) {
586
586
framework .NewTest (t ).Run (func (t framework.TestContext ) {
587
587
t .NewSubTest ("allow" ).Run (func (t framework.TestContext ) {
588
- src := apps .ServiceWithWaypointAtServiceGranularity
588
+ if len (apps .ServiceWithWaypointAtServiceGranularity ) == 0 {
589
+ t .Fatal (fmt .Errorf ("need at least 1 instance of apps.ServiceWithWaypointAtServiceGranularity" ))
590
+ }
591
+ src := apps .ServiceWithWaypointAtServiceGranularity [0 ]
592
+
589
593
clients := src .WorkloadsOrFail (t )
590
594
dst := apps .EnrolledToKmesh
591
595
592
596
addresses := clients .Addresses ()
593
597
if len (addresses ) < 2 {
594
598
t .Fatal (fmt .Errorf ("need at least 2 clients" ))
595
599
}
596
- selectedAddress = addresses [0 ]
600
+ selectedAddress : = addresses [0 ]
597
601
t .ConfigIstio ().Eval (apps .Namespace .Name (), map [string ]string {
598
602
"Destination" : dst .Config ().Service ,
599
- "Namespace" : apps .Namespace .Name (),
600
603
"Ip" : selectedAddress ,
601
- }, `
602
- apiVersion: security.istio.io/v1beta1
604
+ }, `apiVersion: security.istio.io/v1beta1
603
605
kind: AuthorizationPolicy
604
606
metadata:
605
607
name: policy
606
- namespace: "{{ .Namespace }}"
607
608
spec:
608
609
selector:
609
610
matchLabels:
610
- app: "{{ .Destination }}"
611
+ app: "{{.Destination}}"
611
612
action: ALLOW
612
613
rules:
613
614
- from:
614
615
- source:
615
- ipBlocks:
616
- - "{{ .Ip }}"
616
+ ipBlocks:
617
+ - "{{.Ip}}"
617
618
` ).ApplyOrFail (t )
618
619
619
- for _ , clent := range clients {
620
+ for _ , client := range clients {
620
621
opt := echo.CallOptions {
621
622
To : dst ,
622
- Port : echo.Port {Name : "http " },
623
- Scheme : scheme .HTTP ,
623
+ Port : echo.Port {Name : "tcp " },
624
+ Scheme : scheme .TCP ,
624
625
Count : 10 ,
625
626
// Due to the mechanism of Kmesh L4 authorization, we need to set the timeout slightly longer.
626
627
NewConnectionPerRequest : true ,
627
628
Timeout : time .Minute * 2 ,
628
629
Check : check .OK (),
629
630
}
630
631
632
+ fmt .Printf ("--- client.Address() is %v, selectedAddress is %v\n " , client .Address (), selectedAddress )
633
+
631
634
if client .Address () != selectedAddress {
635
+ fmt .Printf ("--- Use CheckDeny\n " )
632
636
opt .Check = CheckDeny
633
637
}
634
638
635
- t .NewSubTestf ("%v" , opt .Scheme ).RunParallel (func (t framework.TestContext ) {
636
- src .WithWorkloads (client ).CallOrFail (t , opt )
639
+ t .NewSubTestf ("%v" , opt .Scheme ).Run (func (t framework.TestContext ) {
640
+ result := src .WithWorkloads (client ).CallOrFail (t , opt )
641
+ fmt .Printf ("-- call result is %v\n " , result .Responses )
637
642
})
638
643
}
639
644
})
0 commit comments