Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package org.commonjava.indy.content.browse;

import org.commonjava.cdi.util.weft.ThreadContext;
import org.commonjava.indy.IndyWorkflowException;
import org.commonjava.indy.content.ContentManager;
import org.commonjava.indy.content.StoreResource;
import org.commonjava.indy.content.browse.model.ContentBrowseResult;
import org.commonjava.indy.data.IndyDataException;
import org.commonjava.indy.data.StoreDataManager;
import org.commonjava.indy.util.RequestContextHelper;
import org.commonjava.o11yphant.metrics.annotation.Measure;
import org.commonjava.indy.model.core.ArtifactStore;
import org.commonjava.indy.model.core.StoreKey;
Expand All @@ -43,6 +45,7 @@
import java.util.Set;
import java.util.TreeMap;

import static org.commonjava.indy.pkg.npm.model.NPMPackageTypeDescriptor.NPM_METADATA_NAME;
import static org.commonjava.maven.galley.util.PathUtils.normalize;
import static org.commonjava.maven.galley.util.PathUtils.parentPath;

Expand Down Expand Up @@ -89,7 +92,13 @@ private ContentBrowseResult renderResult( final StoreKey key, final String reque
String path = requestPath.endsWith( "/" ) ? requestPath : requestPath + "/";

final ArtifactStore store = getStore( key );

// This is used to let galley ignore the NPMPathStorageCalculator handling,
// which will append package.json to a directory transfer and make listing not applicable.
ThreadContext context = ThreadContext.getContext( true );
context.put( RequestContextHelper.IS_RAW_VIEW, Boolean.TRUE );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dup? line 101 also set this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 101 set it to false back. I ref the PromotionManager line 666.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I see. LGTM.

final List<StoreResource> listed = contentManager.list( store, path, eventMetadata );
context.put( RequestContextHelper.IS_RAW_VIEW, Boolean.FALSE );

final Map<String, Set<String>> listingUrls = new TreeMap<>();

Expand All @@ -115,6 +124,11 @@ private ContentBrowseResult renderResult( final StoreKey key, final String reque
if ( p.endsWith( "-" ) || p.endsWith( "-/" ) )
{
//skip npm adduser path to avoid the sensitive info showing.
//continue;
}
if ( p.endsWith( NPM_METADATA_NAME ) )
{
//the package.json should not be visible for user
continue;
}
else if ( pass == 1 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@
package org.commonjava.indy.content.browse.ftest;

import org.apache.commons.io.IOUtils;
import org.commonjava.indy.client.core.IndyClientModule;
import org.commonjava.indy.content.browse.client.IndyContentBrowseClientModule;
import org.commonjava.indy.content.browse.model.ContentBrowseResult;
import org.commonjava.indy.ftest.core.AbstractContentManagementTest;
import org.commonjava.indy.model.core.HostedRepository;
import org.commonjava.indy.model.core.StoreKey;
import org.commonjava.indy.model.core.io.IndyObjectMapper;
import org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor;
import org.commonjava.indy.pkg.npm.model.NPMPackageTypeDescriptor;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.Collection;
import java.util.Collections;

import static org.commonjava.indy.model.core.StoreType.hosted;
import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -78,12 +84,20 @@ public void run()

final String dirPath = "/@babel/opossum";
final String path = dirPath + "/package.json";
final String tarPath = dirPath + "/-/opossum-5.0.0.tgz";

final StoreKey testKey = hostedRepository.getKey();

assertThat( client.content().exists( testKey, tarPath ), equalTo( false ) );

client.content().store( testKey, tarPath, stream );

assertThat( client.content().exists( testKey, tarPath ), equalTo( true ) );

final InputStream stream2 = new ByteArrayInputStream( content.getBytes() );
assertThat( client.content().exists( testKey, path ), equalTo( false ) );

client.content().store( testKey, path, stream );
client.content().store( testKey, path, stream2 );

assertThat( client.content().exists( testKey, path ), equalTo( true ) );

Expand All @@ -103,8 +117,29 @@ public void run()
assertThat( json.contains( "/@babel/" ), equalTo( true ) );
}

IndyContentBrowseClientModule browseClientModule = client.module( IndyContentBrowseClientModule.class );

ContentBrowseResult browseResult = browseClientModule.getContentList(testKey, "/@babel/opossum");
String browseResultInJson = new IndyObjectMapper(false).writeValueAsString(browseResult);

assertThat( browseResultInJson.contains("/@babel/opossum/-/"), equalTo(true) );
assertThat( "no metadata result", browseResult, notNullValue() );

try(InputStream jsonIn = client.content().get( testKey, "/@babel/opossum" ))
{
assertThat( jsonIn, notNullValue() );
String json = IOUtils.toString( jsonIn );
assertEquals(content, json);
}

assertThat( client.content()
.exists( testKey, path ), equalTo( true ) );

}

@Override
protected Collection<IndyClientModule> getAdditionalClientModules()
{
return Collections.singletonList( new IndyContentBrowseClientModule() );
}
}