Exemplo n.º 1
0
  @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"));
  }
Exemplo n.º 2
0
  @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"));
  }
Exemplo n.º 3
0
  @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]");
    }
  }
Exemplo n.º 4
0
  @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);
  }