mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-23 23:10:50 +01:00
Merge with default
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package sonia.scm.repository;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.security.AccessToken;
|
||||
import sonia.scm.security.Xsrf;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Optional.empty;
|
||||
import static java.util.Optional.of;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HgEnvironmentTest {
|
||||
|
||||
@Mock
|
||||
HgRepositoryHandler handler;
|
||||
@Mock
|
||||
HgHookManager hookManager;
|
||||
|
||||
@Test
|
||||
void shouldExtractXsrfTokenWhenSet() {
|
||||
AccessToken accessToken = mock(AccessToken.class);
|
||||
when(accessToken.compact()).thenReturn("");
|
||||
when(accessToken.getCustom(Xsrf.TOKEN_KEY)).thenReturn(of("XSRF Token"));
|
||||
when(hookManager.getAccessToken()).thenReturn(accessToken);
|
||||
|
||||
Map<String, String> environment = new HashMap<>();
|
||||
HgEnvironment.prepareEnvironment(environment, handler, hookManager);
|
||||
|
||||
assertThat(environment).contains(entry("SCM_XSRF", "XSRF Token"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldIgnoreXsrfWhenNotSetButStillContainDummy() {
|
||||
AccessToken accessToken = mock(AccessToken.class);
|
||||
when(accessToken.compact()).thenReturn("");
|
||||
when(accessToken.getCustom(Xsrf.TOKEN_KEY)).thenReturn(empty());
|
||||
when(hookManager.getAccessToken()).thenReturn(accessToken);
|
||||
|
||||
Map<String, String> environment = new HashMap<>();
|
||||
HgEnvironment.prepareEnvironment(environment, handler, hookManager);
|
||||
|
||||
assertThat(environment).containsKeys("SCM_XSRF");
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@ package sonia.scm.repository;
|
||||
import org.junit.Assume;
|
||||
import sonia.scm.SCMContext;
|
||||
import sonia.scm.TempDirRepositoryLocationResolver;
|
||||
import sonia.scm.security.AccessToken;
|
||||
import sonia.scm.store.InMemoryConfigurationStoreFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -107,7 +108,6 @@ public final class HgTestUtil
|
||||
RepositoryLocationResolver repositoryLocationResolver = new TempDirRepositoryLocationResolver(directory);
|
||||
HgRepositoryHandler handler =
|
||||
new HgRepositoryHandler(new InMemoryConfigurationStoreFactory(), new HgContextProvider(), repositoryLocationResolver, null, null);
|
||||
Path repoDir = directory.toPath();
|
||||
handler.init(context);
|
||||
|
||||
return handler;
|
||||
@@ -128,7 +128,9 @@ public final class HgTestUtil
|
||||
"http://localhost:8081/scm/hook/hg/");
|
||||
when(hookManager.createUrl(any(HttpServletRequest.class))).thenReturn(
|
||||
"http://localhost:8081/scm/hook/hg/");
|
||||
when(hookManager.getCredentials()).thenReturn("");
|
||||
AccessToken accessToken = mock(AccessToken.class);
|
||||
when(accessToken.compact()).thenReturn("");
|
||||
when(hookManager.getAccessToken()).thenReturn(accessToken);
|
||||
|
||||
return hookManager;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user