|
| 1 | +use crate::*; |
| 2 | + |
| 3 | +#[tokio::test] |
| 4 | +async fn tagged_transport_http() { |
| 5 | + let _trace = trace_init(); |
| 6 | + |
| 7 | + // identity is always required for direct connections |
| 8 | + let in_svc_acct = "foo.ns1.serviceaccount.identity.linkerd.cluster.local"; |
| 9 | + let in_identity = identity::Identity::new("foo-ns1", in_svc_acct.to_string()); |
| 10 | + |
| 11 | + let out_svc_acct = "bar.ns1.serviceaccount.identity.linkerd.cluster.local"; |
| 12 | + let out_identity = identity::Identity::new("bar-ns1", out_svc_acct.to_string()); |
| 13 | + |
| 14 | + let srv = server::http1().route("/", "hello").run().await; |
| 15 | + let srv_addr = srv.addr; |
| 16 | + let dst = format!("opaque.test.svc.cluster.local:{}", srv_addr.port()); |
| 17 | + |
| 18 | + let (inbound, _profile_in) = { |
| 19 | + let (proxy, profile) = mk_inbound(srv, in_identity.service(), &dst).await; |
| 20 | + let proxy = proxy.run_with_test_env(in_identity.env).await; |
| 21 | + (proxy, profile) |
| 22 | + }; |
| 23 | + |
| 24 | + let (outbound, _profile_out, _dst) = { |
| 25 | + let ctrl = controller::new(); |
| 26 | + let dst = ctrl.destination_tx(dst); |
| 27 | + dst.send( |
| 28 | + controller::destination_add(srv_addr) |
| 29 | + .hint(controller::Hint::H2) |
| 30 | + .opaque_port(inbound.inbound.port()) |
| 31 | + .identity(in_svc_acct), |
| 32 | + ); |
| 33 | + let (proxy, profile) = mk_outbound(srv_addr, ctrl, out_identity).await; |
| 34 | + (proxy, profile, dst) |
| 35 | + }; |
| 36 | + |
| 37 | + let client = client::http1(outbound.outbound, "opaque.test.svc.cluster.local"); |
| 38 | + |
| 39 | + assert_eq!(client.get("/").await, "hello"); |
| 40 | +} |
| 41 | + |
| 42 | +async fn mk_inbound( |
| 43 | + srv: server::Listening, |
| 44 | + id: identity::Controller, |
| 45 | + dst: &str, |
| 46 | +) -> (proxy::Proxy, controller::ProfileSender) { |
| 47 | + let ctrl = controller::new(); |
| 48 | + let profile = ctrl.profile_tx_default(dst, "opaque.test.svc.cluster.local"); |
| 49 | + let ctrl = ctrl |
| 50 | + .run() |
| 51 | + .instrument(tracing::info_span!("ctrl", "inbound")) |
| 52 | + .await; |
| 53 | + let proxy = proxy::new() |
| 54 | + .controller(ctrl) |
| 55 | + .identity(id.run().await) |
| 56 | + .inbound(srv) |
| 57 | + .inbound_direct() |
| 58 | + .named("inbound"); |
| 59 | + (proxy, profile) |
| 60 | +} |
| 61 | + |
| 62 | +async fn mk_outbound( |
| 63 | + srv_addr: SocketAddr, |
| 64 | + ctrl: controller::Controller, |
| 65 | + out_identity: identity::Identity, |
| 66 | +) -> (proxy::Listening, controller::ProfileSender) { |
| 67 | + let profile = ctrl.profile_tx_default(srv_addr, "opaque.test.svc.cluster.local"); |
| 68 | + let ctrl = ctrl |
| 69 | + .run() |
| 70 | + .instrument(tracing::info_span!("ctrl", "outbound")) |
| 71 | + .await; |
| 72 | + let proxy = proxy::new() |
| 73 | + .controller(ctrl) |
| 74 | + .identity(out_identity.service().run().await) |
| 75 | + .outbound_ip(srv_addr) |
| 76 | + .named("outbound") |
| 77 | + .run_with_test_env(out_identity.env) |
| 78 | + .await; |
| 79 | + (proxy, profile) |
| 80 | +} |
0 commit comments