]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19558 made webserver-auth tests compatible with project/branch uuid
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Fri, 30 Jun 2023 12:57:56 +0000 (14:57 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 30 Jun 2023 20:03:15 +0000 (20:03 +0000)
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentDbTester.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/BasicAuthenticationTest.java
server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/event/AuthenticationExceptionMatcher.java [deleted file]
server/sonar-webserver-auth/src/test/java/org/sonar/server/user/UserSessionFactoryImplTest.java

index 9cbe6155a8c0ba7030b569bdd5c79a5d5ad22473..277cacdc8203b92651f6ea74fe37ca923ee231a6 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.db.component;
 
 import java.util.Arrays;
 import java.util.List;
-import java.util.Optional;
 import java.util.function.Consumer;
 import javax.annotation.Nullable;
 import org.sonar.api.resources.Qualifiers;
index eb8ba91b3715a9b7b552ec080c7b81dca451064e..4269f067c95b46b8dd017d1df936980103d3661b 100644 (file)
@@ -62,7 +62,7 @@ public class BasicAuthenticationTest {
   private static final String AUTHORIZATION_HEADER = "Authorization";
 
   @Rule
-  public DbTester db = DbTester.create(System2.INSTANCE);
+  public DbTester db = DbTester.create(true);
 
   private final CredentialsAuthentication credentialsAuthentication = mock(CredentialsAuthentication.class);
   private final UserTokenAuthentication userTokenAuthentication = mock(UserTokenAuthentication.class);
diff --git a/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/event/AuthenticationExceptionMatcher.java b/server/sonar-webserver-auth/src/test/java/org/sonar/server/authentication/event/AuthenticationExceptionMatcher.java
deleted file mode 100644 (file)
index a27902a..0000000
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2023 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.server.authentication.event;
-
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-import org.hamcrest.Description;
-import org.hamcrest.TypeSafeMatcher;
-
-import static java.util.Objects.requireNonNull;
-import static org.sonar.server.authentication.event.AuthenticationEvent.Source;
-
-/**
- * Matcher for {@link AuthenticationException} to be used with {@link org.junit.rules.ExpectedException} JUnit Rule.
- *
- * <p>
- * Usage:
- * <pre>
- * expectedException.expect(authenticationException().from(Source.local(Method.BASIC_TOKEN)).withLogin("foo").andNoPublicMessage());
- * </pre>
- * </p>
- */
-public class AuthenticationExceptionMatcher extends TypeSafeMatcher<Throwable> {
-  private final Source source;
-  @CheckForNull
-  private final String login;
-  @CheckForNull
-  private final String publicMessage;
-
-  private AuthenticationExceptionMatcher(Source source, @Nullable String login, @Nullable String publicMessage) {
-    this.source = requireNonNull(source, "source can't be null");
-    this.login = login;
-    this.publicMessage = publicMessage;
-  }
-
-  public static Builder authenticationException() {
-    return new Builder();
-  }
-
-  public static class Builder {
-    private Source source;
-    private String login;
-
-    public Builder from(Source source) {
-      this.source = checkSource(source);
-      return this;
-    }
-
-    public Builder withLogin(String login) {
-      this.login = requireNonNull(login, "expected login can't be null");
-      return this;
-    }
-
-    public Builder withoutLogin() {
-      this.login = null;
-      return this;
-    }
-
-    public AuthenticationExceptionMatcher andNoPublicMessage() {
-      return new AuthenticationExceptionMatcher(this.source, this.login, null);
-    }
-
-    public AuthenticationExceptionMatcher andPublicMessage(String publicMessage){
-      return new AuthenticationExceptionMatcher(this.source, this.login, requireNonNull(publicMessage));
-    }
-
-    private static Source checkSource(Source source) {
-      return requireNonNull(source, "expected source can't be null");
-    }
-  }
-
-  @Override
-  protected boolean matchesSafely(Throwable throwable) {
-    return check(throwable) == null;
-  }
-
-  private String check(Throwable throwable) {
-    if (!throwable.getClass().isAssignableFrom(AuthenticationException.class)) {
-      return "exception is not a AuthenticationException";
-    }
-    AuthenticationException authenticationException = (AuthenticationException) throwable;
-    if (!this.source.equals(authenticationException.getSource())) {
-      return "source is \"" + authenticationException.getSource() + "\"";
-    }
-
-    String login = authenticationException.getLogin();
-    if (this.login == null) {
-      if (login != null) {
-        return "login is \"" + login + "\"";
-      }
-    } else if (login == null) {
-      return "login is null";
-    } else if (!this.login.equals(login)) {
-      return "login is \"" + login + "\"";
-    }
-
-    String publicMessage = authenticationException.getPublicMessage();
-    if (this.publicMessage == null) {
-      if (publicMessage != null) {
-        return "publicMessage is \"" + publicMessage + "\"";
-      }
-    } else if (publicMessage == null) {
-      return "publicMessage is null";
-    } else if (!this.publicMessage.equals(publicMessage)) {
-      return "publicMessage is \"" + publicMessage + "\"";
-    }
-
-    return null;
-  }
-
-  @Override
-  public void describeTo(Description description) {
-    description.appendText("AuthenticationException with source ").appendText(source.toString());
-    if (login == null) {
-      description.appendText(", no login");
-    } else {
-      description.appendText(", login \"").appendText(login).appendText("\"");
-    }
-    if (publicMessage == null) {
-      description.appendText(" and no publicMessage");
-    } else {
-      description.appendText(" and publicMessage \"").appendText(publicMessage).appendText("\"");
-    }
-  }
-
-  @Override
-  protected void describeMismatchSafely(Throwable item, Description mismatchDescription) {
-    mismatchDescription.appendText(check(item));
-  }
-}
index c1da3ff7b051bd78c00d265dd005467efb7629bf..f7e84722ad944e62b83106fd67077ac7acea0771 100644 (file)
@@ -32,12 +32,6 @@ import static org.assertj.core.api.Assertions.assertThat;
 @RunWith(MockitoJUnitRunner.class)
 public class UserSessionFactoryImplTest {
 
-  @Mock
-  private DbClient dbClient;
-
-  @Mock
-  private UserLastConnectionDatesUpdater userLastConnectionDatesUpdater;
-
   @InjectMocks
   private UserSessionFactoryImpl userSessionFactory;