archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
// MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
MRM - 1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
@Test
    public void testRepositoryGroupFirstRepositoryRequiresAuthentication()
        throws Exception
    {
        DavResourceLocator locator = new ArchivaDavResourceLocator( "", "/repository/" + LOCAL_REPO_GROUP
            + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP,
                                                                    new ArchivaDavLocatorFactory() );
        ManagedRepositoryContent internalRepo = createManagedRepositoryContent( INTERNAL_REPO );
        ManagedRepositoryContent releasesRepo = createManagedRepositoryContent( RELEASES_REPO );
        try
        {
            archivaConfigurationControl.reset();
            expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 3 );
            expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
            expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
            expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
            expect( request.getContextPath() ).andReturn( "" ).times( 2 );
            expect( repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
            expect(
                repoRequest.getLayout( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
                "legacy" );
            expect( repoRequest.toArtifactReference(
                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar"
            ) ).andReturn(
                Paths.get( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                          "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).toString());
            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
            expect( repoRequest.isArchetypeCatalog(
                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
            archivaConfigurationControl.replay();
            requestControl.replay();
            repoContentFactoryControl.replay();
            repoRequestControl.replay();
            resourceFactory.createResource( locator, request, response );
            archivaConfigurationControl.verify();
            requestControl.verify();
            repoContentFactoryControl.verify();
            repoRequestControl.verify();
            fail( "A DavException with 401 error code should have been thrown." );
        }
        catch ( DavException e )
        {
            assertEquals( 401, e.getErrorCode() );
        }
    }
@ Test public void testRepositoryGroupFirstRepositoryRequiresAuthentication ( ) throws Exception { DavResourceLocator locator = new ArchivaDavResourceLocator ( "" , "/repository/" + LOCAL_REPO_GROUP + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" , LOCAL_REPO_GROUP , new ArchivaDavLocatorFactory ( ) ) ; ManagedRepositoryContent internalRepo = createManagedRepositoryContent ( INTERNAL_REPO ) ; ManagedRepositoryContent releasesRepo = createManagedRepositoryContent ( RELEASES_REPO ) ; try { archivaConfigurationControl . reset ( ) ; expect ( archivaConfiguration . getConfiguration ( ) ) . andReturn ( config ) . times ( 3 ) ; expect ( request . getMethod ( ) ) . andReturn ( "GET" ) . times ( 3 ) ; expect ( request . getPathInfo ( ) ) . andReturn ( "org/apache/archiva" ) . times ( 0 , 2 ) ; expect ( repoFactory . getManagedRepositoryContent ( RELEASES_REPO ) ) . andReturn ( releasesRepo ) ; expect ( request . getRemoteAddr ( ) ) . andReturn ( "http://localhost:8080" ) . times ( 2 ) ; expect ( request . getDavSession ( ) ) . andReturn ( new ArchivaDavSession ( ) ) . times ( 2 ) ; expect ( request . getContextPath ( ) ) . andReturn ( "" ) . times ( 2 ) ; expect ( repoRequest . isSupportFile ( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ) . andReturn ( true ) ; expect ( repoRequest . getLayout ( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ) . andReturn ( "legacy" ) ; expect ( repoRequest . toArtifactReference ( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ) . andReturn ( null ) ; expect ( repoRequest . toNativePath ( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ) . andReturn ( Paths . get ( config . findManagedRepositoryById ( INTERNAL_REPO ) . getLocation ( ) , "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) . toString ( ) ) ; expect ( repoFactory . getManagedRepositoryContent ( INTERNAL_REPO ) ) . andReturn ( internalRepo ) ; expect ( repoRequest . isArchetypeCatalog ( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ) . andReturn ( false ) ; archivaConfigurationControl . replay ( ) ; requestControl . replay ( ) ; repoContentFactoryControl . replay ( ) ; repoRequestControl . replay ( ) ; resourceFactory . createResource ( locator , request , response ) ; archivaConfigurationControl . verify ( ) ; requestControl . verify ( ) ; repoContentFactoryControl . verify ( ) ; repoRequestControl . verify ( ) ; fail ( "A DavException with 401 error code should have been thrown." ) ; } catch ( DavException e ) { assertEquals ( 401 , e . getErrorCode ( ) ) ; } }
MRM-1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group
MRM - 1232 - Unable to get artifacts from repositories which requires Repository Manager role using repository group