Skip to content

Commit

Permalink
[java] Removing check "::1"
Browse files Browse the repository at this point in the history
Fixes #11159
  • Loading branch information
diemol committed Oct 24, 2022
1 parent c3ecac3 commit 4b786a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
7 changes: 1 addition & 6 deletions java/src/org/openqa/selenium/net/PortProber.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ private static boolean isFree(String bindHost, int port) {
}

static int checkPortIsFree(int port) {
boolean localhostIsFree = isFree("localhost", port);
// We cannot check against all interfaces if the Grid is running inside Docker.
if (current.is(Platform.LINUX) && localhostIsFree) {
return port;
}
if (localhostIsFree && isFree("0.0.0.0", port) && isFree("::1", port)) {
if (isFree("localhost", port) && isFree("0.0.0.0", port)) {
return port;
}
return -1;
Expand Down
27 changes: 17 additions & 10 deletions java/test/org/openqa/selenium/net/PortProberTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.net;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.openqa.selenium.Platform;

import java.net.InetSocketAddress;
import java.net.ServerSocket;
Expand Down Expand Up @@ -30,15 +46,6 @@ void checkPortIsFree_checksIpv4AllInterfaces() throws Exception {
}
}

@Test
void checkPortIsFree_checksIpv6Localhost() throws Exception {
if (!Platform.getCurrent().is(Platform.LINUX)) {
try (ServerSocket socket = new ServerSocket()) {
socket.bind(new InetSocketAddress("::1", TEST_PORT));
assertThat(PortProber.checkPortIsFree(TEST_PORT)).isEqualTo(-1);
}
}
}

@Test
void checkPortIsFree_checksIpv6AllInterfaces() throws Exception {
Expand Down

0 comments on commit 4b786a1

Please sign in to comment.