Program: 6012
Project: 6012
Buggy source:
@Test public void testAuthorizationForSystemArtifacts() throws Exception {
  SecurityRequestContext.setUserId(Principal.SYSTEM.getName());
  artifactRepository.addSystemArtifacts();
  SecurityRequestContext.setUserId(ALICE.getName());
  try {
    artifactRepository.addSystemArtifacts();
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  authorizer.grant(instance,ALICE,Collections.singleton(Action.WRITE));
  Assert.assertEquals(Collections.singleton(new Privilege(instance,Action.WRITE)),authorizer.listPrivileges(ALICE));
  artifactRepository.addSystemArtifacts();
  try {
    artifactRepository.deleteArtifact(SYSTEM_ARTIFACT.toId());
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  authorizer.grant(instance,ALICE,Collections.singleton(Action.ADMIN));
  NamespaceId namespaceId=new NamespaceId("String_Node_Str");
  namespaceAdmin.create(new NamespaceMeta.Builder().setName(namespaceId.getNamespace()).build());
  authorizer.revoke(instance);
  List<ArtifactSummary> artifacts=artifactRepository.getArtifacts(namespaceId,true);
  Assert.assertEquals(1,artifacts.size());
  ArtifactSummary artifactSummary=artifacts.get(0);
  Assert.assertTrue(SYSTEM_ARTIFACT.getArtifact().equals(artifactSummary.getName()));
  Assert.assertTrue(SYSTEM_ARTIFACT.getVersion().equals(artifactSummary.getVersion()));
  Assert.assertTrue(SYSTEM_ARTIFACT.getNamespace().equals(artifactSummary.getScope().name().toLowerCase()));
  namespaceAdmin.delete(namespaceId.toId());
  Assert.assertEquals(Collections.emptySet(),authorizer.listPrivileges(ALICE));
  authorizer.grant(instance,ALICE,Collections.singleton(Action.ADMIN));
  artifactRepository.deleteArtifact(SYSTEM_ARTIFACT.toId());
}

Fixed version (ground truth):
@Test public void testAuthorizationForSystemArtifacts() throws Exception {
  SecurityRequestContext.setUserId(Principal.SYSTEM.getName());
  artifactRepository.addSystemArtifacts();
  SecurityRequestContext.setUserId(ALICE.getName());
  try {
    artifactRepository.addSystemArtifacts();
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  authorizer.grant(instance,ALICE,Collections.singleton(Action.WRITE));
  Assert.assertEquals(Collections.singleton(new Privilege(instance,Action.WRITE)),authorizer.listPrivileges(ALICE));
  artifactRepository.addSystemArtifacts();
  try {
    artifactRepository.deleteArtifact(SYSTEM_ARTIFACT.toId());
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  authorizer.grant(instance,ALICE,Collections.singleton(Action.ADMIN));
  NamespaceId namespaceId=new NamespaceId("String_Node_Str");
  namespaceAdmin.create(new NamespaceMeta.Builder().setName(namespaceId.getNamespace()).build());
  authorizer.revoke(instance);
  List<ArtifactSummary> artifacts=artifactRepository.getArtifacts(namespaceId,true);
  Assert.assertEquals(1,artifacts.size());
  ArtifactSummary artifactSummary=artifacts.get(0);
  Assert.assertEquals(SYSTEM_ARTIFACT.getArtifact(),artifactSummary.getName());
  Assert.assertEquals(SYSTEM_ARTIFACT.getVersion(),artifactSummary.getVersion());
  Assert.assertEquals(SYSTEM_ARTIFACT.getNamespace(),artifactSummary.getScope().name().toLowerCase());
  ArtifactDetail artifactDetail=artifactRepository.getArtifact(SYSTEM_ARTIFACT.toId());
  co.cask.cdap.api.artifact.ArtifactId artifactId=artifactDetail.getDescriptor().getArtifactId();
  Assert.assertEquals(SYSTEM_ARTIFACT.getArtifact(),artifactId.getName());
  Assert.assertEquals(SYSTEM_ARTIFACT.getVersion(),artifactId.getVersion().getVersion());
  Assert.assertEquals(SYSTEM_ARTIFACT.getNamespace(),artifactId.getScope().name().toLowerCase());
  namespaceAdmin.delete(namespaceId.toId());
  Assert.assertEquals(Collections.emptySet(),authorizer.listPrivileges(ALICE));
  authorizer.grant(instance,ALICE,Collections.singleton(Action.ADMIN));
  artifactRepository.deleteArtifact(SYSTEM_ARTIFACT.toId());
}