mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
fix and enable junit test createSessionAnonymousTest
This commit is contained in:
@@ -49,7 +49,11 @@ public class ScmUrlProvider
|
|||||||
public static final String API_PATH = "/api/rest/";
|
public static final String API_PATH = "/api/rest/";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String URLPART_AUTHENTICATION = "authentication/login";
|
public static final String URLPART_AUTHENTICATION = "authentication";
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
public static final String URLPART_AUTHENTICATION_LOGIN =
|
||||||
|
"authentication/login";
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
public static final String URLPART_REPOSITORIES = "repositories";
|
public static final String URLPART_REPOSITORIES = "repositories";
|
||||||
@@ -88,6 +92,17 @@ public class ScmUrlProvider
|
|||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
//~--- get methods ----------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getAuthenticationLoginUrl()
|
||||||
|
{
|
||||||
|
return getResourceUrl(URLPART_AUTHENTICATION_LOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -32,15 +32,23 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.sonatype.spice</groupId>
|
<groupId>org.sonatype.spice</groupId>
|
||||||
<artifactId>jersey-ahc-client</artifactId>
|
<artifactId>jersey-ahc-client</artifactId>
|
||||||
<version>1.0.1</version>
|
<version>1.0.1-patch1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- test scope -->
|
<!-- test scope -->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jul-to-slf4j</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>0.9.28</version>
|
<version>0.9.28</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -35,7 +35,10 @@ package sonia.scm.client;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
|
import com.sun.jersey.api.client.Client;
|
||||||
import com.sun.jersey.api.client.ClientResponse;
|
import com.sun.jersey.api.client.ClientResponse;
|
||||||
|
import com.sun.jersey.api.client.WebResource;
|
||||||
|
import com.sun.jersey.api.client.filter.LoggingFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -57,4 +60,41 @@ public class ClientUtil
|
|||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param client
|
||||||
|
* @param url
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static WebResource createResource(Client client, String url)
|
||||||
|
{
|
||||||
|
return createResource(client, url, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method description
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param client
|
||||||
|
* @param url
|
||||||
|
* @param enableLogging
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static WebResource createResource(Client client, String url,
|
||||||
|
boolean enableLogging)
|
||||||
|
{
|
||||||
|
WebResource resource = client.resource(url);
|
||||||
|
|
||||||
|
if (enableLogging)
|
||||||
|
{
|
||||||
|
resource.addFilter(new LoggingFilter());
|
||||||
|
}
|
||||||
|
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ package sonia.scm.client;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import org.sonatype.spice.jersey.client.ahc.AhcHttpClient;
|
||||||
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig;
|
import org.sonatype.spice.jersey.client.ahc.config.DefaultAhcConfig;
|
||||||
|
|
||||||
import sonia.scm.ScmState;
|
import sonia.scm.ScmState;
|
||||||
@@ -46,7 +47,6 @@ import sonia.scm.util.Util;
|
|||||||
|
|
||||||
//~--- JDK imports ------------------------------------------------------------
|
//~--- JDK imports ------------------------------------------------------------
|
||||||
|
|
||||||
import com.sun.jersey.api.client.Client;
|
|
||||||
import com.sun.jersey.api.client.ClientResponse;
|
import com.sun.jersey.api.client.ClientResponse;
|
||||||
import com.sun.jersey.api.client.WebResource;
|
import com.sun.jersey.api.client.WebResource;
|
||||||
import com.sun.jersey.core.util.MultivaluedMapImpl;
|
import com.sun.jersey.core.util.MultivaluedMapImpl;
|
||||||
@@ -64,6 +64,25 @@ public class JerseyClientProvider implements ScmClientProvider
|
|||||||
private static final Logger logger =
|
private static final Logger logger =
|
||||||
LoggerFactory.getLogger(JerseyClientProvider.class);
|
LoggerFactory.getLogger(JerseyClientProvider.class);
|
||||||
|
|
||||||
|
//~--- constructors ---------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public JerseyClientProvider() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs ...
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param enableLogging
|
||||||
|
*/
|
||||||
|
public JerseyClientProvider(boolean enableLogging)
|
||||||
|
{
|
||||||
|
this.enableLogging = enableLogging;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- methods --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,12 +118,15 @@ public class JerseyClientProvider implements ScmClientProvider
|
|||||||
|
|
||||||
ScmUrlProvider urlProvider = new ScmUrlProvider(url);
|
ScmUrlProvider urlProvider = new ScmUrlProvider(url);
|
||||||
DefaultAhcConfig config = new DefaultAhcConfig();
|
DefaultAhcConfig config = new DefaultAhcConfig();
|
||||||
Client client = Client.create(config);
|
AhcHttpClient client = AhcHttpClient.create(config);
|
||||||
WebResource resource = client.resource(urlProvider.getAuthenticationUrl());
|
|
||||||
ClientResponse response = null;
|
ClientResponse response = null;
|
||||||
|
|
||||||
if (Util.isNotEmpty(username) && Util.isNotEmpty(password))
|
if (Util.isNotEmpty(username) && Util.isNotEmpty(password))
|
||||||
{
|
{
|
||||||
|
WebResource resource = ClientUtil.createResource(client,
|
||||||
|
urlProvider.getAuthenticationLoginUrl(),
|
||||||
|
enableLogging);
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("try login for {}", username);
|
logger.debug("try login for {}", username);
|
||||||
@@ -119,6 +141,10 @@ public class JerseyClientProvider implements ScmClientProvider
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
WebResource resource = ClientUtil.createResource(client,
|
||||||
|
urlProvider.getAuthenticationUrl(),
|
||||||
|
enableLogging);
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
{
|
{
|
||||||
logger.debug("try anonymous login");
|
logger.debug("try anonymous login");
|
||||||
@@ -164,4 +190,9 @@ public class JerseyClientProvider implements ScmClientProvider
|
|||||||
|
|
||||||
return new JerseyClientSession(client, urlProvider, state);
|
return new JerseyClientSession(client, urlProvider, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
private boolean enableLogging = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ package sonia.scm.client.it;
|
|||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import sonia.scm.client.ClientUtil;
|
||||||
import sonia.scm.client.JerseyClientProvider;
|
import sonia.scm.client.JerseyClientProvider;
|
||||||
import sonia.scm.client.JerseyClientSession;
|
import sonia.scm.client.JerseyClientSession;
|
||||||
import sonia.scm.client.ScmClientException;
|
import sonia.scm.client.ScmClientException;
|
||||||
@@ -77,7 +77,6 @@ public class JerseyClientProviderITCase
|
|||||||
* @throws ScmClientException
|
* @throws ScmClientException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
|
||||||
public void createSessionAnonymousTest() throws ScmClientException
|
public void createSessionAnonymousTest() throws ScmClientException
|
||||||
{
|
{
|
||||||
JerseyClientSession adminSession = createSession("scmadmin", "scmadmin");
|
JerseyClientSession adminSession = createSession("scmadmin", "scmadmin");
|
||||||
@@ -85,7 +84,8 @@ public class JerseyClientProviderITCase
|
|||||||
// enable anonymous access
|
// enable anonymous access
|
||||||
ScmUrlProvider up = adminSession.getUrlProvider();
|
ScmUrlProvider up = adminSession.getUrlProvider();
|
||||||
Client client = adminSession.getClient();
|
Client client = adminSession.getClient();
|
||||||
WebResource resource = client.resource(up.getResourceUrl("config"));
|
WebResource resource = ClientUtil.createResource(client,
|
||||||
|
up.getResourceUrl("config"), true);
|
||||||
ScmConfiguration config = resource.get(ScmConfiguration.class);
|
ScmConfiguration config = resource.get(ScmConfiguration.class);
|
||||||
|
|
||||||
config.setAnonymousAccessEnabled(true);
|
config.setAnonymousAccessEnabled(true);
|
||||||
@@ -154,7 +154,7 @@ public class JerseyClientProviderITCase
|
|||||||
private JerseyClientSession createSession(String username, String password)
|
private JerseyClientSession createSession(String username, String password)
|
||||||
throws ScmClientException
|
throws ScmClientException
|
||||||
{
|
{
|
||||||
JerseyClientProvider provider = new JerseyClientProvider();
|
JerseyClientProvider provider = new JerseyClientProvider(true);
|
||||||
|
|
||||||
return provider.createSession("http://localhost:8081/scm", username,
|
return provider.createSession("http://localhost:8081/scm", username,
|
||||||
password);
|
password);
|
||||||
|
|||||||
Reference in New Issue
Block a user