Skip to content

Commit efda728

Browse files
committed
Cleanup and fix tests
1 parent 8486e0b commit efda728

File tree

7 files changed

+70
-28
lines changed

7 files changed

+70
-28
lines changed

spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/test/java/org/springframework/cloud/function/adapter/azure/helper/BuilderStub.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
/*
2+
* Copyright 2023-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.cloud.function.adapter.azure.helper;
218

319
import java.util.HashMap;
420
import java.util.Map;
521

622
import com.microsoft.azure.functions.HttpResponseMessage;
7-
import com.microsoft.azure.functions.HttpStatusType;
823
import com.microsoft.azure.functions.HttpResponseMessage.Builder;
24+
import com.microsoft.azure.functions.HttpStatusType;
925

1026
public class BuilderStub implements Builder {
1127

@@ -36,4 +52,4 @@ public HttpResponseMessage build() {
3652
return new HttpResponseMessageStub(this.status, this.headers, this.body);
3753
}
3854

39-
}
55+
}

spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/test/java/org/springframework/cloud/function/adapter/azure/helper/HttpRequestMessageStub.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2023-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.cloud.function.adapter.azure.helper;
218

319
import java.net.URI;
@@ -72,5 +88,4 @@ public HttpResponseMessage.Builder createResponseBuilder(HttpStatusType status)
7288
public Builder createResponseBuilder(HttpStatus status) {
7389
return new BuilderStub().status(status);
7490
}
75-
76-
}
91+
}

spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/test/java/org/springframework/cloud/function/adapter/azure/helper/HttpResponseMessageStub.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2023-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.cloud.function.adapter.azure.helper;
218

319
import java.util.HashMap;
@@ -34,4 +50,4 @@ public Object getBody() {
3450
return this.body;
3551
}
3652

37-
}
53+
}

spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/test/java/org/springframework/cloud/function/adapter/azure/injector/AzureFunctionInstanceInjectorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.function.Function;
2121

2222
import com.microsoft.azure.functions.ExecutionContext;
23-
import com.microsoft.azure.functions.HttpMethod;
2423
import com.microsoft.azure.functions.HttpRequestMessage;
2524
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
2625
import com.microsoft.azure.functions.annotation.FunctionName;

spring-cloud-function-adapters/spring-cloud-function-adapter-azure/src/test/java/org/springframework/cloud/function/adapter/azure/injector/FunctionInstanceInjectorServiceLoadingTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Optional;
2121
import java.util.ServiceLoader;
2222
import java.util.function.Function;
23-
import java.util.logging.Logger;
2423

2524
import com.microsoft.azure.functions.ExecutionContext;
2625
import com.microsoft.azure.functions.HttpMethod;

spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/main/java/org/springframework/cloud/function/serverless/web/ProxyServletContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public ServletRegistration getServletRegistration(String servletName) {
217217

218218
@Override
219219
public Map<String, ? extends ServletRegistration> getServletRegistrations() {
220-
throw new UnsupportedOperationException("This ServletContext does not represent a running web container");
220+
return this.registrations;
221221
}
222222

223223
@Override

spring-cloud-function-adapters/spring-cloud-function-serverless-web/src/test/java/org/springframework/cloud/function/test/app/PetStoreSpringAppConfig.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,24 @@ public HandlerAdapter handlerAdapter() {
7272

7373
@Bean
7474
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
75-
http.csrf().disable() // need for POST
76-
.addFilterBefore(new GenericFilterBean() {
77-
@Override
78-
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
79-
throws IOException, ServletException {
80-
SecurityContext securityContext = SecurityContextHolder.getContext();
81-
securityContext.setAuthentication(UsernamePasswordAuthenticationToken.authenticated("user", "password",
82-
Collections.singleton(new SimpleGrantedAuthority("USER"))));
83-
HttpSession session = ((HttpServletRequest) request).getSession();
84-
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
85-
chain.doFilter(request, response);
86-
}
87-
}, SecurityContextHolderFilter.class)
88-
.authorizeHttpRequests((requests) -> requests
89-
.requestMatchers("/", "/pets", "/pets/").hasAnyAuthority("USER")
90-
.requestMatchers("/foo").hasAnyAuthority("FOO")
91-
.anyRequest().authenticated()
75+
http
76+
.addFilterBefore(new GenericFilterBean() {
77+
@Override
78+
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
79+
throws IOException, ServletException {
80+
SecurityContext securityContext = SecurityContextHolder.getContext();
81+
securityContext.setAuthentication(UsernamePasswordAuthenticationToken.authenticated("user", "password",
82+
Collections.singleton(new SimpleGrantedAuthority("USER"))));
83+
HttpSession session = ((HttpServletRequest) request).getSession();
84+
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
85+
chain.doFilter(request, response);
86+
}
87+
}, SecurityContextHolderFilter.class)
88+
.securityMatcher("/foo")
89+
.authorizeHttpRequests(authorize -> authorize
90+
.anyRequest().hasRole("FOO")
9291
)
93-
.exceptionHandling().accessDeniedHandler(accessDeniedHandler()).and()
94-
.logout((logout) -> logout.permitAll());
95-
92+
.exceptionHandling(f -> f.accessDeniedHandler(accessDeniedHandler()));
9693
return http.build();
9794
}
9895

0 commit comments

Comments
 (0)