@@ -467,6 +467,70 @@ func TestKubernetesToken(t *testing.T) {
467467 require .NoError (t , validate (ctx , cfg , "test" ))
468468}
469469
470+ func TestSSHUpstream (t * testing.T ) {
471+ irv := networkingv1.IngressRuleValue {
472+ HTTP : & networkingv1.HTTPIngressRuleValue {
473+ Paths : []networkingv1.HTTPIngressPath {{
474+ PathType : new (networkingv1.PathTypeImplementationSpecific ),
475+ Backend : networkingv1.IngressBackend {
476+ Service : & networkingv1.IngressServiceBackend {
477+ Name : "example-svc" ,
478+ Port : networkingv1.ServiceBackendPort {
479+ Number : 22 ,
480+ },
481+ },
482+ },
483+ }},
484+ },
485+ }
486+ ic := model.IngressConfig {
487+ AnnotationPrefix : "p" ,
488+ Ingress : & networkingv1.Ingress {
489+ ObjectMeta : metav1.ObjectMeta {
490+ Name : "ingress" ,
491+ Namespace : "default" ,
492+ Annotations : map [string ]string {
493+ "p/ssh_upstream" : "true" ,
494+ },
495+ },
496+ Spec : networkingv1.IngressSpec {
497+ Rules : []networkingv1.IngressRule {{
498+ Host : "my-ssh-route" ,
499+ IngressRuleValue : irv ,
500+ }},
501+ },
502+ },
503+ Services : map [types.NamespacedName ]* corev1.Service {
504+ {Name : "example-svc" , Namespace : "default" }: {},
505+ },
506+ }
507+
508+ t .Run ("ok" , func (t * testing.T ) {
509+ routes , err := ingressToRoutes (t .Context (), & ic )
510+ require .NoError (t , err )
511+
512+ require .Len (t , routes , 1 )
513+ assert .Equal (t , "ssh://my-ssh-route" , routes [0 ].From )
514+ assert .Equal (t , []string {"ssh://example-svc.default.svc.cluster.local:22" }, routes [0 ].To )
515+ })
516+ t .Run ("bad path type" , func (t * testing.T ) {
517+ ic := ic
518+ ic .Ingress = ic .Ingress .DeepCopy ()
519+ ic .Ingress .Spec .Rules [0 ].HTTP .Paths [0 ].PathType = new (networkingv1.PathTypeExact )
520+
521+ _ , err := ingressToRoutes (t .Context (), & ic )
522+ assert .ErrorContains (t , err , "ssh services must have ImplementationSpecific path type" )
523+ })
524+ t .Run ("non-empty path" , func (t * testing.T ) {
525+ ic := ic
526+ ic .Ingress = ic .Ingress .DeepCopy ()
527+ ic .Ingress .Spec .Rules [0 ].HTTP .Paths [0 ].Path = "/some/path"
528+
529+ _ , err := ingressToRoutes (t .Context (), & ic )
530+ assert .ErrorContains (t , err , "ssh services must not specify path, got /some/path" )
531+ })
532+ }
533+
470534func TestTCPUpstream (t * testing.T ) {
471535 typePrefix := networkingv1 .PathTypePrefix
472536 typeImpSpec := networkingv1 .PathTypeImplementationSpecific
0 commit comments