Program: 20709
Project: 20709
Buggy source:
public void testPutWithInvalidUserAndGuestHasWriteAccess() throws Exception {
  setupCleanRepo(repoRootInternal);
  String putUrl="String_Node_Str";
  InputStream is=getClass().getResourceAsStream("String_Node_Str");
  assertNotNull("String_Node_Str",is);
  WebRequest request=new PutMethodWebRequest(putUrl,is,"String_Node_Str");
  InvocationContext ic=sc.newInvocation(request);
  servlet=(RepositoryServlet)ic.getServlet();
  servlet.setDavSessionProvider(davSessionProvider);
  ArchivaDavResourceFactory archivaDavResourceFactory=(ArchivaDavResourceFactory)servlet.getResourceFactory();
  archivaDavResourceFactory.setHttpAuth(httpAuth);
  archivaDavResourceFactory.setServletAuth(servletAuth);
  servlet.setResourceFactory(archivaDavResourceFactory);
  AuthenticationResult result=new AuthenticationResult();
  httpAuthControl.expectAndReturn(httpAuth.getAuthenticationResult(null,null),result);
  servletAuthControl.expectAndThrow(servletAuth.isAuthenticated(null,null),new AuthenticationException("String_Node_Str"));
  servletAuth.isAuthorized("String_Node_Str","String_Node_Str",ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD);
  servletAuthControl.setMatcher(MockControl.EQUALS_MATCHER);
  servletAuthControl.setReturnValue(true);
  SecuritySession session=new DefaultSecuritySession();
  httpAuthControl.expectAndReturn(httpAuth.getAuthenticationResult(null,null),result);
  httpAuthControl.expectAndReturn(httpAuth.getSecuritySession(ic.getRequest().getSession(true)),session);
  servletAuthControl.expectAndThrow(servletAuth.isAuthenticated(null,result),new AuthenticationException("String_Node_Str"));
  httpAuthControl.expectAndReturn(httpAuth.getSessionUser(ic.getRequest().getSession()),null);
  servletAuth.isAuthorized("String_Node_Str","String_Node_Str",ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD);
  servletAuthControl.setMatcher(MockControl.EQUALS_MATCHER);
  servletAuthControl.setReturnValue(true);
  httpAuthControl.replay();
  servletAuthControl.replay();
  servlet.service(ic.getRequest(),ic.getResponse());
  httpAuthControl.verify();
  servletAuthControl.verify();
}

Fixed version (ground truth):
@Test public void testPutWithInvalidUserAndGuestHasWriteAccess() throws Exception {
  setupCleanRepo(repoRootInternal);
  String putUrl="String_Node_Str";
  InputStream is=getClass().getResourceAsStream("String_Node_Str");
  assertNotNull("String_Node_Str",is);
  WebRequest request=new PutMethodWebRequest(putUrl,is,"String_Node_Str");
  InvocationContext ic=sc.newInvocation(request);
  servlet=(RepositoryServlet)ic.getServlet();
  servlet.setDavSessionProvider(davSessionProvider);
  ArchivaDavResourceFactory archivaDavResourceFactory=(ArchivaDavResourceFactory)servlet.getResourceFactory();
  archivaDavResourceFactory.setHttpAuth(httpAuth);
  archivaDavResourceFactory.setServletAuth(servletAuth);
  servlet.setResourceFactory(archivaDavResourceFactory);
  AuthenticationResult result=new AuthenticationResult();
  httpAuthControl.expectAndReturn(httpAuth.getAuthenticationResult(null,null),result);
  servletAuthControl.expectAndThrow(servletAuth.isAuthenticated(null,null),new AuthenticationException("String_Node_Str"));
  servletAuth.isAuthorized("String_Node_Str","String_Node_Str",ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD);
  servletAuthControl.setMatcher(MockControl.EQUALS_MATCHER);
  servletAuthControl.setReturnValue(true);
  SecuritySession session=new DefaultSecuritySession();
  httpAuthControl.expectAndReturn(httpAuth.getAuthenticationResult(null,null),result);
  httpAuthControl.expectAndReturn(httpAuth.getSecuritySession(ic.getRequest().getSession(true)),session);
  servletAuthControl.expectAndThrow(servletAuth.isAuthenticated(null,result),new AuthenticationException("String_Node_Str"));
  httpAuthControl.expectAndReturn(httpAuth.getSessionUser(ic.getRequest().getSession()),null);
  servletAuth.isAuthorized("String_Node_Str","String_Node_Str",ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD);
  servletAuthControl.setMatcher(MockControl.EQUALS_MATCHER);
  servletAuthControl.setReturnValue(true);
  httpAuthControl.replay();
  servletAuthControl.replay();
  servlet.service(ic.getRequest(),ic.getResponse());
  httpAuthControl.verify();
  servletAuthControl.verify();
}