RpcUtils { public static boolean doOriginsMatch(String origin1, String origin2) { try { if (origin1 == null || origin2 == null) { return false; } if (origin1.equals("*") || origin2.equals("*")) { return true; } URI uri1 = getURI(origin1); URI uri2 = getURI(origin2); if (!uri1.getHost().equals(uri2.getHost())) { return false; } return getPort(uri1) == getPort(uri2); } catch (URISyntaxException ex) { return false; } } private  RpcUtils(); static String getVersion(); static String getDescription(); static RpcSpringContext getSpringContext(ServletContext sc); static Set<String> getUserRoles(Object securityContext); static boolean doOriginsMatch(String origin1, String origin2);  }
@Test public void testDoOriginMatch() { Pair<String, String>[] matches = new Pair[]{ new Pair("*", "*"), new Pair("file: new Pair("localhost", "http: new Pair("localhost:8080", "http: new Pair("http: new Pair("https: }; Pair<String, String>[] nonMatches = new Pair[]{ new Pair(null, null), new Pair("*", null), new Pair("file: new Pair("http: new Pair("http: }; for (int i = 0; i < matches.length; i++) { Pair<String, String> pair = matches[i]; System.out.println("asserting match: " + pair); assertTrue(RpcUtils.doOriginsMatch(pair.getElement1(), pair.getElement2())); assertTrue(RpcUtils.doOriginsMatch(pair.getElement2(), pair.getElement1())); } for (int i = 0; i < nonMatches.length; i++) { Pair<String, String> pair = nonMatches[i]; System.out.println("asserting not match: " + pair); assertFalse(RpcUtils.doOriginsMatch(pair.getElement1(), pair.getElement2())); assertFalse(RpcUtils.doOriginsMatch(pair.getElement2(), pair.getElement1())); } }