23
23
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
24
24
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
25
25
import static org .assertj .core .api .InstanceOfAssertFactories .MAP ;
26
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
27
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
26
28
import static org .openqa .selenium .json .Json .MAP_TYPE ;
27
29
import static org .openqa .selenium .remote .http .Contents .string ;
28
30
import static org .openqa .selenium .remote .http .HttpMethod .DELETE ;
@@ -102,7 +104,9 @@ class NodeTest {
102
104
private Tracer tracer ;
103
105
private EventBus bus ;
104
106
private LocalNode local ;
107
+ private LocalNode local2 ;
105
108
private Node node ;
109
+ private Node node2 ;
106
110
private ImmutableCapabilities stereotype ;
107
111
private ImmutableCapabilities caps ;
108
112
private URI uri ;
@@ -150,6 +154,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
150
154
builder = builder .enableManagedDownloads (true ).sessionTimeout (Duration .ofSeconds (1 ));
151
155
}
152
156
local = builder .build ();
157
+ local2 = builder .build ();
153
158
154
159
node =
155
160
new RemoteNode (
@@ -160,6 +165,16 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
160
165
registrationSecret ,
161
166
local .getSessionTimeout (),
162
167
ImmutableSet .of (caps ));
168
+
169
+ node2 =
170
+ new RemoteNode (
171
+ tracer ,
172
+ new PassthroughHttpClient .Factory (local2 ),
173
+ new NodeId (UUID .randomUUID ()),
174
+ uri ,
175
+ registrationSecret ,
176
+ local2 .getSessionTimeout (),
177
+ ImmutableSet .of (caps ));
163
178
}
164
179
165
180
@ Test
@@ -371,13 +386,36 @@ void shouldOnlyRespondToWebDriverCommandsForSessionsTheNodeOwns() {
371
386
assertThatEither (response ).isRight ();
372
387
Session session = response .right ().getSession ();
373
388
389
+ Either <WebDriverException , CreateSessionResponse > response2 =
390
+ node2 .newSession (createSessionRequest (caps ));
391
+ assertThatEither (response2 ).isRight ();
392
+ Session session2 = response2 .right ().getSession ();
393
+
394
+ // Assert that should respond to commands for sessions Node 1 owns
374
395
HttpRequest req = new HttpRequest (POST , String .format ("/session/%s/url" , session .getId ()));
375
396
assertThat (local .matches (req )).isTrue ();
376
397
assertThat (node .matches (req )).isTrue ();
377
398
378
- req = new HttpRequest (POST , String .format ("/session/%s/url" , UUID .randomUUID ()));
379
- assertThat (local .matches (req )).isFalse ();
380
- assertThat (node .matches (req )).isFalse ();
399
+ // Assert that should respond to commands for sessions Node 2 owns
400
+ HttpRequest req2 = new HttpRequest (POST , String .format ("/session/%s/url" , session2 .getId ()));
401
+ assertThat (local2 .matches (req2 )).isTrue ();
402
+ assertThat (node2 .matches (req2 )).isTrue ();
403
+
404
+ // Assert that should not respond to commands for sessions Node 1 does not own
405
+ NoSuchSessionException exception =
406
+ assertThrows (NoSuchSessionException .class , () -> node .execute (req2 ));
407
+ assertTrue (
408
+ exception
409
+ .getMessage ()
410
+ .startsWith (String .format ("Cannot find session with id: %s" , session2 .getId ())));
411
+
412
+ // Assert that should not respond to commands for sessions Node 2 does not own
413
+ NoSuchSessionException exception2 =
414
+ assertThrows (NoSuchSessionException .class , () -> node2 .execute (req ));
415
+ assertTrue (
416
+ exception2
417
+ .getMessage ()
418
+ .startsWith (String .format ("Cannot find session with id: %s" , session .getId ())));
381
419
}
382
420
383
421
@ Test
0 commit comments