4
4
"fmt"
5
5
"reflect"
6
6
"testing"
7
+ "time"
7
8
8
9
mapset "github.com/deckarep/golang-set"
9
10
"github.com/golang/mock/gomock"
@@ -15,6 +16,7 @@ import (
15
16
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
17
17
18
policyv1alpha1 "github.com/openservicemesh/osm/pkg/apis/policy/v1alpha1"
19
+ tresorFake "github.com/openservicemesh/osm/pkg/certificate/providers/tresor/fake"
18
20
19
21
"github.com/openservicemesh/osm/pkg/configurator"
20
22
"github.com/openservicemesh/osm/pkg/endpoint"
@@ -168,10 +170,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
168
170
Weight : 100 ,
169
171
}),
170
172
},
171
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
173
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
172
174
Name : "sa2" ,
173
175
Namespace : "ns2" ,
174
- }.ToServiceIdentity ( )),
176
+ }.AsPrincipal ( "cluster.local" )),
175
177
},
176
178
},
177
179
},
@@ -207,10 +209,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
207
209
Weight : 100 ,
208
210
}),
209
211
},
210
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
212
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
211
213
Name : "sa2" ,
212
214
Namespace : "ns2" ,
213
- }.ToServiceIdentity ( )),
215
+ }.AsPrincipal ( "cluster.local" )),
214
216
},
215
217
},
216
218
},
@@ -473,10 +475,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
473
475
Weight : 100 ,
474
476
}),
475
477
},
476
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
478
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
477
479
Name : "sa2" ,
478
480
Namespace : "ns2" ,
479
- }.ToServiceIdentity ( )),
481
+ }.AsPrincipal ( "cluster.local" )),
480
482
},
481
483
{
482
484
Route : trafficpolicy.RouteWeightedClusters {
@@ -493,10 +495,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
493
495
Weight : 100 ,
494
496
}),
495
497
},
496
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
498
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
497
499
Name : "sa2" ,
498
500
Namespace : "ns2" ,
499
- }.ToServiceIdentity ( )),
501
+ }.AsPrincipal ( "cluster.local" )),
500
502
},
501
503
},
502
504
},
@@ -532,10 +534,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
532
534
Weight : 100 ,
533
535
}),
534
536
},
535
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
537
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
536
538
Name : "sa2" ,
537
539
Namespace : "ns2" ,
538
- }.ToServiceIdentity ( )),
540
+ }.AsPrincipal ( "cluster.local" )),
539
541
},
540
542
{
541
543
Route : trafficpolicy.RouteWeightedClusters {
@@ -552,10 +554,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
552
554
Weight : 100 ,
553
555
}),
554
556
},
555
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
557
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
556
558
Name : "sa2" ,
557
559
Namespace : "ns2" ,
558
- }.ToServiceIdentity ( )),
560
+ }.AsPrincipal ( "cluster.local" )),
559
561
},
560
562
},
561
563
},
@@ -721,10 +723,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
721
723
Weight : 100 ,
722
724
}),
723
725
},
724
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
726
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
725
727
Name : "sa2" ,
726
728
Namespace : "ns2" ,
727
- }.ToServiceIdentity ( )),
729
+ }.AsPrincipal ( "cluster.local" )),
728
730
},
729
731
},
730
732
},
@@ -758,10 +760,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
758
760
Weight : 100 ,
759
761
}),
760
762
},
761
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
763
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
762
764
Name : "sa2" ,
763
765
Namespace : "ns2" ,
764
- }.ToServiceIdentity ( )),
766
+ }.AsPrincipal ( "cluster.local" )),
765
767
},
766
768
},
767
769
},
@@ -797,10 +799,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
797
799
Weight : 100 ,
798
800
}),
799
801
},
800
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
802
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
801
803
Name : "sa2" ,
802
804
Namespace : "ns2" ,
803
- }.ToServiceIdentity ( )),
805
+ }.AsPrincipal ( "cluster.local" )),
804
806
},
805
807
},
806
808
},
@@ -914,7 +916,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
914
916
Weight : 100 ,
915
917
}),
916
918
},
917
- AllowedServiceIdentities : mapset .NewSet (identity .WildcardServiceIdentity ),
919
+ AllowedPrincipals : mapset .NewSet (identity .WildcardPrincipal ),
918
920
},
919
921
},
920
922
},
@@ -941,7 +943,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
941
943
Weight : 100 ,
942
944
}),
943
945
},
944
- AllowedServiceIdentities : mapset .NewSet (identity .WildcardServiceIdentity ),
946
+ AllowedPrincipals : mapset .NewSet (identity .WildcardPrincipal ),
945
947
},
946
948
},
947
949
},
@@ -970,7 +972,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
970
972
Weight : 100 ,
971
973
}),
972
974
},
973
- AllowedServiceIdentities : mapset .NewSet (identity .WildcardServiceIdentity ),
975
+ AllowedPrincipals : mapset .NewSet (identity .WildcardPrincipal ),
974
976
},
975
977
},
976
978
},
@@ -1116,10 +1118,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1116
1118
Weight : 100 ,
1117
1119
}),
1118
1120
},
1119
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
1120
- Name : "sa2" ,
1121
- Namespace : "ns2" ,
1122
- }.ToServiceIdentity ()),
1121
+ AllowedPrincipals : mapset .NewSet ("sa2.ns2.cluster.local" ),
1123
1122
},
1124
1123
},
1125
1124
},
@@ -1287,15 +1286,15 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1287
1286
Weight : 100 ,
1288
1287
}),
1289
1288
},
1290
- AllowedServiceIdentities : mapset .NewSet (
1289
+ AllowedPrincipals : mapset .NewSet (
1291
1290
identity.K8sServiceAccount {
1292
1291
Name : "sa2" ,
1293
1292
Namespace : "ns2" ,
1294
- }.ToServiceIdentity ( ),
1293
+ }.AsPrincipal ( "cluster.local" ),
1295
1294
identity.K8sServiceAccount {
1296
1295
Name : "sa3" ,
1297
1296
Namespace : "ns3" ,
1298
- }.ToServiceIdentity ( )),
1297
+ }.AsPrincipal ( "cluster.local" )),
1299
1298
},
1300
1299
},
1301
1300
},
@@ -1331,15 +1330,15 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1331
1330
Weight : 100 ,
1332
1331
}),
1333
1332
},
1334
- AllowedServiceIdentities : mapset .NewSet (
1333
+ AllowedPrincipals : mapset .NewSet (
1335
1334
identity.K8sServiceAccount {
1336
1335
Name : "sa2" ,
1337
1336
Namespace : "ns2" ,
1338
- }.ToServiceIdentity ( ),
1337
+ }.AsPrincipal ( "cluster.local" ),
1339
1338
identity.K8sServiceAccount {
1340
1339
Name : "sa3" ,
1341
1340
Namespace : "ns3" ,
1342
- }.ToServiceIdentity ( )),
1341
+ }.AsPrincipal ( "cluster.local" )),
1343
1342
},
1344
1343
},
1345
1344
},
@@ -1503,10 +1502,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1503
1502
Weight : 100 ,
1504
1503
}),
1505
1504
},
1506
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
1505
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
1507
1506
Name : "sa2" ,
1508
1507
Namespace : "ns2" ,
1509
- }.ToServiceIdentity ( )),
1508
+ }.AsPrincipal ( "cluster.local" )),
1510
1509
},
1511
1510
},
1512
1511
},
@@ -1542,10 +1541,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1542
1541
Weight : 100 ,
1543
1542
}),
1544
1543
},
1545
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
1544
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
1546
1545
Name : "sa2" ,
1547
1546
Namespace : "ns2" ,
1548
- }.ToServiceIdentity ( )),
1547
+ }.AsPrincipal ( "cluster.local" )),
1549
1548
},
1550
1549
},
1551
1550
},
@@ -1653,7 +1652,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1653
1652
Weight : 100 ,
1654
1653
}),
1655
1654
},
1656
- AllowedServiceIdentities : mapset .NewSet (identity .WildcardServiceIdentity ),
1655
+ AllowedPrincipals : mapset .NewSet (identity .WildcardPrincipal ),
1657
1656
},
1658
1657
},
1659
1658
},
@@ -1680,7 +1679,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1680
1679
Weight : 100 ,
1681
1680
}),
1682
1681
},
1683
- AllowedServiceIdentities : mapset .NewSet (identity .WildcardServiceIdentity ),
1682
+ AllowedPrincipals : mapset .NewSet (identity .WildcardPrincipal ),
1684
1683
},
1685
1684
},
1686
1685
},
@@ -1825,10 +1824,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1825
1824
}),
1826
1825
RateLimit : perRouteRateLimitConfig ,
1827
1826
},
1828
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
1827
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
1829
1828
Name : "sa2" ,
1830
1829
Namespace : "ns2" ,
1831
- }.ToServiceIdentity ( )),
1830
+ }.AsPrincipal ( "cluster.local" )),
1832
1831
},
1833
1832
},
1834
1833
},
@@ -1866,10 +1865,10 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1866
1865
}),
1867
1866
RateLimit : perRouteRateLimitConfig ,
1868
1867
},
1869
- AllowedServiceIdentities : mapset .NewSet (identity.K8sServiceAccount {
1868
+ AllowedPrincipals : mapset .NewSet (identity.K8sServiceAccount {
1870
1869
Name : "sa2" ,
1871
1870
Namespace : "ns2" ,
1872
- }.ToServiceIdentity ( )),
1871
+ }.AsPrincipal ( "cluster.local" )),
1873
1872
},
1874
1873
},
1875
1874
},
@@ -1953,7 +1952,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1953
1952
}),
1954
1953
RateLimit : perRouteRateLimitConfig ,
1955
1954
},
1956
- AllowedServiceIdentities : mapset .NewSet (identity .WildcardServiceIdentity ),
1955
+ AllowedPrincipals : mapset .NewSet (identity .WildcardPrincipal ),
1957
1956
},
1958
1957
},
1959
1958
},
@@ -1984,7 +1983,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
1984
1983
}),
1985
1984
RateLimit : perRouteRateLimitConfig ,
1986
1985
},
1987
- AllowedServiceIdentities : mapset .NewSet (identity .WildcardServiceIdentity ),
1986
+ AllowedPrincipals : mapset .NewSet (identity .WildcardPrincipal ),
1988
1987
},
1989
1988
},
1990
1989
},
@@ -2014,6 +2013,8 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
2014
2013
mockCtrl := gomock .NewController (t )
2015
2014
defer mockCtrl .Finish ()
2016
2015
2016
+ fakeCertManager := tresorFake .NewFake (nil , 1 * time .Hour )
2017
+
2017
2018
mockKubeController := k8s .NewMockController (mockCtrl )
2018
2019
mockPolicyController := policy .NewMockController (mockCtrl )
2019
2020
mockEndpointProvider := endpoint .NewMockProvider (mockCtrl )
@@ -2025,6 +2026,7 @@ func TestGetInboundMeshTrafficPolicy(t *testing.T) {
2025
2026
policyController : mockPolicyController ,
2026
2027
endpointsProviders : []endpoint.Provider {mockEndpointProvider },
2027
2028
serviceProviders : []service.Provider {mockServiceProvider },
2029
+ certManager : fakeCertManager ,
2028
2030
configurator : mockCfg ,
2029
2031
meshSpec : mockMeshSpec ,
2030
2032
}
0 commit comments