@Test public void testRequestedClaimsNoScope() throws Exception { // Given Map<String, Set<String>> requestedClaims = new HashMap<String, Set<String>>(); requestedClaims.put("given_name", asSet("fred")); requestedClaims.put("family_name", asSet("flintstone")); Bindings variables = testBindings(asSet("openid"), requestedClaims); // When Map<String, Object> result = scriptEvaluator.evaluateScript(script, variables); // Then assertThat(result) .containsOnly(entry("given_name", "fred"), entry("family_name", "flintstone")); }
@Test public void testProfileScope() throws Exception { // Given Bindings variables = testBindings(asSet("profile")); when(identity.getAttribute("givenname")).thenReturn(asSet("joe")); when(identity.getAttribute("sn")).thenReturn(asSet("bloggs")); when(identity.getAttribute("preferredtimezone")).thenReturn(asSet("Europe/London")); when(identity.getAttribute("preferredlocale")).thenReturn(asSet("en")); when(identity.getAttribute("cn")).thenReturn(asSet("Joe Bloggs")); // When Map<String, Object> result = scriptEvaluator.evaluateScript(script, variables); // Then assertThat(result) .containsOnly( entry("given_name", "joe"), entry("family_name", "bloggs"), entry("name", "Joe Bloggs"), entry("zoneinfo", "Europe/London"), entry("locale", "en")); }
@Test public void testRequestedClaimsSelectNoScope() throws Exception { // Given Bindings variables = testBindings( asSet("openid"), Collections.singletonMap("given_name", asSet("fred", "george"))); when(identity.getAttribute("cn")).thenReturn(asSet("Joe Bloggs")); // When/Then try { scriptEvaluator.evaluateScript(script, variables); } catch (Throwable e) { Throwable last = null; while (last != e) { if (e.getClass().equals(RuntimeException.class)) { break; } last = e; e = e.getCause(); } assertThat(e.getMessage()) .isEqualTo("No selection logic for given_name defined. Values: [george, fred]"); } }
@Test public void testRequestedClaims() throws Exception { // Given Map<String, Set<String>> requestedClaims = new HashMap<String, Set<String>>(); requestedClaims.put("given_name", asSet("fred")); requestedClaims.put("family_name", asSet("flintstone")); Bindings variables = testBindings(asSet("profile"), requestedClaims); when(identity.getAttribute("cn")).thenReturn(asSet("Joe Bloggs")); // When Map<String, Object> result = scriptEvaluator.evaluateScript(script, variables); // Then assertThat(result) .containsOnly( entry("given_name", "fred"), entry("family_name", "flintstone"), entry("name", "Joe Bloggs")); verify(identity).getAttribute("cn"); verify(identity).getAttribute("preferredlocale"); verify(identity).getAttribute("preferredtimezone"); verifyNoMoreInteractions(identity); }