|
16 | 16 |
|
17 | 17 | package org.springframework.security.web.server.authentication;
|
18 | 18 |
|
| 19 | +import java.nio.charset.StandardCharsets; |
| 20 | + |
19 | 21 | import org.junit.jupiter.api.Test;
|
20 | 22 | import reactor.core.publisher.Mono;
|
21 | 23 |
|
@@ -62,7 +64,7 @@ public void applyWhenNotBase64ThenEmpty() {
|
62 | 64 | }
|
63 | 65 |
|
64 | 66 | @Test
|
65 |
| - public void applyWhenNoSemicolonThenEmpty() { |
| 67 | + public void applyWhenNoColonThenEmpty() { |
66 | 68 | Mono<Authentication> result = apply(this.request.header(HttpHeaders.AUTHORIZATION, "Basic dXNlcg=="));
|
67 | 69 | assertThat(result.block()).isNull();
|
68 | 70 | }
|
@@ -104,6 +106,38 @@ public void applyWhenWrongSchemeThenEmpty() {
|
104 | 106 | assertThat(result.block()).isNull();
|
105 | 107 | }
|
106 | 108 |
|
| 109 | + @Test |
| 110 | + public void applyWhenNonAsciiThenAuthentication() { |
| 111 | + Mono<Authentication> result = apply( |
| 112 | + this.request.header(HttpHeaders.AUTHORIZATION, "Basic w7xzZXI6cGFzc3fDtnJk")); |
| 113 | + UsernamePasswordAuthenticationToken authentication = result.cast(UsernamePasswordAuthenticationToken.class) |
| 114 | + .block(); |
| 115 | + assertThat(authentication.getPrincipal()).isEqualTo("üser"); |
| 116 | + assertThat(authentication.getCredentials()).isEqualTo("passwörd"); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + public void applyWhenIsoOnlyAsciiThenAuthentication() { |
| 121 | + this.converter.setCredentialsCharset(StandardCharsets.ISO_8859_1); |
| 122 | + Mono<Authentication> result = apply( |
| 123 | + this.request.header(HttpHeaders.AUTHORIZATION, "Basic dXNlcjpwYXNzd29yZA==")); |
| 124 | + UsernamePasswordAuthenticationToken authentication = result.cast(UsernamePasswordAuthenticationToken.class) |
| 125 | + .block(); |
| 126 | + assertThat(authentication.getPrincipal()).isEqualTo("user"); |
| 127 | + assertThat(authentication.getCredentials()).isEqualTo("password"); |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + public void applyWhenIsoNonAsciiThenAuthentication() { |
| 132 | + this.converter.setCredentialsCharset(StandardCharsets.ISO_8859_1); |
| 133 | + Mono<Authentication> result = apply( |
| 134 | + this.request.header(HttpHeaders.AUTHORIZATION, "Basic /HNlcjpwYXNzd/ZyZA==")); |
| 135 | + UsernamePasswordAuthenticationToken authentication = result.cast(UsernamePasswordAuthenticationToken.class) |
| 136 | + .block(); |
| 137 | + assertThat(authentication.getPrincipal()).isEqualTo("üser"); |
| 138 | + assertThat(authentication.getCredentials()).isEqualTo("passwörd"); |
| 139 | + } |
| 140 | + |
107 | 141 | private Mono<Authentication> apply(MockServerHttpRequest.BaseBuilder<?> request) {
|
108 | 142 | return this.converter.convert(MockServerWebExchange.from(this.request.build()));
|
109 | 143 | }
|
|
0 commit comments