felixauringer commented on code in PR #2773: URL: https://github.com/apache/james-project/pull/2773#discussion_r2555090921
########## 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 enabled the test and kept the comment. -- 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]
