mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-24 01:09:48 +01:00
Fix permission errors
The BaseReceivePackFactory re-used the GitReceiveHook. The problem is, that the hook is not thread safe. Due to the re-usage, the repository could have been changed during processing post receive hooks. With this, the factory will always create a new receive pack. Pushed-by: Rene Pfeuffer<rene.pfeuffer@cloudogu.com> Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com> Committed-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
@@ -50,6 +50,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -88,8 +90,7 @@ public class BaseReceivePackFactoryTest {
|
||||
when(handler.getConfig()).thenReturn(gitConfig);
|
||||
when(handler.getRepositoryId(repository.getConfig())).thenReturn("heart-of-gold");
|
||||
|
||||
ReceivePack receivePack = new ReceivePack(repository);
|
||||
when(wrappedReceivePackFactory.create(request, repository)).thenReturn(receivePack);
|
||||
when(wrappedReceivePackFactory.create(request, repository)).thenAnswer(invocation -> new ReceivePack(repository));
|
||||
|
||||
when(gitRepositoryConfigStoreProvider.getGitRepositoryConfig("heart-of-gold")).thenReturn(gitRepositoryConfig);
|
||||
|
||||
@@ -130,4 +131,11 @@ public class BaseReceivePackFactoryTest {
|
||||
assertFalse(receivePack.isAllowNonFastForwards());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotReUseGitReceiveHook() throws Exception {
|
||||
ReceivePack receivePack1 = factory.create(request, repository);
|
||||
ReceivePack receivePack2 = factory.create(request, repository);
|
||||
|
||||
assertThat(receivePack1.getPostReceiveHook(), not(sameInstance(receivePack2.getPostReceiveHook())));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user