Arsnael commented on code in PR #2810: URL: https://github.com/apache/james-project/pull/2810#discussion_r2350506424
########## server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/ConfiguredAuthTest.java: ########## @@ -0,0 +1,82 @@ +/**************************************************************** + * 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.smtpserver; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; + +import java.net.InetSocketAddress; +import java.util.Base64; + +import org.apache.commons.net.smtp.SMTPClient; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class ConfiguredAuthTest { + private final SMTPServerTestSystem smtpServerTestSystem = new SMTPServerTestSystem(); + + @BeforeEach + void setUp() throws Exception { + smtpServerTestSystem.setUp("smtpserver-configured-auth.xml"); + } + + @AfterEach + void tearDown() { + smtpServerTestSystem.smtpServer.destroy(); + } + + + @ParameterizedTest + @CsvSource({ + "[email protected], secret123456", + "[email protected], here_to_ease_secret_rotation", + "[email protected], here_to_give_different_creds_to_each_app", + "[email protected], secret234567", + }) + void authShouldBePossibleWHenMatchingConfiguredValue(String username, String password) throws Exception { + SMTPClient smtpProtocol = new SMTPClient(); + InetSocketAddress bindedAddress = smtpServerTestSystem.getBindedAddress(); + smtpProtocol.connect(bindedAddress.getAddress().getHostAddress(), bindedAddress.getPort()); + + smtpProtocol.sendCommand("AUTH PLAIN"); + smtpProtocol.sendCommand(Base64.getEncoder().encodeToString(("\0" + username + "\0" + password + "\0").getBytes(UTF_8))); + assertThat(smtpProtocol.getReplyCode()) + .isEqualTo(235); + } + + @ParameterizedTest + @CsvSource({ + "[email protected], bad", + "[email protected], here_to_ease_secret_rotation", + "[email protected], secret123456", + "noreply-tdrive, secret123456" + }) + void authShouldBeDeniedWhenMatchingConfiguredValue(String username, String password) throws Exception { Review Comment: ```suggestion void authShouldBeDeniedWhenNotMatchingConfiguredValue(String username, String password) throws Exception { ``` -- 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]
