|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2022 the original author or authors. |
| 2 | + * Copyright 2002-2024 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
19 | 19 | import org.junit.jupiter.api.AfterEach;
|
20 | 20 | import org.junit.jupiter.api.Test;
|
21 | 21 | import org.w3c.dom.Element;
|
| 22 | +import org.xml.sax.SAXParseException; |
22 | 23 |
|
| 24 | +import org.springframework.beans.factory.parsing.BeanDefinitionParsingException; |
| 25 | +import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; |
23 | 26 | import org.springframework.security.authentication.AuthenticationManager;
|
24 | 27 | import org.springframework.security.authentication.CachingUserDetailsService;
|
25 | 28 | import org.springframework.security.authentication.ProviderManager;
|
|
33 | 36 | import org.springframework.security.util.FieldUtils;
|
34 | 37 |
|
35 | 38 | import static org.assertj.core.api.Assertions.assertThat;
|
| 39 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
36 | 40 | import static org.mockito.Mockito.mock;
|
37 | 41 |
|
38 | 42 | /**
|
@@ -160,6 +164,38 @@ public void rolePrefixIsUsedWhenSet() {
|
160 | 164 | assertThat(AuthorityUtils.authorityListToSet(rod.getAuthorities())).contains("PREFIX_ROLE_SUPERVISOR");
|
161 | 165 | }
|
162 | 166 |
|
| 167 | + @Test |
| 168 | + public void testEmptyDataSourceRef() { |
| 169 | + // @formatter:off |
| 170 | + String xml = "<authentication-manager>" |
| 171 | + + " <authentication-provider>" |
| 172 | + + " <jdbc-user-service data-source-ref=''/>" |
| 173 | + + " </authentication-provider>" |
| 174 | + + "</authentication-manager>"; |
| 175 | + assertThatExceptionOfType(BeanDefinitionParsingException.class) |
| 176 | + .isThrownBy(() -> setContext(xml)) |
| 177 | + .withFailMessage("Expected exception due to empty data-source-ref") |
| 178 | + .withMessageContaining("data-source-ref is required for jdbc-user-service"); |
| 179 | + // @formatter:on |
| 180 | + } |
| 181 | + |
| 182 | + @Test |
| 183 | + public void testMissingDataSourceRef() { |
| 184 | + // @formatter:off |
| 185 | + String xml = "<authentication-manager>" |
| 186 | + + " <authentication-provider>" |
| 187 | + + " <jdbc-user-service/>" |
| 188 | + + " </authentication-provider>" |
| 189 | + + "</authentication-manager>"; |
| 190 | + assertThatExceptionOfType(XmlBeanDefinitionStoreException.class) |
| 191 | + .isThrownBy(() -> setContext(xml)) |
| 192 | + .withFailMessage("Expected exception due to missing data-source-ref") |
| 193 | + .havingRootCause() |
| 194 | + .isInstanceOf(SAXParseException.class) |
| 195 | + .withMessageContaining("Attribute 'data-source-ref' must appear on element 'jdbc-user-service'"); |
| 196 | + // @formatter:on |
| 197 | + } |
| 198 | + |
163 | 199 | private void setContext(String context) {
|
164 | 200 | this.appContext = new InMemoryXmlApplicationContext(context);
|
165 | 201 | }
|
|
0 commit comments