chibenwa commented on code in PR #2773:
URL: https://github.com/apache/james-project/pull/2773#discussion_r2463860187


##########
mpt/impl/managesieve/core/src/main/resources/org/apache/james/managesieve/scripts/capability.test:
##########
@@ -38,8 +38,9 @@ S: "VERSION" "1.0"
 S: OK
 
 C: AUTHENTICATE "PLAIN"
-S: \+ ""
-C:  user password
+S: ""
+S: OK
+C: "user password"

Review Comment:
   I am not fully sure that this code is compliant with eg Thunderbird extension
   
   From my memories of SASL we either have
   
   ```
   C: AUTHENTICATE "PLAIN" "AGFsaWNlAHNlY3JldA=="\r\n
   S: OK "Logged in"
   ```
   
   Or
   
   ```
   C: AUTHENTICATE "PLAIN"\r\n
   S: +\r\n
   C: AGFsaWNlAHNlY3JldA==\r\n
   S: OK "Logged in"\r\n
   ```
   
   (with base64 being `\0LOGIN\0password`)
   
   So seing not base64 encoded, qutoed password seems indeed weird to me...
   
   From the above exemple the initial server response is `+ \r\n`
   
   -----------------
   
   After reading the code below I think the client payload handling is 
retro-compatible.
   
   So I would welcome tests that demonstrate previous behaviours are still 
supported.



##########
server/protocols/protocols-managesieve/src/test/java/org/apache/james/managesieveserver/AuthenticateTest.java:
##########
@@ -0,0 +1,220 @@
+/****************************************************************
+ * 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.                                           *
+ ****************************************************************/
+
+package org.apache.james.managesieveserver;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+public class AuthenticateTest {
+    private ManageSieveClient client;
+    private final ManageSieveServerTestSystem testSystem;
+
+    public AuthenticateTest() throws Exception {
+        this.testSystem = new ManageSieveServerTestSystem();
+    }
+
+    @BeforeEach
+    void setUp() throws Exception {
+        this.testSystem.setUp();
+        this.client = new ManageSieveClient();
+        this.client.connect(this.testSystem.getBindedIP(), 
this.testSystem.getBindedPort());
+        this.client.readResponse();
+    }
+
+    @AfterEach
+    void tearDown() {
+        this.testSystem.manageSieveServer.destroy();
+    }
+
+    @Test
+    void plainLoginWithCorrectCredentialsShouldSucceed() throws IOException {
+        this.authenticatePlain();
+    }
+
+    @Test
+    void plainLoginWithWrongPasswordShouldNotSucceed() throws IOException {
+        String initialClientResponse = "\0" + 
ManageSieveServerTestSystem.USERNAME.asString() + "\0" + 
ManageSieveServerTestSystem.PASSWORD + "wrong";
+        this.client.sendCommand("AUTHENTICATE \"PLAIN\" \"" + 
Base64.getEncoder().encodeToString(initialClientResponse.getBytes(StandardCharsets.UTF_8))
 + "\"");
+        ManageSieveClient.ServerResponse authenticationResponse = 
this.client.readResponse();
+        
Assertions.assertThat(authenticationResponse.responseType()).isEqualTo(ManageSieveClient.ResponseType.NO);
+    }
+
+    @Test
+    void plainLoginWithNotExistingUserShouldNotSucceed() throws IOException {
+        String initialClientResponse = "\0" + 
ManageSieveServerTestSystem.USERNAME.asString() + "not-existing" + "\0" + "pwd";
+        this.client.sendCommand("AUTHENTICATE \"PLAIN\" \"" + 
Base64.getEncoder().encodeToString(initialClientResponse.getBytes(StandardCharsets.UTF_8))
 + "\"");
+        ManageSieveClient.ServerResponse authenticationResponse = 
this.client.readResponse();
+        
Assertions.assertThat(authenticationResponse.responseType()).isEqualTo(ManageSieveClient.ResponseType.NO);
+    }
+
+    @Test
+    void plainLoginWithoutPasswordShouldNotSucceed() throws IOException {
+        String initialClientResponse = "\0" + 
ManageSieveServerTestSystem.USERNAME.asString() + "\0";
+        this.client.sendCommand("AUTHENTICATE \"PLAIN\" \"" + 
Base64.getEncoder().encodeToString(initialClientResponse.getBytes(StandardCharsets.UTF_8))
 + "\"");
+        ManageSieveClient.ServerResponse authenticationResponse = 
this.client.readResponse();
+        
Assertions.assertThat(authenticationResponse.responseType()).isEqualTo(ManageSieveClient.ResponseType.NO);
+    }
+
+    // The SASL PLAIN standard (https://datatracker.ietf.org/doc/html/rfc4616) 
defines the following message:
+    // message = [authzid] UTF8NUL authcid UTF8NUL passwd
+    // The current code is more lenient and accepts the message without the 
first null byte.
+    @Disabled
+    @Test

Review Comment:
   I we think it is a good thing to be more relaxed than the RFC, I see no 
issue:
   
    - Keeping the valuable comment
    - Testing the existing behaviour with a passing test.



##########
protocols/managesieve/src/main/java/org/apache/james/managesieve/core/PlainAuthenticationProcessor.java:
##########
@@ -50,7 +50,7 @@ public PlainAuthenticationProcessor(UsersRepository 
usersRepository) {
 
     @Override
     public String initialServerResponse(Session session) {
-        return "+ \"\"";
+        return "\"\"\r\nOK";

Review Comment:
   Why do we need changing the initial server response here?



##########
mpt/impl/managesieve/core/src/main/resources/org/apache/james/managesieve/scripts/authenticate.test:
##########
@@ -18,20 +18,25 @@
 ################################################################
 
 C: AUTHENTICATE
-S: NO ManageSieve syntax is incorrect : You must specify a SASL mechanism as 
an argument of AUTHENTICATE command
+S: NO "ManageSieve syntax is incorrect: quoted SASL mechanism must be supplied"

Review Comment:
   +1 for fixing this likely non-compliant unpquoted no explanation (thanks)



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to