[spring-extensions] branch main updated: IDP-1806 Warn on Resource names ending with a space
Rod Widdowson
rdw at steadingsoftware.com
Mon May 3 13:25:33 UTC 2021
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository spring-extensions.
View the commit online:
http://git.shibboleth.net/view/?p=spring-extensions.git;a=commit;h=d68738f1ff469137c2ec27d93a20741307f10887
The following commit(s) were added to refs/heads/main by this push:
new d68738f IDP-1806 Warn on Resource names ending with a space
d68738f is described below
commit d68738f1ff469137c2ec27d93a20741307f10887
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon May 3 14:24:30 2021 +0100
IDP-1806 Warn on Resource names ending with a space
https://issues.shibboleth.net/jira/browse/IDP-1806
---
.../spring/config/StringToResourceConverter.java | 15 ++++-
.../ext/spring/config/StringToResourceTest.java | 65 ++++++++++++++++++++++
2 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/src/main/java/net/shibboleth/ext/spring/config/StringToResourceConverter.java b/src/main/java/net/shibboleth/ext/spring/config/StringToResourceConverter.java
index 1726205..8cc7b1f 100644
--- a/src/main/java/net/shibboleth/ext/spring/config/StringToResourceConverter.java
+++ b/src/main/java/net/shibboleth/ext/spring/config/StringToResourceConverter.java
@@ -17,12 +17,15 @@
package net.shibboleth.ext.spring.config;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.shibboleth.ext.spring.resource.PreferFileSystemResourceLoader;
import net.shibboleth.ext.spring.resource.ResourceHelper;
import net.shibboleth.utilities.java.support.resource.Resource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.convert.converter.Converter;
@@ -38,11 +41,21 @@ public class StringToResourceConverter implements Converter<String, Resource>, A
/** Application context. */
@Nullable private ApplicationContext applicationContext;
+ /** Log. */
+ @Nonnull private final Logger log = LoggerFactory.getLogger(StringToResourceConverter.class);
+
/** {@inheritDoc} */
public Resource convert(final String source) {
final ResourceLoader loader =
applicationContext == null ? new PreferFileSystemResourceLoader() : applicationContext;
- return ResourceHelper.of(loader.getResource(source));
+ if (source.endsWith(" ")) {
+ log.warn("Path '{}' ends with a space", source);
+ }
+ final Resource result = ResourceHelper.of(loader.getResource(source));
+ if (log.isDebugEnabled() && !result.exists()) {
+ log.debug("Resource at '{}' does not exist", source);
+ }
+ return result;
}
/** {@inheritDoc} */
diff --git a/src/test/java/net/shibboleth/ext/spring/config/StringToResourceTest.java b/src/test/java/net/shibboleth/ext/spring/config/StringToResourceTest.java
new file mode 100644
index 0000000..0ef23e2
--- /dev/null
+++ b/src/test/java/net/shibboleth/ext/spring/config/StringToResourceTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.ext.spring.config;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.InvalidPathException;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import net.shibboleth.utilities.java.support.resource.Resource;
+
+ at SuppressWarnings("javadoc")
+public class StringToResourceTest {
+
+ private final StringToResourceConverter converter = new StringToResourceConverter();
+
+ private String path;
+
+ @BeforeClass public void setup() throws IOException {
+ final File file = File.createTempFile("TEST", "convert");
+ file.createNewFile();
+ file.deleteOnExit();
+ assertTrue(file.exists());
+ path = file.getAbsolutePath();
+ }
+
+ @Test public void exists() {
+ final Resource r = converter.convert(path);
+ assertTrue(r.exists());
+ }
+
+ @Test public void notExist() {
+ final Resource r = converter.convert(path + "x");
+ assertFalse(r.exists());
+ }
+
+ @Test public void endsWithSpace() {
+ try {
+ final Resource r = converter.convert(path + " ");
+ assertFalse(r.exists()); // Linux
+ } catch (final InvalidPathException e) {
+ // expected on Windows
+ }
+ }
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list