|
69 | 69 | import org.springframework.context.ApplicationListener; |
70 | 70 | import org.springframework.context.ConfigurableApplicationContext; |
71 | 71 | import org.springframework.context.event.ApplicationEventMulticaster; |
| 72 | +import org.springframework.http.HttpMethod; |
72 | 73 | import org.springframework.http.MediaType; |
73 | 74 | import org.springframework.jdbc.core.JdbcTemplate; |
74 | 75 | import org.springframework.mock.web.MockHttpServletRequest; |
@@ -134,6 +135,53 @@ private MockMvcUtils() { |
134 | 135 | throw new java.lang.UnsupportedOperationException("This is a utility class and cannot be instantiated"); |
135 | 136 | } |
136 | 137 |
|
| 138 | + /** |
| 139 | + * Mode for resolving identity zone in tests: by host subdomain or by path prefix {@code /z/{subdomain}/}. |
| 140 | + * The test passes the path suffix (e.g. {@code "/oauth/token"}); |
| 141 | + * the mode constructs the full path. |
| 142 | + */ |
| 143 | + public enum ZoneResolutionMode { |
| 144 | + SUBDOMAIN { |
| 145 | + @Override |
| 146 | + public MockHttpServletRequestBuilder createRequestBuilder(String subdomain, HttpMethod method, String pathSuffix) { |
| 147 | + return requestBuilderForMethod(method, pathSuffix) |
| 148 | + .with(new SetServerNameRequestPostProcessor(subdomain + ".localhost")); |
| 149 | + } |
| 150 | + }, |
| 151 | + ZONE_PATH { |
| 152 | + @Override |
| 153 | + public MockHttpServletRequestBuilder createRequestBuilder(String subdomain, HttpMethod method, String pathSuffix) { |
| 154 | + return requestBuilderForMethod(method, "/z/{subdomain}" + pathSuffix, subdomain); |
| 155 | + } |
| 156 | + }; |
| 157 | + |
| 158 | + public abstract MockHttpServletRequestBuilder createRequestBuilder(String subdomain, HttpMethod method, String pathSuffix); |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Builds a MockHttpServletRequestBuilder for the given HTTP method and path. |
| 163 | + * |
| 164 | + * @param method the HTTP method (GET, POST, PUT, DELETE) |
| 165 | + * @param path the path (may contain path variables like {@code /z/{subdomain}/oauth/token}) |
| 166 | + * @param pathVars optional path variable values |
| 167 | + * @return the request builder |
| 168 | + */ |
| 169 | + public static MockHttpServletRequestBuilder requestBuilderForMethod(HttpMethod method, String path, Object... pathVars) { |
| 170 | + if (method == HttpMethod.GET) { |
| 171 | + return get(path, pathVars); |
| 172 | + } |
| 173 | + if (method == HttpMethod.POST) { |
| 174 | + return post(path, pathVars); |
| 175 | + } |
| 176 | + if (method == HttpMethod.PUT) { |
| 177 | + return put(path, pathVars); |
| 178 | + } |
| 179 | + if (method == HttpMethod.DELETE) { |
| 180 | + return delete(path, pathVars); |
| 181 | + } |
| 182 | + throw new IllegalArgumentException("Unsupported method: " + method); |
| 183 | + } |
| 184 | + |
137 | 185 | private static final String SIMPLESAMLPHP_UAA_ACCEPTANCE = "http://simplesamlphp.uaa-acceptance.cf-app.com"; |
138 | 186 |
|
139 | 187 | public static final String IDP_META_DATA = |
|
0 commit comments