Polish "Add Basic Authorization for UrlResource"
See gh-1822
This commit is contained in:
@@ -33,6 +33,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import okhttp3.mockwebserver.Dispatcher;
|
||||
@@ -377,6 +378,19 @@ class ResourceTests {
|
||||
assertThat(request.getHeader("Framework-Name")).isEqualTo("Spring");
|
||||
}
|
||||
|
||||
@Test
|
||||
void useUserInfoToSetBasicAuth() throws Exception {
|
||||
startServer();
|
||||
UrlResource resource = new UrlResource("http://alice:secret@localhost:"
|
||||
+ this.server.getPort() + "/resource");
|
||||
assertThat(resource.getInputStream()).hasContent("Spring");
|
||||
RecordedRequest request = this.server.takeRequest();
|
||||
String authorization = request.getHeader("Authorization");
|
||||
assertThat(authorization).isNotNull().startsWith("Basic ");
|
||||
assertThat(new String(Base64.getDecoder().decode(
|
||||
authorization.substring(6)), StandardCharsets.ISO_8859_1)).isEqualTo("alice:secret");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void shutdown() throws Exception {
|
||||
this.server.shutdown();
|
||||
|
||||
Reference in New Issue
Block a user