Skip to content

Commit

Permalink
Skip invalid DN into the VO map file (#74)
Browse files Browse the repository at this point in the history
An invalid DN can lead to ignore the succeeding entries
Fix for https://issues.infn.it/jira/browse/STOR-1399
  • Loading branch information
enricovianello authored Dec 9, 2024
1 parent 5a357ab commit c9f19ae
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

Expand All @@ -32,6 +31,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Sets;

import eu.emi.security.authn.x509.impl.OpensslNameUtils;

public class MapfileVOMembershipSource implements VOMembershipSource {
Expand Down Expand Up @@ -64,12 +65,12 @@ private CSVParser getParser() {
private boolean isValidCSVRecord(CSVRecord r) {

if (r.size() > 3) {
logger.debug("Invalid CSVRecord: {}. Illegal size: {}", r, r.size());
logger.warn("Invalid CSVRecord: {}. Illegal size: {}", r, r.size());
return false;
}

if (!r.get(0).startsWith("/")) {
logger.debug("Invalid CSVRecord: {}. Subject does not start with / : {}",
logger.warn("Invalid CSVRecord: {}. Subject does not start with / : {}",
r, r.get(0));
return false;
}
Expand All @@ -82,7 +83,7 @@ public Set<String> getVOMembers() {

long startTime = System.currentTimeMillis();

Set<String> subjects = new HashSet<String>();
Set<String> subjects = Sets.newHashSet();

CSVParser parser = getParser();

Expand All @@ -97,7 +98,8 @@ public Set<String> getVOMembers() {
}

if (!isValidCSVRecord(r)) {
break;
/* Fix https://issues.infn.it/jira/browse/STOR-1399 */
continue;
}

String subject = r.get(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,28 @@

public class VOMSMapTests {

public static final String MY_SUBJECT = "CN=Andrea Ceccanti,L=CNAF,OU=Personal Certificate,O=INFN,C=IT";
@Test
void VOMapParserTest() {

MapfileVOMembershipSource m = new MapfileVOMembershipSource("testers",
new File("src/test/resources/vomsmap/testers.map"));

Assert.assertEquals("testers",m.getVOName());
Assert.assertTrue(m.getVOMembers().contains(MY_SUBJECT));

Assert.assertFalse(m.getVOMembers().contains("CN=I am not Real, L=CNAF"));

}
public static final String AC_SUBJECT =
"CN=Andrea Ceccanti,L=CNAF,OU=Personal Certificate,O=INFN,C=IT";
public static final String EV_SUBJECT =
"CN=Enrico Vianello,L=CNAF,OU=Personal Certificate,O=INFN,C=IT";
public static final String COMMA_SUBJECT =
"CN=Federica Agostini,L=CNAF,Bologna,OU=Personal Certificate,O=INFN,C=IT";
public static final String RM_SUBJECT =
"CN=Roberta Miccoli,L=CNAF,OU=Personal Certificate,O=INFN,C=IT";

@Test
void VOMapParserTest() {

MapfileVOMembershipSource m = new MapfileVOMembershipSource("testers",
new File("src/test/resources/vomsmap/testers.map"));

Assert.assertEquals("testers", m.getVOName());
Assert.assertTrue(m.getVOMembers().contains(AC_SUBJECT));
Assert.assertFalse(m.getVOMembers().contains(EV_SUBJECT));
Assert.assertFalse(m.getVOMembers().contains(COMMA_SUBJECT));
Assert.assertTrue(m.getVOMembers().contains(RM_SUBJECT));
Assert.assertFalse(m.getVOMembers().contains("CN=I am not Real, L=CNAF"));

}

}
4 changes: 3 additions & 1 deletion src/test/resources/vomsmap/testers.map
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/C=IT/O=INFN/OU=Personal Certificate/L=CNAF/CN=Andrea Ceccanti,/C=IT/O=INFN/CN=INFN CA,[email protected]
/C=IT/O=INFN/OU=Personal Certificate/L=CNAF/CN=Enrico Vianello,/C=IT/O=INFN/CN=INFN CA,[email protected]
C=IT/O=INFN/OU=Personal Certificate/L=CNAF/CN=Enrico Vianello,/C=IT/O=INFN/CN=INFN CA,[email protected]
/C=IT/O=INFN/OU=Personal Certificate/L=CNAF,Bologna/CN=Federica Agostini,/C=IT/O=INFN/CN=INFN CA,[email protected]
/C=IT/O=INFN/OU=Personal Certificate/L=CNAF/CN=Roberta Miccoli,/C=IT/O=INFN/CN=INFN CA,[email protected]

0 comments on commit c9f19ae

Please sign in to comment.