1 19 20 package com.sslexplorer.reverseproxy; 21 22 import static org.junit.Assert.assertEquals; 23 import org.junit.Test; 24 25 public class ReverseProxyMethodHandlerTest { 26 @Test 27 public void stripHttpProtocol() { 28 String stripProtocol = ReverseProxyMethodHandler.stripProtocol("http://"); 29 assertEquals("", stripProtocol); 30 } 31 32 @Test 33 public void stripHttpsProtocol() { 34 String stripProtocol = ReverseProxyMethodHandler.stripProtocol("https://"); 35 assertEquals("", stripProtocol); 36 } 37 38 @Test 39 public void stripHttp() { 40 String stripProtocol = ReverseProxyMethodHandler.stripProtocol("http://google.com"); 41 assertEquals("google.com", stripProtocol); 42 } 43 44 @Test 45 public void stripHttps() { 46 String stripProtocol = ReverseProxyMethodHandler.stripProtocol("https://google.com"); 47 assertEquals("google.com", stripProtocol); 48 } 49 50 @Test 51 public void stripNothing() { 52 String stripProtocol = ReverseProxyMethodHandler.stripProtocol(""); 53 assertEquals("", stripProtocol); 54 } 55 56 @Test 57 public void stripForwardSlash() { 58 String stripProtocol = ReverseProxyMethodHandler.stripProtocol("/"); 59 assertEquals("/", stripProtocol); 60 } 61 62 @Test 63 public void stripHost() { 64 String stripProtocol = ReverseProxyMethodHandler.stripProtocol("google.com"); 65 assertEquals("google.com", stripProtocol); 66 } 67 68 @Test 69 public void rebuildHttpLocalhost() { 70 String newLocation = ReverseProxyMethodHandler.rebuildLocation("http://localhost/home", "localhost", "google.com"); 71 assertEquals("https://localhost/home", newLocation); 72 } 73 74 @Test 75 public void rebuildHttpsLocalhost() { 76 String newLocation = ReverseProxyMethodHandler.rebuildLocation("https://localhost/home", "localhost", "google.com"); 77 assertEquals("https://localhost/home", newLocation); 78 } 79 80 @Test 81 public void rebuildLocalhostWithParmeters() { 82 String newLocation = ReverseProxyMethodHandler.rebuildLocation("https://localhost/home/blah?username=karl", "localhost", "google.com"); 83 assertEquals("https://localhost/home/blah?username=karl", newLocation); 84 } 85 86 @Test 87 public void rebuildHttpRemotehost() { 88 String newLocation = ReverseProxyMethodHandler.rebuildLocation("http://google.com/home", "localhost", "google.com"); 89 assertEquals("https://localhost/home", newLocation); 90 } 91 92 @Test 93 public void rebuildHttpsRemotehost() { 94 String newLocation = ReverseProxyMethodHandler.rebuildLocation("https://google.com/home", "localhost", "google.com"); 95 assertEquals("https://localhost/home", newLocation); 96 } 97 98 @Test 99 public void rebuildRemotehostWithParmeters() { 100 String newLocation = ReverseProxyMethodHandler.rebuildLocation("https://google.com/home/blah?username=karl", "localhost", "google.com"); 101 assertEquals("https://localhost/home/blah?username=karl", newLocation); 102 } 103 104 @Test 105 public void rebuildSlashHost() { 106 String newLocation = ReverseProxyMethodHandler.rebuildLocation("/", "localhost", "google.com"); 107 assertEquals("/", newLocation); 108 } 109 110 @Test 111 public void rebuildSlashPath() { 112 String newLocation = ReverseProxyMethodHandler.rebuildLocation("/home/blah?username=karl", "localhost", "google.com"); 113 assertEquals("/home/blah?username=karl", newLocation); 114 } 115 116 @Test 117 public void rebuildHttpUnknownHost() { 118 String newLocation = ReverseProxyMethodHandler.rebuildLocation("http://unknown/", "localhost", "google.com"); 119 assertEquals("http://unknown/", newLocation); 120 } 121 122 @Test 123 public void rebuildHttpsUnknownHost() { 124 String newLocation = ReverseProxyMethodHandler.rebuildLocation("https://unknown/", "localhost", "google.com"); 125 assertEquals("https://unknown/", newLocation); 126 } 127 } | Popular Tags |