CorsUtils { public static Boolean isValidOrigin(String sourceHost, ZeppelinConfiguration conf) throws UnknownHostException, URISyntaxException { String sourceUriHost = ""; if (sourceHost != null && !sourceHost.isEmpty()) { sourceUriHost = new URI(sourceHost).getHost(); sourceUriHost = (sourceUriHost == null) ? "" : sourceUriHost.toLowerCase(); } sourceUriHost = sourceUriHost.toLowerCase(); String currentHost = InetAddress.getLocalHost().getHostName().toLowerCase(); return conf.getAllowedOrigins().contains("*") || currentHost.equals(sourceUriHost) || "localhost".equals(sourceUriHost) || conf.getAllowedOrigins().contains(sourceHost); }  static Boolean isValidOrigin(String sourceHost, ZeppelinConfiguration conf);  }
@Test public void isInvalid() throws URISyntaxException, UnknownHostException { assertFalse(CorsUtils.isValidOrigin("http: }
@Test public void isInvalidFromConfig() throws URISyntaxException, UnknownHostException, ConfigurationException { assertFalse(CorsUtils.isValidOrigin("http: new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml")))); }
@Test public void isLocalhost() throws URISyntaxException, UnknownHostException { assertTrue(CorsUtils.isValidOrigin("http: }
@Test public void isLocalMachine() throws URISyntaxException, UnknownHostException { String origin = "http: assertTrue("Origin " + origin + " is not allowed. Please check your hostname.", CorsUtils.isValidOrigin(origin, ZeppelinConfiguration.create())); }
@Test public void isValidFromConfig() throws URISyntaxException, UnknownHostException, ConfigurationException { assertTrue(CorsUtils.isValidOrigin("http: new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml")))); }
@Test public void isValidFromStar() throws URISyntaxException, UnknownHostException, ConfigurationException { assertTrue(CorsUtils.isValidOrigin("http: new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site-star.xml")))); }
@Test public void nullOrigin() throws URISyntaxException, UnknownHostException, ConfigurationException { assertFalse(CorsUtils.isValidOrigin(null, new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml")))); }
@Test public void nullOriginWithStar() throws URISyntaxException, UnknownHostException, ConfigurationException { assertTrue(CorsUtils.isValidOrigin(null, new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site-star.xml")))); }
@Test public void emptyOrigin() throws URISyntaxException, UnknownHostException, ConfigurationException { assertFalse(CorsUtils.isValidOrigin("", new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml")))); }
@Test public void notAURIOrigin() throws URISyntaxException, UnknownHostException, ConfigurationException { assertFalse(CorsUtils.isValidOrigin("test123", new ZeppelinConfiguration(this.getClass().getResource("/zeppelin-site.xml")))); }