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


Reply via email to