You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/06/05 15:46:06 UTC
[GitHub] [maven-surefire] Tibor17 opened a new pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Tibor17 opened a new pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] olamy removed a comment on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
olamy removed a comment on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640145950
I don't think 127.0.0.1 neither localhost will work when executing within docker images running with k8s. That's why tools such testcontainer provide this https://www.testcontainers.org/features/networking/#getting-the-container-host.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r437762464
##########
File path: surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java
##########
@@ -80,7 +81,8 @@ public void test() throws Exception
AsynchronousChannelGroup group = AsynchronousChannelGroup.withThreadPool( executorService );
AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open( group );
setTrueOptions( server, SO_REUSEADDR, TCP_NODELAY, SO_KEEPALIVE );
- server.bind( null, 1 );
+ InetAddress ip = Inet4Address.getLocalHost();
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640112264
@michael-o Done!
The localhost is fixed in master.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r437645611
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -119,4 +128,23 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
}
}
}
+
+ private static String parseSessionId( URI uri )
Review comment:
I think `extractSessionId` is a better name since the URI has already been parsed, we just need to extract the session id. Thoogh, this might be just a personal taste.
##########
File path: surefire-api/src/test/java/org/apache/maven/surefire/api/util/internal/AsyncSocketTest.java
##########
@@ -80,7 +81,8 @@ public void test() throws Exception
AsynchronousChannelGroup group = AsynchronousChannelGroup.withThreadPool( executorService );
AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel.open( group );
setTrueOptions( server, SO_REUSEADDR, TCP_NODELAY, SO_KEEPALIVE );
- server.bind( null, 1 );
+ InetAddress ip = Inet4Address.getLocalHost();
Review comment:
Inet4Address => InetAddress
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +117,26 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
Review comment:
`verifySessionId()`?
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +195,70 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID().toString() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments );
+ SurefireMasterProcessChannelProcessorFactory client = new SurefireMasterProcessChannelProcessorFactory() )
+ {
+ FutureTask<String> task = new FutureTask<>( new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ return "client connected";
+ }
+ } );
+
+ Thread t = new Thread( task );
+ t.setDaemon( true );
+ t.start();
+
+ server.connectToClient();
+
+ assertThat( task.get() )
+ .isEqualTo( "client connected" );
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ String serverSessionId = UUID.randomUUID().toString();
+ when( forkNodeArguments.getSessionId() ).thenReturn( serverSessionId );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments );
+ SurefireMasterProcessChannelProcessorFactory client = new SurefireMasterProcessChannelProcessorFactory() )
+ {
+ FutureTask<String> task = new FutureTask<>( new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
Review comment:
connectionString => connectionUri because we have a URI object now.
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +117,26 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
+ {
+ ByteBuffer buffer = ByteBuffer.allocate( sessionId.length() );
+ int read;
+ do
+ {
+ read = worker.read( buffer ).get();
+ } while ( read != -1 && buffer.hasRemaining() );
+ if ( read == -1 )
+ {
+ throw new IOException( "Channel closed while authenticating the client." );
Review comment:
...while verifying...`
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/AuthenticationException.java
##########
@@ -0,0 +1,39 @@
+package org.apache.maven.plugin.surefire.extensions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.
+ */
+
+import org.apache.maven.surefire.extensions.ForkChannel;
+import org.apache.maven.surefire.extensions.util.CommandlineExecutor;
+
+import java.io.IOException;
+
+/**
+ * After the authentication has failed, {@link ForkChannel#connectToClient()} throws {@link AuthenticationException}
+ * and {@link org.apache.maven.plugin.surefire.booterclient.ForkStarter} should close {@link CommandlineExecutor}.
+ *
+ * @since 3.0.0-M5
+ */
+public class AuthenticationException extends IOException
Review comment:
I think since we've got rid the `auth` term, but this class name still refers to it. What about `InvalidSessionIdEx` extends IllegalArgumentEx`. This is clearly not an `IOEx`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436302150
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +124,25 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
+ {
+ ByteBuffer hash = ByteBuffer.allocate( UUID_STRING_LENGTH );
Review comment:
No hash is exchanged here. Why not call it `token`?
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
##########
@@ -162,17 +172,20 @@ public void handleEvent( @Nonnull Event s )
private final class Client extends Thread
{
private final int port;
+ private final String sessionId;
- private Client( int port )
+ private Client( int port, String sessionId )
{
this.port = port;
+ this.sessionId = sessionId;
}
@Override
public void run()
{
try ( Socket socket = new Socket( "127.0.0.1", port ) )
Review comment:
Still see IP address here.
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -385,4 +472,26 @@ public Object answer( InvocationOnMock invocation )
} ).when( ShutdownHookUtils.class, "addShutDownHook", any( Thread.class ) );
invokeMethod( booter, "flushEventChannelOnExit" );
}
+
+ @Test
+ public void shouldParseUUID() throws Exception
+ {
+ SurefireMasterProcessChannelProcessorFactory factory = new SurefireMasterProcessChannelProcessorFactory();
+ UUID uuid = UUID.randomUUID();
+ URI uri = new URI( "tcp://127.0.0.1:12345?auth=" + uuid );
Review comment:
Still see IP address here.
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -385,4 +472,26 @@ public Object answer( InvocationOnMock invocation )
} ).when( ShutdownHookUtils.class, "addShutDownHook", any( Thread.class ) );
invokeMethod( booter, "flushEventChannelOnExit" );
}
+
+ @Test
+ public void shouldParseUUID() throws Exception
+ {
+ SurefireMasterProcessChannelProcessorFactory factory = new SurefireMasterProcessChannelProcessorFactory();
+ UUID uuid = UUID.randomUUID();
+ URI uri = new URI( "tcp://127.0.0.1:12345?auth=" + uuid );
+ UUID parsed = invokeMethod( factory, "parseAuth", uri );
+ assertThat( parsed )
+ .isEqualTo( uuid );
+ }
+
+ @Test
+ public void shouldNotParseUUID() throws Exception
+ {
+ SurefireMasterProcessChannelProcessorFactory factory = new SurefireMasterProcessChannelProcessorFactory();
+ UUID uuid = UUID.randomUUID();
+ URI uri = new URI( "tcp://127.0.0.1:12345?xxx=" + uuid );
Review comment:
Still see IP address here.
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -362,6 +372,83 @@ public void run() throws Throwable
}
}
+ @Test
+ public void shouldAuthenticate() throws Exception
+ {
+ mockStatic( ForkedBooter.class );
+
+ doCallRealMethod()
+ .when( ForkedBooter.class, "lookupDecoderFactory", anyString() );
+
+ try ( final ServerSocketChannel server = ServerSocketChannel.open() )
+ {
+ if ( server.supportedOptions().contains( SO_REUSEADDR ) )
+ {
+ server.setOption( SO_REUSEADDR, true );
+ }
+
+ if ( server.supportedOptions().contains( TCP_NODELAY ) )
+ {
+ server.setOption( TCP_NODELAY, true );
+ }
+
+ if ( server.supportedOptions().contains( SO_KEEPALIVE ) )
+ {
+ server.setOption( SO_KEEPALIVE, true );
+ }
+
+ server.bind( new InetSocketAddress( 0 ) );
+ int serverPort = ( (InetSocketAddress) server.getLocalAddress() ).getPort();
+ final UUID uuid = UUID.randomUUID();
+ String url = "tcp://127.0.0.1:" + serverPort + "?auth=" + uuid;
Review comment:
Still see IP address here.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://127.0.0.1:" + connectionString.getPort()
Review comment:
Still see IP address here.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
##########
@@ -100,7 +109,8 @@ public ConsoleLogger getConsoleLogger()
assertThat( channel.getForkNodeConnectionString() )
.startsWith( "tcp://127.0.0.1:" )
- .isNotEqualTo( "tcp://127.0.0.1:" );
+ .isNotEqualTo( "tcp://127.0.0.1:" )
Review comment:
Still see IP address here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436266600
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -119,4 +129,23 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
}
}
}
+
+ private UUID parseAuth( URI uri )
Review comment:
Yes, i will make it static.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] eolivelli commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
eolivelli commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640161374
Maybe it is more consistent to call this new parameter 'sessionId' and not 'auth' or 'hash'
This way it won't be confused for some kind of real security mechanism
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] eolivelli commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
eolivelli commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640040229
@michael-o
This is an initial attempt to make it sure that the client is only the expected one.
We are always on localhost and IMO there is no need to do something more complicated.
Using network enables every other user of the local machine to interact easily with the Maven execution of current user. This is true for dev machines and for CI agents.
This session will also be useful to prevent headaches of people running multiple instance of surefire on the same machine as on CI
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640016939
@eolivelli Pls answer @michael-o 's questions.
@michael-o Yes, it is on `127.0.0.1`. The stream cannot use SSL, otherwise we slowdown the tests. Instead we use the token. The hacker has harder situation because the `ForkStarter` accepts only one client connection, and he has very short time and a chance to connect while he is faster than the fork VM starts.
I did it because it was required feature by @eolivelli .
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] eolivelli commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
eolivelli commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640057210
We could add new implementations in the future
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436267032
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -362,6 +372,83 @@ public void run() throws Throwable
}
}
+ @Test
+ public void shouldAuthenticate() throws Exception
+ {
+ mockStatic( ForkedBooter.class );
+
+ doCallRealMethod()
+ .when( ForkedBooter.class, "lookupDecoderFactory", anyString() );
+
+ try ( final ServerSocketChannel server = ServerSocketChannel.open() )
+ {
+ if ( server.supportedOptions().contains( SO_REUSEADDR ) )
+ {
+ server.setOption( SO_REUSEADDR, true );
+ }
+
+ if ( server.supportedOptions().contains( TCP_NODELAY ) )
+ {
+ server.setOption( TCP_NODELAY, true );
+ }
+
+ if ( server.supportedOptions().contains( SO_KEEPALIVE ) )
Review comment:
There are few of them.
@jon-bell
@eolivelli
Which options do we need, and which we need?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r437754132
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +195,70 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID().toString() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments );
+ SurefireMasterProcessChannelProcessorFactory client = new SurefireMasterProcessChannelProcessorFactory() )
+ {
+ FutureTask<String> task = new FutureTask<>( new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ return "client connected";
+ }
+ } );
+
+ Thread t = new Thread( task );
+ t.setDaemon( true );
+ t.start();
+
+ server.connectToClient();
+
+ assertThat( task.get() )
+ .isEqualTo( "client connected" );
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ String serverSessionId = UUID.randomUUID().toString();
+ when( forkNodeArguments.getSessionId() ).thenReturn( serverSessionId );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments );
+ SurefireMasterProcessChannelProcessorFactory client = new SurefireMasterProcessChannelProcessorFactory() )
+ {
+ FutureTask<String> task = new FutureTask<>( new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436304663
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -385,4 +472,26 @@ public Object answer( InvocationOnMock invocation )
} ).when( ShutdownHookUtils.class, "addShutDownHook", any( Thread.class ) );
invokeMethod( booter, "flushEventChannelOnExit" );
}
+
+ @Test
+ public void shouldParseUUID() throws Exception
+ {
+ SurefireMasterProcessChannelProcessorFactory factory = new SurefireMasterProcessChannelProcessorFactory();
+ UUID uuid = UUID.randomUUID();
+ URI uri = new URI( "tcp://127.0.0.1:12345?auth=" + uuid );
Review comment:
This needs to be changed in current branch.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436304525
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
##########
@@ -100,7 +109,8 @@ public ConsoleLogger getConsoleLogger()
assertThat( channel.getForkNodeConnectionString() )
.startsWith( "tcp://127.0.0.1:" )
- .isNotEqualTo( "tcp://127.0.0.1:" );
+ .isNotEqualTo( "tcp://127.0.0.1:" )
Review comment:
Rebase in needed.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436306303
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://127.0.0.1:" + connectionString.getPort()
Review comment:
@michael-o Well, for me the naming conventions are always the dilema of domain - who is watching.
The `ForkStarter` creates this string passing it to the abstraction.
If it is the class `ForkStarter`, it is the lifetime of JVM which is everything it understands - it does not know authentication in e.g. process pipes.
Maybe some constraints are missing writen, e.g. in Javadoc.
The domain of forked JVM operates with TCP authentication but only in one implementation, i.e. `SurefireMasterProcessChannelProcessorFactory`. The abstraction `MasterProcessChannelProcessorFactory` again has no notion.
I am not against your opinion. Fel free to tell me your ideas.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] eolivelli commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436259355
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -119,4 +129,23 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
}
}
}
+
+ private UUID parseAuth( URI uri )
Review comment:
static ?
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -362,6 +372,83 @@ public void run() throws Throwable
}
}
+ @Test
+ public void shouldAuthenticate() throws Exception
+ {
+ mockStatic( ForkedBooter.class );
+
+ doCallRealMethod()
+ .when( ForkedBooter.class, "lookupDecoderFactory", anyString() );
+
+ try ( final ServerSocketChannel server = ServerSocketChannel.open() )
+ {
+ if ( server.supportedOptions().contains( SO_REUSEADDR ) )
+ {
+ server.setOption( SO_REUSEADDR, true );
+ }
+
+ if ( server.supportedOptions().contains( TCP_NODELAY ) )
+ {
+ server.setOption( TCP_NODELAY, true );
+ }
+
+ if ( server.supportedOptions().contains( SO_KEEPALIVE ) )
Review comment:
IMO you don't need these options in a test
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +124,25 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
+ {
+ ByteBuffer hash = ByteBuffer.allocate( UUID_STRING_LENGTH );
Review comment:
Why 'hash' ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-639894960
What is the purpose of authentication when the transport channel is not secure? Anyone can incept this. On localhost is there a need for this?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436660313
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
Review comment:
The view in GH is not enough. You have to see whole nested class `Runnable`.
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -129,7 +159,7 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
@Override
public String getForkNodeConnectionString()
{
- return "tcp://" + localHost + ":" + localPort;
+ return "tcp://" + localHost + ":" + localPort + ( sessionId == null ? "" : "?sessionId=" + sessionId );
Review comment:
We do not know if it is localhost. Nothing must be hard coded in this place. Only one point in whole `SurefireForkChannel` can do it and it is the constructor at the [Line 93](https://github.com/apache/maven-surefire/blob/ea4020701cb2c53545a0ae3a2820938195f4077f/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java#L93). We provide abstraction and we provide two default implementations but it does not mean that later it would not be foreign IP address since some user inherited this class overriding the constructor. This reimplementation can be done in the POM `<forkNode implementation=""/>`. This connection string goes to the properties file and to the fork JVM.
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -129,7 +159,7 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
@Override
public String getForkNodeConnectionString()
{
- return "tcp://" + localHost + ":" + localPort;
+ return "tcp://" + localHost + ":" + localPort + ( sessionId == null ? "" : "?sessionId=" + sessionId );
Review comment:
It's the best programming approach to set the value in one place of the class and reference the value even if it would be the same with hard coded value. We do it with our experiences that the analysis is simple and easy to change. Therefore our suumptions of a constant string `locahost` does not end up in 3 places, nothing but only one. It's later easy to manipulate with such a class and extend it with alternative construcotr, etc. These are the practices which drive us to this design.
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -129,7 +159,7 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
@Override
public String getForkNodeConnectionString()
{
- return "tcp://" + localHost + ":" + localPort;
+ return "tcp://" + localHost + ":" + localPort + ( sessionId == null ? "" : "?sessionId=" + sessionId );
Review comment:
It's the best programming approach to set the value in one place of the class and reference the value even if it would be the same with hard coded value. We do it with our experiences that the analysis is simple and easy to change. Therefore our asumptions of a constant string `locahost` does not end up in 3 places, nothing but only one. It's later easy to manipulate with such a class and extend it with alternative construcotr, etc. These are the practices which drive us to this design.
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -129,7 +159,7 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
@Override
public String getForkNodeConnectionString()
{
- return "tcp://" + localHost + ":" + localPort;
+ return "tcp://" + localHost + ":" + localPort + ( sessionId == null ? "" : "?sessionId=" + sessionId );
Review comment:
It's the best programming approach to set the value in one place of the class and reference the value even if it would be the same with hard coded value. We do it with our experiences that the analysis is simple and easy to change. Therefore our assumptions of a constant string `locahost` does not end up in 3 places, nothing but only one. It's later easy to manipulate with such a class and extend it with alternative construcotr, etc. These are the practices which drive us to this design.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://" + connectionString.getHost() + ":" + connectionString.getPort()
+ + "?sessionId=6ba7b812-9dad-11d1-80b4-00c04fd430c8" );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+
+ e.expect( IOException.class );
Review comment:
This asserts the failure at next line 262 `server.connectToClient();`
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://" + connectionString.getHost() + ":" + connectionString.getPort()
+ + "?sessionId=6ba7b812-9dad-11d1-80b4-00c04fd430c8" );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+
+ e.expect( IOException.class );
Review comment:
See the [commit](https://github.com/apache/maven-surefire/pull/300/commits/c6f52fbb756482b0dfc3e5fae73c434b192db1fd) which explains that we did not expect an exception within the Thread. We expect it in server's facility verifying the session id returned by the client. Now the client's Thread also has to be running without exception.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://" + connectionString.getHost() + ":" + connectionString.getPort()
+ + "?sessionId=6ba7b812-9dad-11d1-80b4-00c04fd430c8" );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
Review comment:
See the [commit](https://github.com/apache/maven-surefire/pull/300/commits/c6f52fbb756482b0dfc3e5fae73c434b192db1fd) which explains that we did not expect an exception within the Thread. We expect it in server's facility verifying the session id returned by the client. Now the client's Thread also has to be running without exception.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
Review comment:
See the [commit](https://github.com/apache/maven-surefire/pull/300/commits/c6f52fbb756482b0dfc3e5fae73c434b192db1fd) which explains that we did not expect an exception within the Thread. We expect it in server's facility verifying the session id returned by the client. Now the client's Thread also has to be running without exception.
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +124,25 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
+ {
+ ByteBuffer hash = ByteBuffer.allocate( UUID_STRING_LENGTH );
Review comment:
@eolivelli done!
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -119,4 +129,23 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
}
}
}
+
+ private UUID parseAuth( URI uri )
Review comment:
@eolivelli done!
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -362,6 +372,83 @@ public void run() throws Throwable
}
}
+ @Test
+ public void shouldAuthenticate() throws Exception
+ {
+ mockStatic( ForkedBooter.class );
+
+ doCallRealMethod()
+ .when( ForkedBooter.class, "lookupDecoderFactory", anyString() );
+
+ try ( final ServerSocketChannel server = ServerSocketChannel.open() )
+ {
+ if ( server.supportedOptions().contains( SO_REUSEADDR ) )
+ {
+ server.setOption( SO_REUSEADDR, true );
+ }
+
+ if ( server.supportedOptions().contains( TCP_NODELAY ) )
+ {
+ server.setOption( TCP_NODELAY, true );
+ }
+
+ if ( server.supportedOptions().contains( SO_KEEPALIVE ) )
Review comment:
@eolivelli
@olamy
Removed in test. Done!
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://127.0.0.1:" + connectionString.getPort()
Review comment:
@olamy
@eolivelli
Used another name `sessionId`.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://127.0.0.1:" + connectionString.getPort()
Review comment:
@michael-o
@eolivelli
Used another name `sessionId`.
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -362,6 +372,83 @@ public void run() throws Throwable
}
}
+ @Test
+ public void shouldAuthenticate() throws Exception
+ {
+ mockStatic( ForkedBooter.class );
+
+ doCallRealMethod()
+ .when( ForkedBooter.class, "lookupDecoderFactory", anyString() );
+
+ try ( final ServerSocketChannel server = ServerSocketChannel.open() )
+ {
+ if ( server.supportedOptions().contains( SO_REUSEADDR ) )
+ {
+ server.setOption( SO_REUSEADDR, true );
+ }
+
+ if ( server.supportedOptions().contains( TCP_NODELAY ) )
+ {
+ server.setOption( TCP_NODELAY, true );
+ }
+
+ if ( server.supportedOptions().contains( SO_KEEPALIVE ) )
Review comment:
@eolivelli
Removed in test. Done!
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -362,6 +372,83 @@ public void run() throws Throwable
}
}
+ @Test
+ public void shouldAuthenticate() throws Exception
+ {
+ mockStatic( ForkedBooter.class );
+
+ doCallRealMethod()
+ .when( ForkedBooter.class, "lookupDecoderFactory", anyString() );
+
+ try ( final ServerSocketChannel server = ServerSocketChannel.open() )
+ {
+ if ( server.supportedOptions().contains( SO_REUSEADDR ) )
+ {
+ server.setOption( SO_REUSEADDR, true );
+ }
+
+ if ( server.supportedOptions().contains( TCP_NODELAY ) )
+ {
+ server.setOption( TCP_NODELAY, true );
+ }
+
+ if ( server.supportedOptions().contains( SO_KEEPALIVE ) )
+ {
+ server.setOption( SO_KEEPALIVE, true );
+ }
+
+ server.bind( new InetSocketAddress( 0 ) );
+ int serverPort = ( (InetSocketAddress) server.getLocalAddress() ).getPort();
+ final UUID uuid = UUID.randomUUID();
+ String url = "tcp://127.0.0.1:" + serverPort + "?auth=" + uuid;
Review comment:
@michael-o
Done!
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -385,4 +472,26 @@ public Object answer( InvocationOnMock invocation )
} ).when( ShutdownHookUtils.class, "addShutDownHook", any( Thread.class ) );
invokeMethod( booter, "flushEventChannelOnExit" );
}
+
+ @Test
+ public void shouldParseUUID() throws Exception
+ {
+ SurefireMasterProcessChannelProcessorFactory factory = new SurefireMasterProcessChannelProcessorFactory();
+ UUID uuid = UUID.randomUUID();
+ URI uri = new URI( "tcp://127.0.0.1:12345?auth=" + uuid );
Review comment:
@michael-o
Done!
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -129,7 +159,7 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
@Override
public String getForkNodeConnectionString()
{
- return "tcp://" + localHost + ":" + localPort;
+ return "tcp://" + localHost + ":" + localPort + ( sessionId == null ? "" : "?sessionId=" + sessionId );
Review comment:
@michael-o used InetAddress.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
Review comment:
@michael-o see whole block of code
https://github.com/apache/maven-surefire/blob/c6f52fbb756482b0dfc3e5fae73c434b192db1fd/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java#L235-L259
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://" + connectionString.getHost() + ":" + connectionString.getPort()
+ + "?sessionId=6ba7b812-9dad-11d1-80b4-00c04fd430c8" );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
Review comment:
@michael-o This is no more printed. Handled with `Future.get()`.
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -75,6 +79,12 @@ public void connect( String channelConfig ) throws IOException
clientSocketChannel = open( withFixedThreadPool( 2, newDaemonThreadFactory() ) );
setTrueOptions( SO_REUSEADDR, TCP_NODELAY, SO_KEEPALIVE );
clientSocketChannel.connect( hostAddress ).get();
+ UUID sessionId = parseAuth( uri );
+ if ( sessionId != null )
+ {
+ ByteBuffer buff = ByteBuffer.wrap( sessionId.toString().getBytes( US_ASCII ) );
Review comment:
@michael-o already renamed to buffer.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640026011
@michael-o
Thx, I will turn this to localhost.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640064404
The next optimization should be done in `ThreadedStreamConsumer` to implement lock-free queue. I have several shelfs in IDEA witht the impl using the locks on the border of the queue capacity but I do not want to introduce it now since Java Concurrency improvements are always risky while we are in hurry with a release.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436266749
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -119,4 +129,23 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
}
}
}
+
+ private UUID parseAuth( URI uri )
Review comment:
The method should be renamed because nothing is parsed, you have a `URI` instance already. It is a matter of calling a getter.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436266939
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +124,25 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
+ {
+ ByteBuffer hash = ByteBuffer.allocate( UUID_STRING_LENGTH );
Review comment:
I was trying to be consistent, so that the connection string has string in the properties file and the code as well.
What approach is better?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436306303
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://127.0.0.1:" + connectionString.getPort()
Review comment:
@michael-o Well, for me the naming conventions are always the dilema of domain - who is watching.
The `ForkStarter` creates this string passing it to the abstraction.
If it is the class `ForkStarter`, it is the lifetime of JVM which is everything it understands - it does not know authentication in e.g. process pipes.
Maybe some constraints are missing writen, e.g. in Javadoc.
The domain of forked JVM operates with TCP authentication but only in one implementation, i.e. `SurefireMasterProcessChannelProcessorFactory`. The abstraction `MasterProcessChannelProcessorFactory` again has no notion.
I am not against your opinion. Feel free to tell me your ideas.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436304538
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://127.0.0.1:" + connectionString.getPort()
Review comment:
Need for rebase.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r437755074
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +117,26 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
+ {
+ ByteBuffer buffer = ByteBuffer.allocate( sessionId.length() );
+ int read;
+ do
+ {
+ read = worker.read( buffer ).get();
+ } while ( read != -1 && buffer.hasRemaining() );
+ if ( read == -1 )
+ {
+ throw new IOException( "Channel closed while authenticating the client." );
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436266749
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -119,4 +129,23 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
}
}
}
+
+ private UUID parseAuth( URI uri )
Review comment:
The method should be renamed because nothing is parsed, you have a `URI` instance already. It is a matter of calling a getter.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r437926268
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/AuthenticationException.java
##########
@@ -0,0 +1,39 @@
+package org.apache.maven.plugin.surefire.extensions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.
+ */
+
+import org.apache.maven.surefire.extensions.ForkChannel;
+import org.apache.maven.surefire.extensions.util.CommandlineExecutor;
+
+import java.io.IOException;
+
+/**
+ * After the authentication has failed, {@link ForkChannel#connectToClient()} throws {@link AuthenticationException}
+ * and {@link org.apache.maven.plugin.surefire.booterclient.ForkStarter} should close {@link CommandlineExecutor}.
+ *
+ * @since 3.0.0-M5
+ */
+public class AuthenticationException extends IOException
Review comment:
OK, let's accept that limitation, but use a proper name: `InvalidSessionIdEx extends IOEx`.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +195,70 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
Review comment:
`shouldVerifyClient`
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +195,70 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID().toString() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments );
+ SurefireMasterProcessChannelProcessorFactory client = new SurefireMasterProcessChannelProcessorFactory() )
+ {
+ FutureTask<String> task = new FutureTask<>( new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ return "client connected";
+ }
+ } );
+
+ Thread t = new Thread( task );
+ t.setDaemon( true );
+ t.start();
+
+ server.connectToClient();
+
+ assertThat( task.get() )
+ .isEqualTo( "client connected" );
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
Review comment:
`shouldNotVerifyClient`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640022711
@Tibor17 OK. Don't use `127.0.0.1`, but always use `localhost`. There is no guarantee that `localhost` == `127.0.0.1`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r437754163
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -119,4 +128,23 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
}
}
}
+
+ private static String parseSessionId( URI uri )
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640286858
Now we use `sessionId` and `localhost` in mock tetss or IP address of localhost.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r437755538
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +117,26 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436304161
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
##########
@@ -100,7 +109,8 @@ public ConsoleLogger getConsoleLogger()
assertThat( channel.getForkNodeConnectionString() )
.startsWith( "tcp://127.0.0.1:" )
- .isNotEqualTo( "tcp://127.0.0.1:" );
+ .isNotEqualTo( "tcp://127.0.0.1:" )
Review comment:
This is no more in master.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436304747
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -385,4 +472,26 @@ public Object answer( InvocationOnMock invocation )
} ).when( ShutdownHookUtils.class, "addShutDownHook", any( Thread.class ) );
invokeMethod( booter, "flushEventChannelOnExit" );
}
+
+ @Test
+ public void shouldParseUUID() throws Exception
+ {
+ SurefireMasterProcessChannelProcessorFactory factory = new SurefireMasterProcessChannelProcessorFactory();
+ UUID uuid = UUID.randomUUID();
+ URI uri = new URI( "tcp://127.0.0.1:12345?auth=" + uuid );
+ UUID parsed = invokeMethod( factory, "parseAuth", uri );
+ assertThat( parsed )
+ .isEqualTo( uuid );
+ }
+
+ @Test
+ public void shouldNotParseUUID() throws Exception
+ {
+ SurefireMasterProcessChannelProcessorFactory factory = new SurefireMasterProcessChannelProcessorFactory();
+ UUID uuid = UUID.randomUUID();
+ URI uri = new URI( "tcp://127.0.0.1:12345?xxx=" + uuid );
Review comment:
I will fix it here too.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] eolivelli commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436327376
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -362,6 +372,83 @@ public void run() throws Throwable
}
}
+ @Test
+ public void shouldAuthenticate() throws Exception
+ {
+ mockStatic( ForkedBooter.class );
+
+ doCallRealMethod()
+ .when( ForkedBooter.class, "lookupDecoderFactory", anyString() );
+
+ try ( final ServerSocketChannel server = ServerSocketChannel.open() )
+ {
+ if ( server.supportedOptions().contains( SO_REUSEADDR ) )
+ {
+ server.setOption( SO_REUSEADDR, true );
+ }
+
+ if ( server.supportedOptions().contains( TCP_NODELAY ) )
+ {
+ server.setOption( TCP_NODELAY, true );
+ }
+
+ if ( server.supportedOptions().contains( SO_KEEPALIVE ) )
Review comment:
Is is only a test case.
It is not real code that will be executed by users
You don't need any special option.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640063766
@michael-o We agreed with @eolivelli to avoid Base64 and transfer the raw stream with bytes counter in the frame. This way we would be totally fast (below 1 microsecond) because we would only copy the arrays and the performance of `System.arrayCopy()` is logarithmic.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 edited a comment on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 edited a comment on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640286858
Now we use `sessionId` and `localhost` in mock tests or IP address of localhost.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r437759596
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/AuthenticationException.java
##########
@@ -0,0 +1,39 @@
+package org.apache.maven.plugin.surefire.extensions;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF 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.
+ */
+
+import org.apache.maven.surefire.extensions.ForkChannel;
+import org.apache.maven.surefire.extensions.util.CommandlineExecutor;
+
+import java.io.IOException;
+
+/**
+ * After the authentication has failed, {@link ForkChannel#connectToClient()} throws {@link AuthenticationException}
+ * and {@link org.apache.maven.plugin.surefire.booterclient.ForkStarter} should close {@link CommandlineExecutor}.
+ *
+ * @since 3.0.0-M5
+ */
+public class AuthenticationException extends IOException
Review comment:
Sorry but the callsequences expect IOException upto ForkStarter. I could simply throw the IOException but the mesage might be lost or the users do not read them and the stack trace with authentication exception would be understood by every developer.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640056533
If this is abstracted enough, we could also consider using Unix domain sockets in the future which will be availabe in Java soon and already also available in Windows. This performs even better than TCP sockets.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436304424
##########
File path: surefire-booter/src/test/java/org/apache/maven/surefire/booter/ForkedBooterMockTest.java
##########
@@ -362,6 +372,83 @@ public void run() throws Throwable
}
}
+ @Test
+ public void shouldAuthenticate() throws Exception
+ {
+ mockStatic( ForkedBooter.class );
+
+ doCallRealMethod()
+ .when( ForkedBooter.class, "lookupDecoderFactory", anyString() );
+
+ try ( final ServerSocketChannel server = ServerSocketChannel.open() )
+ {
+ if ( server.supportedOptions().contains( SO_REUSEADDR ) )
+ {
+ server.setOption( SO_REUSEADDR, true );
+ }
+
+ if ( server.supportedOptions().contains( TCP_NODELAY ) )
+ {
+ server.setOption( TCP_NODELAY, true );
+ }
+
+ if ( server.supportedOptions().contains( SO_KEEPALIVE ) )
+ {
+ server.setOption( SO_KEEPALIVE, true );
+ }
+
+ server.bind( new InetSocketAddress( 0 ) );
+ int serverPort = ( (InetSocketAddress) server.getLocalAddress() ).getPort();
+ final UUID uuid = UUID.randomUUID();
+ String url = "tcp://127.0.0.1:" + serverPort + "?auth=" + uuid;
Review comment:
This is in current branch. So the change must be done in here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436304484
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
##########
@@ -162,17 +172,20 @@ public void handleEvent( @Nonnull Event s )
private final class Client extends Thread
{
private final int port;
+ private final String sessionId;
- private Client( int port )
+ private Client( int port, String sessionId )
{
this.port = port;
+ this.sessionId = sessionId;
}
@Override
public void run()
{
try ( Socket socket = new Socket( "127.0.0.1", port ) )
Review comment:
Not in master.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r438064728
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +195,70 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID().toString() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments );
+ SurefireMasterProcessChannelProcessorFactory client = new SurefireMasterProcessChannelProcessorFactory() )
+ {
+ FutureTask<String> task = new FutureTask<>( new Callable<String>()
+ {
+ @Override
+ public String call() throws Exception
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ return "client connected";
+ }
+ } );
+
+ Thread t = new Thread( task );
+ t.setDaemon( true );
+ t.start();
+
+ server.connectToClient();
+
+ assertThat( task.get() )
+ .isEqualTo( "client connected" );
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
Review comment:
done
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +195,70 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] asfgit merged pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
asfgit merged pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-642501453
@michael-o
We have a problem with the `localhost` which was uncovered by GH build process on Mac OS and JDK 14. I have not noticed either.
```
[ERROR] Caused by: java.net.BindException: Can't assign requested address
[ERROR] at java.base/sun.nio.ch.Net.bind0(Native Method)
[ERROR] at java.base/sun.nio.ch.Net.bind(Net.java:479)
[ERROR] at java.base/sun.nio.ch.Net.bind(Net.java:468)
[ERROR] at java.base/sun.nio.ch.AsynchronousServerSocketChannelImpl.bind(AsynchronousServerSocketChannelImpl.java:163)
[ERROR] at org.apache.maven.plugin.surefire.extensions.SurefireForkChannel.<init>(SurefireForkChannel.java:90)
```
See the last comment at the [stackoverflow](https://stackoverflow.com/questions/17201598/cassandra-cant-assign-requested-address-at):
```
This exact issue happened to me. Running a VM and then switched VM from ethernet to wifi which changed my network settings. Checked hosts file and was set to 127.0.0.1. However when I pinged my localhost from my VM, I got 192.x.x.x. So it wasn't resolving properly. I then set to 127.0.0.1 last stated above and voila!
```
It looks like the local loopback was more stable on Docker.
`127.0.0.1` is always the same even if the network settings change in time.
I had to interrupt the release.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] olamy commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
olamy commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640145950
I don't think 127.0.0.1 neither localhost will work when executing within docker images running with k8s. That's why tools such testcontainer provide this https://www.testcontainers.org/features/networking/#getting-the-container-host.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] michael-o commented on a change in pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
michael-o commented on a change in pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#discussion_r436655314
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -113,6 +124,25 @@ public void connectToClient() throws IOException
}
}
+ private void authenticate() throws InterruptedException, ExecutionException, IOException
+ {
+ ByteBuffer hash = ByteBuffer.allocate( UUID_STRING_LENGTH );
Review comment:
The name of this variable should be changed.
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
Review comment:
Wouldn't this be handled anyway when the runtime exception is catched by JUnit?
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -129,7 +159,7 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
@Override
public String getForkNodeConnectionString()
{
- return "tcp://" + localHost + ":" + localPort;
+ return "tcp://" + localHost + ":" + localPort + ( sessionId == null ? "" : "?sessionId=" + sessionId );
Review comment:
If this is local host, why do we need it as a vaialble?
##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/SurefireMasterProcessChannelProcessorFactory.java
##########
@@ -75,6 +79,12 @@ public void connect( String channelConfig ) throws IOException
clientSocketChannel = open( withFixedThreadPool( 2, newDaemonThreadFactory() ) );
setTrueOptions( SO_REUSEADDR, TCP_NODELAY, SO_KEEPALIVE );
clientSocketChannel.connect( hostAddress ).get();
+ UUID sessionId = parseAuth( uri );
+ if ( sessionId != null )
+ {
+ ByteBuffer buff = ByteBuffer.wrap( sessionId.toString().getBytes( US_ASCII ) );
Review comment:
Think the canonical name is `buf`
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://" + connectionString.getHost() + ":" + connectionString.getPort()
+ + "?sessionId=6ba7b812-9dad-11d1-80b4-00c04fd430c8" );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
Review comment:
Same here
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+ server.connectToClient();
+ }
+ }
+
+ @Test( timeout = 10_000L )
+ public void shouldNotAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ URI connectionString = new URI( server.getForkNodeConnectionString() );
+ client.connect( "tcp://" + connectionString.getHost() + ":" + connectionString.getPort()
+ + "?sessionId=6ba7b812-9dad-11d1-80b4-00c04fd430c8" );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ throw new RuntimeException( e );
+ }
+ }
+ };
+ t.setDaemon( true );
+ t.start();
+
+ e.expect( IOException.class );
Review comment:
Stupid question: Don't you need to unwrap from `RuntimeException` first?
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
##########
@@ -102,7 +111,8 @@ public ConsoleLogger getConsoleLogger()
String localHost = InetAddress.getLocalHost().getHostAddress();
assertThat( channel.getForkNodeConnectionString() )
.startsWith( "tcp://" + localHost + ":" )
- .isNotEqualTo( "tcp://" + localHost + ":" );
+ .isNotEqualTo( "tcp://" + localHost + ":" )
Review comment:
same here
##########
File path: maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
##########
@@ -184,4 +192,74 @@ public void close()
.isPositive()
.isLessThanOrEqualTo( 6_000L );
}
+
+ @Test( timeout = 10_000L )
+ public void shouldAuthenticateClient() throws Exception
+ {
+ ForkNodeArguments forkNodeArguments = mock( ForkNodeArguments.class );
+ when( forkNodeArguments.getSessionId() ).thenReturn( UUID.randomUUID() );
+
+ try ( SurefireForkChannel server = new SurefireForkChannel( forkNodeArguments ) )
+ {
+ Thread t = new Thread()
+ {
+ @Override
+ public void run()
+ {
+ SurefireMasterProcessChannelProcessorFactory client
+ = new SurefireMasterProcessChannelProcessorFactory();
+ try
+ {
+ client.connect( server.getForkNodeConnectionString() );
+ }
+ catch ( IOException e )
+ {
+ e.printStackTrace();
Review comment:
Sorry, I am blind to see the obvious. Can you please link to the line?
##########
File path: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
##########
@@ -129,7 +159,7 @@ private final void setTrueOptions( SocketOption<Boolean>... options )
@Override
public String getForkNodeConnectionString()
{
- return "tcp://" + localHost + ":" + localPort;
+ return "tcp://" + localHost + ":" + localPort + ( sessionId == null ? "" : "?sessionId=" + sessionId );
Review comment:
I see, but there a few problems here if you want to have maximum flexibility:
* Just use variables `host` + `port`. Don't imply that you are limited to `localhost` even if you use it only
* Don't use `Inet4Address`. If the host is running on IPv6 only, the code will fail. Use `InetAddress` and it will work for both.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [maven-surefire] Tibor17 commented on pull request #300: [SUREFIRE-1796] The session of TCP channel should be authenticated
Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #300:
URL: https://github.com/apache/maven-surefire/pull/300#issuecomment-640062050
@michael-o Using the native sockets for the performance reasons is useless because here the Base64 is slower than the data transmission. We are talking about 50 microseconds per line (100 chars), and this delay is caused by the Apache impl of Base64.
Surefire is abstract enough to find one functionality in one place - now it is not a distributed logic.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org