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:
us...@infra.apache.org


Reply via email to