]> source.dussan.org Git - sonarqube.git/blob
f8cbf8c944d3bceed42766108366f4982f960d8c
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2023 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 package org.sonar.scanner.scan;
21
22 import org.assertj.core.api.Assertions;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.sonar.api.CoreProperties;
28 import org.sonar.api.config.internal.MapSettings;
29 import org.sonar.api.notifications.AnalysisWarnings;
30 import org.sonar.api.utils.log.LogTester;
31 import org.sonar.api.utils.log.LoggerLevel;
32
33 import static org.mockito.Mockito.times;
34 import static org.mockito.Mockito.verify;
35 import static org.mockito.Mockito.verifyNoInteractions;
36 import static org.sonar.scanner.scan.DeprecatedPropertiesWarningGenerator.CREDENTIALS_WARN_MESSAGE;
37
38 public class DeprecatedPropertiesWarningGeneratorTest {
39
40   @Rule
41   public LogTester logger = new LogTester();
42
43   private final MapSettings settings = new MapSettings();
44
45   private final AnalysisWarnings analysisWarnings = Mockito.spy(AnalysisWarnings.class);
46   private final DeprecatedPropertiesWarningGenerator underTest = new DeprecatedPropertiesWarningGenerator(settings.asConfig(),
47     analysisWarnings);
48
49   @Before
50   public void setUp() throws Exception {
51     settings.removeProperty(CoreProperties.LOGIN);
52     settings.removeProperty(CoreProperties.PASSWORD);
53   }
54
55   @Test
56   public void execute_whenUsingLogin_shouldAddWarning() {
57     settings.setProperty(CoreProperties.LOGIN, "test");
58
59     underTest.execute();
60
61     verify(analysisWarnings, times(1)).addUnique(CREDENTIALS_WARN_MESSAGE);
62     Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(CREDENTIALS_WARN_MESSAGE);
63   }
64
65   @Test
66   public void execute_whenUsingPassword_shouldAddWarning() {
67     settings.setProperty(CoreProperties.PASSWORD, "winner winner chicken dinner");
68
69     underTest.execute();
70
71     verify(analysisWarnings, times(1)).addUnique(CREDENTIALS_WARN_MESSAGE);
72     Assertions.assertThat(logger.logs(LoggerLevel.WARN)).contains(CREDENTIALS_WARN_MESSAGE);
73   }
74
75   @Test
76   public void execute_whenNotUsingLoginOrPassword_shouldNotAddWarning() {
77     underTest.execute();
78
79     verifyNoInteractions(analysisWarnings);
80     Assertions.assertThat(logger.logs(LoggerLevel.WARN)).isEmpty();
81   }
82
83 }