Skip to content

Commit f242119

Browse files
fix(client-core): seed WinRunspace resource URI from configuration name
1 parent add6865 commit f242119

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

crates/ironposh-client-core/src/runspace_pool/creator.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ pub struct RunspacePoolCreator {
4848

4949
impl RunspacePoolCreator {
5050
pub fn into_runspace_pool(self, connection: Arc<WsMan>) -> RunspacePool {
51-
let shell = WinRunspace::builder().id(self.id).build();
51+
let shell = WinRunspace::builder()
52+
.id(self.id)
53+
.resource_uri(connection.resource_uri().to_owned())
54+
.build();
5255

5356
RunspacePool {
5457
id: self.id,

crates/ironposh-client-core/tests/connector_handshake.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,60 @@ fn configuration_name_sets_shell_resource_uri() {
6363
);
6464
}
6565

66+
/// With a JEA `configuration_name`, post-create operations must keep targeting the
67+
/// JEA resource URI even when the server's CreateResponse omits the ResourceUri echo.
68+
#[test]
69+
fn configuration_name_survives_create_response_without_resource_uri_echo() {
70+
let mut config = support::test_config();
71+
config.configuration_name = Some("MyJEAEndpoint".into());
72+
let mut connector = Connector::new(config);
73+
74+
// 1. Idle step emits the shell Create request.
75+
let result = connector.step(None).expect("idle step");
76+
let ConnectorStepResult::SendBack { try_send } = result else {
77+
panic!("expected SendBack for Create");
78+
};
79+
let (_request, conn_id) = support::expect_just_send(try_send);
80+
81+
// 2. Reply with a CreateResponse whose Shell does NOT echo a ResourceUri element.
82+
let create_response = include_str!("resources/resource_created.xml");
83+
let strip_resource_uri =
84+
regex::Regex::new(r"(?s)<rsp:ResourceUri>.*?</rsp:ResourceUri>").expect("valid regex");
85+
let create_response = strip_resource_uri.replace(create_response, "").into_owned();
86+
assert!(
87+
!create_response.contains("rsp:ResourceUri"),
88+
"fixture must not echo a shell ResourceUri for this test"
89+
);
90+
91+
let result = connector
92+
.step(Some(support::xml_response(conn_id, create_response)))
93+
.expect("accept CreateResponse");
94+
let ConnectorStepResult::SendBack { try_send } = result else {
95+
panic!("expected SendBack for Receive");
96+
};
97+
98+
// 3. The post-create Receive must still target the JEA endpoint resource URI.
99+
let (request, _conn_id) = support::expect_just_send(try_send);
100+
let receive_xml = request
101+
.body
102+
.expect("receive has a body")
103+
.as_str()
104+
.expect("plaintext body")
105+
.to_owned();
106+
assert!(
107+
receive_xml.contains("http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Receive"),
108+
"connector must fire a Receive after shell creation"
109+
);
110+
assert!(
111+
receive_xml.contains("powershell/MyJEAEndpoint"),
112+
"post-create Receive must target the JEA endpoint resource URI"
113+
);
114+
assert!(
115+
!receive_xml.contains("powershell/Microsoft.PowerShell"),
116+
"post-create Receive must not fall back to the default resource URI"
117+
);
118+
}
119+
66120
/// Drive the connector through the full handshake against a fake server:
67121
/// Create -> CreateResponse -> Receive -> ReceiveResponse(PSRP negotiation) -> Connected.
68122
#[test]

crates/ironposh-winrm/src/ws_management/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ impl WsMan {
4444
pub fn max_envelope_size(&self) -> u32 {
4545
self.max_envelope_size
4646
}
47+
48+
pub fn resource_uri(&self) -> &str {
49+
&self.resource_uri
50+
}
4751
}
4852

4953
#[derive(Debug, Clone)]

0 commit comments

Comments
 (0)