Skip to content

Commit

Permalink
Add more testing of required SAML attribute handling
Browse files Browse the repository at this point in the history
  • Loading branch information
markpatton committed Aug 26, 2024
1 parent 0cc0c93 commit a2a3429
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -16,6 +18,7 @@
import org.eclipse.pass.object.model.UserRole;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.BadCredentialsException;

public class PassAuthenticationFilterTest extends SamlIntegrationTest {
@Autowired
Expand Down Expand Up @@ -128,4 +131,52 @@ public void testParseUserMissingEmployeeIdAndAffiliation() {

assertEquals(expected, user);
}

@Test
public void testParseUserMissingRequiredAttributes() {
Map<String, List<Object>> attributes = new HashMap<>();

attributes.put("urn:oid:2.16.840.1.113730.3.1.241", List.of("Thomas L. Submitter"));
attributes.put("urn:oid:0.9.2342.19200300.100.1.3", List.of("[email protected]"));
attributes.put("urn:oid:1.3.6.1.4.1.5923.1.1.1.6", List.of("[email protected]"));
attributes.put("urn:oid:2.5.4.42", List.of("Tom"));
attributes.put("urn:oid:2.5.4.4", List.of("Submitter"));
attributes.put("urn:oid:1.3.6.1.4.1.5923.1.1.1.13", List.of("[email protected]"));

// Show that removing each of the required keys causes a failure
// and that various values are treated as the key not existing
for (String key: attributes.keySet()) {
HashMap<String, List<Object>> test = new HashMap<>(attributes);

test.remove(key);

assertThrows(BadCredentialsException.class, () -> {
passAuthFilter.parseUser(test);
});

test.put(key, null);

assertThrows(BadCredentialsException.class, () -> {
passAuthFilter.parseUser(test);
});

test.put(key, List.of());

assertThrows(BadCredentialsException.class, () -> {
passAuthFilter.parseUser(test);
});

test.put(key, List.of(""));

assertThrows(BadCredentialsException.class, () -> {
passAuthFilter.parseUser(test);
});

test.put(key, new ArrayList<>(1));

assertThrows(BadCredentialsException.class, () -> {
passAuthFilter.parseUser(test);
});
}
}
}

0 comments on commit a2a3429

Please sign in to comment.