|
23 | 23 | import com.alibaba.nacos.common.http.client.NacosRestTemplate; |
24 | 24 | import com.alibaba.nacos.common.http.param.Header; |
25 | 25 | import com.alibaba.nacos.common.http.param.Query; |
| 26 | +import com.alibaba.nacos.common.tls.TlsSystemConfig; |
26 | 27 | import com.alibaba.nacos.common.utils.JacksonUtils; |
27 | 28 | import com.alibaba.nacos.plugin.auth.api.LoginIdentityContext; |
28 | 29 | import org.junit.jupiter.api.BeforeEach; |
|
39 | 40 | import static org.junit.jupiter.api.Assertions.assertNull; |
40 | 41 | import static org.mockito.ArgumentMatchers.any; |
41 | 42 | import static org.mockito.ArgumentMatchers.anyMap; |
| 43 | +import static org.mockito.ArgumentMatchers.anyString; |
42 | 44 | import static org.mockito.ArgumentMatchers.eq; |
| 45 | +import static org.mockito.Mockito.verify; |
43 | 46 | import static org.mockito.Mockito.when; |
44 | 47 |
|
45 | 48 | @ExtendWith(MockitoExtension.class) |
@@ -96,6 +99,27 @@ void testGetResponseException() throws Exception { |
96 | 99 | assertNull(loginProcessor.getResponse(properties)); |
97 | 100 | } |
98 | 101 |
|
| 102 | + @Test |
| 103 | + void testGetResponseUsesHttpsWhenTlsEnabled() throws Exception { |
| 104 | + String previousTlsEnable = System.getProperty(TlsSystemConfig.TLS_ENABLE); |
| 105 | + System.setProperty(TlsSystemConfig.TLS_ENABLE, "true"); |
| 106 | + try { |
| 107 | + properties.setProperty(NacosAuthLoginConstant.SERVER, "localhost"); |
| 108 | + when(restTemplate.postForm(anyString(), |
| 109 | + eq(Header.EMPTY), |
| 110 | + any(Query.class), anyMap(), eq(String.class))).thenReturn(result); |
| 111 | + assertNull(loginProcessor.getResponse(properties)); |
| 112 | + verify(restTemplate).postForm(eq("https://localhost:8848/nacos/v3/auth/user/login"), |
| 113 | + eq(Header.EMPTY), any(Query.class), anyMap(), eq(String.class)); |
| 114 | + } finally { |
| 115 | + if (previousTlsEnable == null) { |
| 116 | + System.clearProperty(TlsSystemConfig.TLS_ENABLE); |
| 117 | + } else { |
| 118 | + System.setProperty(TlsSystemConfig.TLS_ENABLE, previousTlsEnable); |
| 119 | + } |
| 120 | + } |
| 121 | + } |
| 122 | + |
99 | 123 | @Test |
100 | 124 | void testGetResponseSuccessFromV1() throws Exception { |
101 | 125 | properties.setProperty(NacosAuthLoginConstant.SERVER, "localhost"); |
|
0 commit comments