JAVA-20555 use Java Base64 instead of deprecated Spring Base64Utils (#13941)

This commit is contained in:
Kasra Madadipouya
2023-05-05 12:58:11 +03:00
committed by GitHub
parent 2e41874a5c
commit 7e404b3dfb
6 changed files with 24 additions and 19 deletions
@@ -11,13 +11,14 @@ import org.springframework.security.web.FilterChainProxy;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.Base64Utils;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.util.Base64;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = AuthResolverApplication.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -44,7 +45,7 @@ public class AuthResolverIntegrationTest {
this.mockMvc
.perform(get("/customer/welcome")
.header(
"Authorization", String.format("Basic %s", Base64Utils.encodeToString("customer1:pass1".getBytes()))
"Authorization", String.format("Basic %s", Base64.getEncoder().encodeToString("customer1:pass1".getBytes()))
)
)
.andExpect(status().is2xxSuccessful());
@@ -55,7 +56,7 @@ public class AuthResolverIntegrationTest {
this.mockMvc
.perform(get("/customer/welcome")
.header(
"Authorization", "Basic " + Base64Utils.encodeToString("employee1:pass1".getBytes()))
"Authorization", "Basic " + Base64.getEncoder().encodeToString("employee1:pass1".getBytes()))
)
.andExpect(status().isUnauthorized());
}
@@ -65,7 +66,7 @@ public class AuthResolverIntegrationTest {
this.mockMvc
.perform(get("/employee/welcome")
.header(
"Authorization", "Basic " + Base64Utils.encodeToString("employee1:pass1".getBytes()))
"Authorization", "Basic " + Base64.getEncoder().encodeToString("employee1:pass1".getBytes()))
)
.andExpect(status().is2xxSuccessful());
}
@@ -75,7 +76,7 @@ public class AuthResolverIntegrationTest {
this.mockMvc
.perform(get("/employee/welcome")
.header(
"Authorization", "Basic " + Base64Utils.encodeToString("customer1:pass1".getBytes()))
"Authorization", "Basic " + Base64.getEncoder().encodeToString("customer1:pass1".getBytes()))
)
.andExpect(status().isUnauthorized());
}