Program: 5915
Project: 5915
Buggy source:
@Test public void testAuthorizationForSystemArtifacts() throws Exception {
  SecurityRequestContext.setUserId(systemUser);
  artifactRepository.addSystemArtifacts();
  SecurityRequestContext.setUserId(ALICE.getName());
  try {
    artifactRepository.addSystemArtifacts();
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  authorizer.grant(NamespaceId.SYSTEM,ALICE,Collections.singleton(Action.WRITE));
  Assert.assertEquals(Collections.singleton(new Privilege(NamespaceId.SYSTEM,Action.WRITE)),authorizer.listPrivileges(ALICE));
  artifactRepository.addSystemArtifacts();
  SecurityRequestContext.setUserId("String_Node_Str");
  try {
    artifactRepository.deleteArtifact(SYSTEM_ARTIFACT.toId());
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  SecurityRequestContext.setUserId(ALICE.getName());
  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());
  authorizer.enforce(SYSTEM_ARTIFACT,ALICE,EnumSet.allOf(Action.class));
  authorizer.enforce(NamespaceId.SYSTEM,ALICE,Action.WRITE);
  artifactRepository.deleteArtifact(SYSTEM_ARTIFACT.toId());
}

Fixed version (ground truth):
@Test public void testAuthorizationForSystemArtifacts() throws Exception {
  artifactRepository.addSystemArtifacts();
  SecurityRequestContext.setUserId(ALICE.getName());
  try {
    artifactRepository.addSystemArtifacts();
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  authorizer.grant(NamespaceId.SYSTEM,ALICE,Collections.singleton(Action.WRITE));
  Assert.assertEquals(Collections.singleton(new Privilege(NamespaceId.SYSTEM,Action.WRITE)),authorizer.listPrivileges(ALICE));
  artifactRepository.addSystemArtifacts();
  SecurityRequestContext.setUserId("String_Node_Str");
  try {
    artifactRepository.deleteArtifact(SYSTEM_ARTIFACT.toId());
    Assert.fail("String_Node_Str" + "String_Node_Str");
  }
 catch (  UnauthorizedException expected) {
  }
  SecurityRequestContext.setUserId(ALICE.getName());
  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());
  authorizer.enforce(SYSTEM_ARTIFACT,ALICE,EnumSet.allOf(Action.class));
  authorizer.enforce(NamespaceId.SYSTEM,ALICE,Action.WRITE);
  artifactRepository.deleteArtifact(SYSTEM_ARTIFACT.toId());
}