@@ -4,6 +4,7 @@ use super::*;
44fn route_attaches_to_server ( ) {
55 let test = TestConfig :: default ( ) ;
66
7+ // Create pod.
78 let mut pod = mk_pod ( "ns-0" , "pod-0" , Some ( ( "container-0" , None ) ) ) ;
89 pod. labels_mut ( )
910 . insert ( "app" . to_string ( ) , "app-0" . to_string ( ) ) ;
@@ -16,6 +17,7 @@ fn route_attaches_to_server() {
1617 . expect ( "pod-0.ns-0 should exist" ) ;
1718 assert_eq ! ( * rx. borrow_and_update( ) , test. default_server( ) ) ;
1819
20+ // Create server.
1921 test. index . write ( ) . apply ( mk_server (
2022 "ns-0" ,
2123 "srv-8080" ,
@@ -34,6 +36,8 @@ fn route_attaches_to_server() {
3436 http_routes: HashMap :: default ( ) ,
3537 } ,
3638 ) ;
39+
40+ // Create route.
3741 test. index
3842 . write ( )
3943 . apply ( mk_http_route ( "ns-0" , "route-foo" , "srv-8080" ) ) ;
@@ -42,7 +46,27 @@ fn route_attaches_to_server() {
4246 rx. borrow( ) . reference,
4347 ServerRef :: Server ( "srv-8080" . to_string( ) )
4448 ) ;
45- assert ! ( rx. borrow( ) . http_routes. contains_key( "route-foo" ) ) ;
49+ assert ! ( rx. borrow_and_update( ) . http_routes. contains_key( "route-foo" ) ) ;
50+
51+ // Create authz policy.
52+ test. index . write ( ) . apply ( mk_authorization_policy (
53+ "ns-0" ,
54+ "authz-foo" ,
55+ "route-foo" ,
56+ vec ! [ NamespacedTargetRef {
57+ group: None ,
58+ kind: "ServiceAccount" . to_string( ) ,
59+ namespace: Some ( "ns-0" . to_string( ) ) ,
60+ name: "foo" . to_string( ) ,
61+ } ] ,
62+ ) ) ;
63+
64+ assert ! ( rx. has_changed( ) . unwrap( ) ) ;
65+ assert ! ( rx. borrow( ) . http_routes[ "route-foo" ]
66+ . authorizations
67+ . contains_key( & AuthorizationRef :: AuthorizationPolicy (
68+ "authz-foo" . to_string( )
69+ ) ) ) ;
4670}
4771
4872fn mk_http_route (
@@ -84,3 +108,26 @@ fn mk_http_route(
84108 status : None ,
85109 }
86110}
111+
112+ fn mk_authorization_policy (
113+ ns : impl ToString ,
114+ name : impl ToString ,
115+ route : impl ToString ,
116+ authns : impl IntoIterator < Item = NamespacedTargetRef > ,
117+ ) -> k8s:: policy:: AuthorizationPolicy {
118+ k8s:: policy:: AuthorizationPolicy {
119+ metadata : k8s:: ObjectMeta {
120+ namespace : Some ( ns. to_string ( ) ) ,
121+ name : Some ( name. to_string ( ) ) ,
122+ ..Default :: default ( )
123+ } ,
124+ spec : k8s:: policy:: AuthorizationPolicySpec {
125+ target_ref : LocalTargetRef {
126+ group : Some ( "gateway.networking.k8s.io" . to_string ( ) ) ,
127+ kind : "HttpRoute" . to_string ( ) ,
128+ name : route. to_string ( ) ,
129+ } ,
130+ required_authentication_refs : authns. into_iter ( ) . collect ( ) ,
131+ } ,
132+ }
133+ }
0 commit comments