From c8585baebc9fc35ed12a3321acf47730c967b5d3 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Tue, 24 May 2016 15:45:03 +0000
Subject: [PATCH] OPENDJ-2880 Rest2Ldap as an OAuth2 Resource Server

---
 opendj-rest2ldap/src/test/java/org/forgerock/opendj/rest2ldap/authz/AuthzIdTemplateTest.java |   39 ++++++++++++++++++++-------------------
 1 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/opendj-rest2ldap/src/test/java/org/forgerock/opendj/rest2ldap/authz/AuthzIdTemplateTest.java b/opendj-rest2ldap/src/test/java/org/forgerock/opendj/rest2ldap/authz/AuthzIdTemplateTest.java
index 3d7e099..bfec765 100644
--- a/opendj-rest2ldap/src/test/java/org/forgerock/opendj/rest2ldap/authz/AuthzIdTemplateTest.java
+++ b/opendj-rest2ldap/src/test/java/org/forgerock/opendj/rest2ldap/authz/AuthzIdTemplateTest.java
@@ -20,7 +20,7 @@
 import java.util.LinkedHashMap;
 import java.util.Map;
 
-import org.forgerock.opendj.ldap.schema.Schema;
+import org.forgerock.json.JsonValue;
 import org.forgerock.testng.ForgeRockTestCase;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
@@ -35,46 +35,47 @@
     @DataProvider
     public Object[][] templateData() {
         // @formatter:off
+        // [template as set in json configuration file]
+        // [excepted result after placeholders resolution]
+        // [Values to use to resolve the placeholders]
         return new Object[][] {
             {
                 "dn:uid={uid},ou={realm},dc=example,dc=com",
-                "dn:uid=test.user,ou=acme,dc=example,dc=com",
+                "uid=test.user,ou=acme,dc=example,dc=com",
                 map("uid", "test.user", "realm", "acme")
             },
             {
                 // Should perform DN quoting.
                 "dn:uid={uid},ou={realm},dc=example,dc=com",
-                "dn:uid=test.user,ou=test\\+cn=quoting,dc=example,dc=com",
+                "uid=test.user,ou=test\\+cn=quoting,dc=example,dc=com",
                 map("uid", "test.user", "realm", "test+cn=quoting")
             },
             {
-                // Should not perform DN quoting.
-                "dn:{dn}",
-                "dn:uid=test.user,ou=acme,dc=example,dc=com",
-                map("dn", "uid=test.user,ou=acme,dc=example,dc=com")
-            },
-            {
                 "u:{uid}@{realm}.example.com",
-                "u:test.user@acme.example.com",
+                "test.user@acme.example.com",
                 map("uid", "test.user", "realm", "acme")
             },
             {
                 // Should not perform any DN quoting.
                 "u:{uid}@{realm}.example.com",
-                "u:test.user@test+cn=quoting.example.com",
+                "test.user@test+cn=quoting.example.com",
                 map("uid", "test.user", "realm", "test+cn=quoting")
             },
+            {
+                // Should resolve boolean and numbers
+                "u:{uid}.{numericid}.{testboolean}@{realm}.example.com",
+                "test.42.true@test.example.com",
+                map("uid", "test", "numericid", 42, "testboolean", true, "realm", "test")
+            }
         };
         // @formatter:on
 
     }
 
     @Test(dataProvider = "templateData")
-    public void testTemplates(final String template, final String expected,
-            Map<String, Object> principals) throws Exception {
-        assertThat(
-                new AuthzIdTemplate(template)
-                        .formatAsAuthzId(principals, Schema.getDefaultSchema()))
+    public void testTemplates(final String template, final String expected, Map<String, Object> principals)
+            throws Exception {
+        assertThat(new AuthzIdTemplate(template).formatAsAuthzId(new JsonValue(principals)))
                 .isEqualTo(expected);
     }
 
@@ -103,7 +104,7 @@
     @Test(dataProvider = "invalidTemplateData", expectedExceptions = IllegalArgumentException.class)
     public void testInvalidTemplateData(final String template, Map<String, Object> principals)
             throws Exception {
-        new AuthzIdTemplate(template).formatAsAuthzId(principals, Schema.getDefaultSchema());
+        new AuthzIdTemplate(template).formatAsAuthzId(new JsonValue(principals));
     }
 
     @DataProvider
@@ -122,10 +123,10 @@
         new AuthzIdTemplate(template);
     }
 
-    private Map<String, Object> map(String... keyValues) {
+    private Map<String, Object> map(Object... keyValues) {
         Map<String, Object> map = new LinkedHashMap<>();
         for (int i = 0; i < keyValues.length; i += 2) {
-            map.put(keyValues[i], keyValues[i + 1]);
+            map.put(keyValues[i].toString(), keyValues[i + 1]);
         }
         return map;
     }

--
Gitblit v1.10.0