1717package org .apache .jackrabbit .oak .plugins .name ;
1818
1919import static org .junit .Assert .assertEquals ;
20+ import static org .junit .Assert .assertThrows ;
2021import static org .junit .Assert .assertTrue ;
2122import static org .junit .Assert .fail ;
2223
@@ -68,13 +69,13 @@ public void testMappings() throws Exception {
6869 assertEquals ("mix" , r .getPrefix ("http://www.jcp.org/jcr/mix/1.0" ));
6970 assertEquals ("xml" , r .getPrefix ("http://www.w3.org/XML/1998/namespace" ));
7071
71- r .registerNamespace ("p" , "n" );
72- assertEquals (r .getURI ("p" ), "n" );
73- assertEquals (r .getPrefix ("n" ), "p" );
72+ r .registerNamespace ("p" , "myscheme: n" );
73+ assertEquals (r .getURI ("p" ), "myscheme: n" );
74+ assertEquals (r .getPrefix ("myscheme: n" ), "p" );
7475
75- r .registerNamespace ("p2" , "n2" );
76- assertEquals (r .getURI ("p2" ), "n2" );
77- assertEquals (r .getPrefix ("n2" ), "p2" );
76+ r .registerNamespace ("p2" , "myscheme: n2" );
77+ assertEquals (r .getURI ("p2" ), "myscheme: n2" );
78+ assertEquals (r .getPrefix ("myscheme: n2" ), "p2" );
7879
7980 // xml namespace check
8081 assertTrue (SetUtils .toSet (r .getPrefixes ()).contains ("xml" ));
@@ -87,13 +88,12 @@ public void testMappings() throws Exception {
8788 }
8889
8990 @ Test
90- public void testInvalidNamespace () throws Exception {
91- final ContentSession session = createContentSession ();
92- final Root root = session .getLatestRoot ();
93- NamespaceRegistry r = getNamespaceRegistry (session , root );
94-
91+ public void testInvalidNamespaceInDefaultMode () throws Exception {
9592 LogCustomizer customLogs = LogCustomizer .forLogger ("org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry" ).enable (Level .ERROR ).create ();
9693 try {
94+ final ContentSession session = createContentSession ();
95+ final Root root = session .getLatestRoot ();
96+ NamespaceRegistry r = getNamespaceRegistry (session , root );
9797 customLogs .starting ();
9898 r .registerNamespace ("foo" , "example.com" );
9999 r .unregisterNamespace ("foo" );
@@ -103,6 +103,24 @@ public void testInvalidNamespace() throws Exception {
103103 }
104104 finally {
105105 customLogs .finished ();
106+
107+ }
108+ }
109+
110+ @ Test
111+ public void testInvalidNamespaceInStrictMode () {
112+ String oldValue = System .setProperty ("oak.allowInvalidNamespaceUris" , "true" );
113+ try {
114+ final ContentSession session = createContentSession ();
115+ final Root root = session .getLatestRoot ();
116+ NamespaceRegistry r = getNamespaceRegistry (session , root );
117+ assertThrows (NamespaceException .class , () -> r .registerNamespace ("foo" , "example.com" ));
118+ } finally {
119+ if (oldValue != null ) {
120+ System .setProperty ("oak.allowInvalidNamespaceUris" , oldValue );
121+ } else {
122+ System .clearProperty ("oak.allowInvalidNamespaceUris" );
123+ }
106124 }
107125 }
108126
0 commit comments