|
| 1 | +/* |
| 2 | + * Copyright 2012-2025 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 | + |
| 17 | +package org.springframework.boot.test.autoconfigure.web.servlet.mockmvc; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
| 22 | +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; |
| 23 | +import org.springframework.security.test.context.support.WithAnonymousUser; |
| 24 | +import org.springframework.test.web.servlet.MockMvc; |
| 25 | + |
| 26 | +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; |
| 27 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrlPattern; |
| 28 | +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
| 29 | + |
| 30 | +/** |
| 31 | + * Tests for {@link WebMvcTest @WebMvcTest} with SAML2. |
| 32 | + * |
| 33 | + * @author Dmytro Nosan |
| 34 | + */ |
| 35 | +@WebMvcTest(controllers = ExampleController1.class, properties = { |
| 36 | + "spring.security.saml2.relyingparty.registration.test.entity-id=relyingparty", |
| 37 | + "spring.security.saml2.relyingparty.registration.test.assertingparty.entity-id=assertingparty", |
| 38 | + "spring.security.saml2.relyingparty.registration.test.assertingparty.singlesignon.url=https://example.com", |
| 39 | + "spring.security.saml2.relyingparty.registration.test.assertingparty.singlesignon.sign-request=false" }) |
| 40 | +class WebMvcTestSaml2Tests { |
| 41 | + |
| 42 | + @Autowired |
| 43 | + private MockMvc mockMvc; |
| 44 | + |
| 45 | + @Test |
| 46 | + @WithAnonymousUser |
| 47 | + void loginShouldBeAuthorized() throws Exception { |
| 48 | + this.mockMvc.perform(get("/one")) |
| 49 | + .andExpect(status().isFound()) |
| 50 | + .andExpect(redirectedUrlPattern("**/saml2/authenticate?registrationId=test")); |
| 51 | + } |
| 52 | + |
| 53 | +} |
0 commit comments