"" );
ass.updateFormat( "drl" );
ass.updateContent( "some content" );
ass.checkin( "hey ho" );
MockIdentity midentity = new MockIdentity();
midentity.setIsLoggedIn( false );
midentity.setAllowLogin( false );
Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
midentity );
RestAPIServlet serv = new RestAPIServlet();
assertNotNull( serv.getAPI() );
Map<String, String> headers = new HashMap<String, String>() {
{
put( "Irrelevant",
"garbage" );
}
};
String uri = "http://loser/api/packages/testGetRestServlet/asset1.drl";
MockHTTPRequest req = new MockHTTPRequest( uri,
headers );
MockHTTPResponse res = new MockHTTPResponse();
//try with no password
serv.doGet( req,
res );
assertEquals( HttpServletResponse.SC_UNAUTHORIZED,
res.errorCode );
assertTrue( res.headers.containsKey( "WWW-Authenticate" ) );
//try again with bad password
headers = new HashMap<String, String>() {
{
put( "Authorization",
new String( Base64.encodeBase64( "foo:bar".getBytes() ) ) );
}
};
req = new MockHTTPRequest( uri,
headers );
res = new MockHTTPResponse();
serv.doGet( req,
res );
assertEquals( HttpServletResponse.SC_UNAUTHORIZED,
res.errorCode );
assertTrue( res.headers.containsKey( "WWW-Authenticate" ) );
//finally, making it work
midentity.setAllowLogin( true );
headers = new HashMap<String, String>() {
{
put( "Authorization",
"BASIC " + new String( Base64.encodeBase64( "testuser:password".getBytes() ) ) );