@ -9,12 +9,15 @@
* /
* /
package org.eclipse.jgit.transport ;
package org.eclipse.jgit.transport ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.catchThrowableOfType ;
import java.io.IOException ;
import java.io.IOException ;
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.Map ;
import java.util.Map ;
import org.eclipse.jgit.errors.PackProtocolException ;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable ;
import org.eclipse.jgit.errors.TransportException ;
import org.eclipse.jgit.errors.TransportException ;
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector ;
import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector ;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription ;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription ;
@ -25,17 +28,11 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevBlob ;
import org.eclipse.jgit.revwalk.RevBlob ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.revwalk.RevCommit ;
import org.eclipse.jgit.transport.UploadPack.RequestValidator ;
import org.eclipse.jgit.transport.UploadPack.RequestValidator ;
import org.hamcrest.Matchers ;
import org.junit.Before ;
import org.junit.Before ;
import org.junit.Rule ;
import org.junit.Test ;
import org.junit.Test ;
import org.junit.rules.ExpectedException ;
public abstract class RequestValidatorTestCase {
public abstract class RequestValidatorTestCase {
@Rule
public ExpectedException thrown = ExpectedException . none ( ) ;
private RevCommit reachableCommit ;
private RevCommit reachableCommit ;
private RevCommit tipAdvertisedCommit ;
private RevCommit tipAdvertisedCommit ;
@ -111,156 +108,165 @@ public abstract class RequestValidatorTestCase {
protected abstract boolean isUnreachableBlobValid ( ) ;
protected abstract boolean isUnreachableBlobValid ( ) ;
@Test
@Test
public void validateReachableCommitWithBitmaps ( )
public void validateReachableCommitWithBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithBitmaps ( ) ) ,
Arrays . asList ( reachableCommit ) ) ;
if ( ! isReachableCommitValid ( ) ) {
if ( ! isReachableCommitValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers
"want " + reachableCommit . name ( ) + " not valid" ) ;
. containsString (
return ;
"want " + reachableCommit . name ( ) + " not valid" ) ) ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( reachableCommit ) ) ;
}
}
@Test
@Test
public void validateReachableCommitWithoutBitmaps ( )
public void validateReachableCommitWithoutBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
Arrays . asList ( reachableCommit ) ) ;
if ( ! isReachableCommitValid ( ) ) {
if ( ! isReachableCommitValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + reachableCommit . name ( ) + " not valid" ) ;
"want " + reachableCommit . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( reachableCommit ) ) ;
}
}
@Test
@Test
public void validateAdvertisedTipWithBitmaps ( )
public void validateAdvertisedTipWithBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithBitmaps ( ) ) ,
Arrays . asList ( tipAdvertisedCommit ) ) ;
if ( ! isAdvertisedTipValid ( ) ) {
if ( ! isAdvertisedTipValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + tipAdvertisedCommit . name ( ) + " not valid" ) ;
"want " + tipAdvertisedCommit . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( tipAdvertisedCommit ) ) ;
}
}
@Test
@Test
public void validateAdvertisedTipWithoutBitmaps ( )
public void validateAdvertisedTipWithoutBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
Arrays . asList ( tipAdvertisedCommit ) ) ;
if ( ! isAdvertisedTipValid ( ) ) {
if ( ! isAdvertisedTipValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + tipAdvertisedCommit . name ( ) + " not valid" ) ;
"want " + tipAdvertisedCommit . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( tipAdvertisedCommit ) ) ;
}
}
@Test
@Test
public void validateUnadvertisedTipWithBitmaps ( )
public void validateUnadvertisedTipWithBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithBitmaps ( ) ) ,
Arrays . asList ( tipUnadvertisedCommit ) ) ;
if ( ! isUnadvertisedTipCommitValid ( ) ) {
if ( ! isUnadvertisedTipCommitValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + tipUnadvertisedCommit . name ( ) + " not valid" ) ;
"want " + tipUnadvertisedCommit . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( tipUnadvertisedCommit ) ) ;
}
}
@Test
@Test
public void validateUnadvertisedTipWithoutBitmaps ( )
public void validateUnadvertisedTipWithoutBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
Arrays . asList ( tipUnadvertisedCommit ) ) ;
if ( ! isUnadvertisedTipCommitValid ( ) ) {
if ( ! isUnadvertisedTipCommitValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + tipUnadvertisedCommit . name ( ) + " not valid" ) ;
"want " + tipUnadvertisedCommit . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( tipUnadvertisedCommit ) ) ;
}
}
@Test
@Test
public void validateUnreachableCommitWithBitmaps ( )
public void validateUnreachableCommitWithBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithBitmaps ( ) ) ,
Arrays . asList ( unreachableCommit ) ) ;
if ( ! isUnreachableCommitValid ( ) ) {
if ( ! isUnreachableCommitValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + unreachableCommit . name ( ) + " not valid" ) ;
"want " + unreachableCommit . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( unreachableCommit ) ) ;
}
}
@Test
@Test
public void validateUnreachableCommitWithoutBitmaps ( )
public void validateUnreachableCommitWithoutBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
Arrays . asList ( unreachableCommit ) ) ;
if ( ! isUnreachableCommitValid ( ) ) {
if ( ! isUnreachableCommitValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + unreachableCommit . name ( ) + " not valid" ) ;
"want " + unreachableCommit . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( unreachableCommit ) ) ;
}
}
@Test
@Test
public void validateReachableBlobWithBitmaps ( )
public void validateReachableBlobWithBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithBitmaps ( ) ) ,
Arrays . asList ( reachableBlob ) ) ;
if ( ! isReachableBlobValid_withBitmaps ( ) ) {
if ( ! isReachableBlobValid_withBitmaps ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + reachableBlob . name ( ) + " not valid" ) ;
"want " + reachableBlob . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( reachableBlob ) ) ;
}
}
@Test
@Test
public void validateReachableBlobWithoutBitmaps ( )
public void validateReachableBlobWithoutBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
Arrays . asList ( reachableBlob ) ) ;
if ( ! isReachableBlobValid_withoutBitmaps ( ) ) {
if ( ! isReachableBlobValid_withoutBitmaps ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + reachableBlob . name ( ) + " not valid" ) ;
"want " + reachableBlob . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( reachableBlob ) ) ;
}
}
@Test
@Test
public void validateUnreachableBlobWithBitmaps ( )
public void validateUnreachableBlobWithBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithBitmaps ( ) ) ,
Arrays . asList ( unreachableBlob ) ) ;
if ( ! isUnreachableBlobValid ( ) ) {
if ( ! isUnreachableBlobValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + unreachableBlob . name ( ) + " not valid" ) ;
"want " + unreachableBlob . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( unreachableBlob ) ) ;
}
}
@Test
@Test
public void validateUnreachableBlobWithoutBitmaps ( )
public void validateUnreachableBlobWithoutBitmaps ( ) throws Throwable {
throws PackProtocolException , IOException {
ThrowingCallable c = ( ) - > createValidator ( ) . checkWants (
getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
Arrays . asList ( unreachableBlob ) ) ;
if ( ! isUnreachableBlobValid ( ) ) {
if ( ! isUnreachableBlobValid ( ) ) {
thrown . expect ( TransportException . class ) ;
assertTransportException ( c ,
thrown . expectMessage ( Matchers . containsString (
"want " + unreachableBlob . name ( ) + " not valid" ) ;
"want " + unreachableBlob . name ( ) + " not valid" ) ) ;
return ;
}
}
createValidator ( ) . checkWants ( getUploadPack ( getRepoWithoutBitmaps ( ) ) ,
c . call ( ) ;
Arrays . asList ( unreachableBlob ) ) ;
}
private void assertTransportException ( ThrowingCallable c ,
String messageContent ) throws AssertionError {
assertThat ( catchThrowableOfType ( c , TransportException . class ) )
. hasMessageContaining ( messageContent ) ;
}
}
private UploadPack getUploadPack ( Repository repository ) throws IOException {
private UploadPack getUploadPack ( Repository repository ) throws IOException {