|
16 | 16 |
|
17 | 17 | package org.springframework.security.config.authentication;
|
18 | 18 |
|
| 19 | +import org.assertj.core.api.Assertions; |
19 | 20 | import org.junit.jupiter.api.AfterEach;
|
20 | 21 | import org.junit.jupiter.api.Test;
|
21 | 22 | import org.w3c.dom.Element;
|
22 | 23 |
|
| 24 | +import org.springframework.beans.factory.BeanDefinitionStoreException; |
23 | 25 | import org.springframework.security.authentication.AuthenticationManager;
|
24 | 26 | import org.springframework.security.authentication.CachingUserDetailsService;
|
25 | 27 | import org.springframework.security.authentication.ProviderManager;
|
@@ -160,6 +162,44 @@ public void rolePrefixIsUsedWhenSet() {
|
160 | 162 | assertThat(AuthorityUtils.authorityListToSet(rod.getAuthorities())).contains("PREFIX_ROLE_SUPERVISOR");
|
161 | 163 | }
|
162 | 164 |
|
| 165 | + @Test |
| 166 | + public void testEmptyDataSourceRef() { |
| 167 | + // @formatter:off |
| 168 | + String xml = "<authentication-manager>" |
| 169 | + + " <authentication-provider>" |
| 170 | + + " <jdbc-user-service data-source-ref=''/>" |
| 171 | + + " </authentication-provider>" |
| 172 | + + "</authentication-manager>"; |
| 173 | + // @formatter:on |
| 174 | + |
| 175 | + try { |
| 176 | + setContext(xml); |
| 177 | + Assertions.fail("Expected exception due to empty data-source-ref"); |
| 178 | + } |
| 179 | + catch (BeanDefinitionStoreException ex) { |
| 180 | + assertThat(ex.getMessage()).contains("data-source-ref is required"); |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + @Test |
| 185 | + public void testMissingDataSourceRef() { |
| 186 | + // @formatter:off |
| 187 | + String xml = "<authentication-manager>" |
| 188 | + + " <authentication-provider>" |
| 189 | + + " <jdbc-user-service/>" |
| 190 | + + " </authentication-provider>" |
| 191 | + + "</authentication-manager>"; |
| 192 | + // @formatter:on |
| 193 | + |
| 194 | + try { |
| 195 | + setContext(xml); |
| 196 | + Assertions.fail("Expected exception due to missing data-source-ref"); |
| 197 | + } |
| 198 | + catch (BeanDefinitionStoreException ex) { |
| 199 | + assertThat(ex.getMessage()).contains("XML document from").contains("is invalid"); |
| 200 | + } |
| 201 | + } |
| 202 | + |
163 | 203 | private void setContext(String context) {
|
164 | 204 | this.appContext = new InMemoryXmlApplicationContext(context);
|
165 | 205 | }
|
|
0 commit comments