[MRM-1327] make sure getArtifacts query is restricted to the right repository

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1053780 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2010-12-30 01:29:50 +00:00
parent bf3058dbeb
commit e28ae522d1
2 changed files with 18 additions and 2 deletions

View File

@ -812,6 +812,21 @@ public abstract class AbstractMetadataRepositoryTest
assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) ); assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
} }
public void testGetArtifactsByRepoIdMultipleCopies()
throws Exception
{
ArtifactMetadata artifact = createArtifact();
repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact );
ArtifactMetadata secondArtifact = createArtifact();
secondArtifact.setRepositoryId( OTHER_REPO_ID );
repository.updateArtifact( OTHER_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, secondArtifact );
// test it restricts to the appropriate repository
assertEquals( Collections.singletonList( artifact ), repository.getArtifacts( TEST_REPO_ID ) );
assertEquals( Collections.singletonList( secondArtifact ), repository.getArtifacts( OTHER_REPO_ID ) );
}
public void testGetNamespacesWithSparseDepth() public void testGetNamespacesWithSparseDepth()
throws Exception throws Exception
{ {

View File

@ -79,7 +79,7 @@ public class JcrMetadataRepository
static final String FACET_NODE_TYPE = "archiva:facet"; static final String FACET_NODE_TYPE = "archiva:facet";
private static final String QUERY_ARTIFACTS = "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "]"; private static final String QUERY_ARTIFACTS = "SELECT * FROM [" + ARTIFACT_NODE_TYPE + "] AS artifact";
private final Map<String, MetadataFacetFactory> metadataFacetFactories; private final Map<String, MetadataFacetFactory> metadataFacetFactories;
@ -630,7 +630,8 @@ public class JcrMetadataRepository
{ {
List<ArtifactMetadata> artifacts; List<ArtifactMetadata> artifacts;
String q = QUERY_ARTIFACTS; String q = QUERY_ARTIFACTS + " WHERE ISDESCENDANTNODE(artifact,'/" + getRepositoryContentPath( repositoryId ) +
"')";
try try
{ {