-
Notifications
You must be signed in to change notification settings - Fork 6k
Throw exception when specified ldif file does not exist #8434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…nding of the task
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @dratler!This is a great starting point.
I have left some comments inline.
I suggest adding the test to the UnboundIdContainerTests
file, rather than creating a new one.
ldap/src/integration-test/java/org/springframework/security/ldap/SpringLdapFalseAuthTest.java
Outdated
Show resolved
Hide resolved
ldap/src/integration-test/java/org/springframework/security/ldap/SpringLdapFalseAuthTest.java
Outdated
Show resolved
Hide resolved
ldap/src/integration-test/java/org/springframework/security/ldap/SpringLdapFalseAuthTest.java
Outdated
Show resolved
Hide resolved
try { | ||
new InMemoryDirectoryServer("dc=springframework,dc=org", | ||
"classpath:missing-file.ldif"); | ||
} catch (LDAPException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An IllegalArgumentException
is more suitable in this case.
LDAPException
should only be used when a problem occurs while performing LDAP-related processing.
In this case, we haven't started the LDAP-related processing yet, so we should use IllegalArgumentException
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The InMemoryDirectoryServer
throw LDAPException
I can wrap it but I think it's not a good practice.
public InMemoryDirectoryServer(final String... baseDNs) throws LDAPException
1. move the tests into UnboundIdContainerTests 2. Starting phase one of the commit
Hi @eleftherias , |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @dratler.
I have left feedback inline.
ldap/src/integration-test/java/org/springframework/security/ldap/SpringLdapFalseAuthTest.java
Outdated
Show resolved
Hide resolved
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
…ndIdContainerTests and to UnboundIdContainerLdifTests classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @dratler!
I have requested some changes inline.
if (!StringUtils.hasText(ldif)) { | ||
throw new IllegalArgumentException("Unable to load LDIF " + ldif); | ||
} | ||
if (!ldif.endsWith(".ldif")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this check. We do not require the file to have a ".ldif" extension to be processed.
@@ -67,7 +76,9 @@ public void setPort(int port) { | |||
|
|||
@Override | |||
public void destroy() { | |||
stop(); | |||
if (null != directoryServer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep this commit focused on throwing an exception with the LDIF file does not exist.
This doesn't seem like it is part of that.
if (resources.length > 0 | ||
&& resources[0].exists() | ||
&& resources[0].isFile() | ||
&& resources[0].isReadable()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With these changes, there is still no exception thrown when the file does not exist.
We need to check if the LDIF exists and throw an exception if it does not.
We can add the check for isFile()
and isReadable()
after we verify it exists.
if (resources.length > 0 | |
&& resources[0].exists() | |
&& resources[0].isFile() | |
&& resources[0].isReadable()) { | |
if (resources.length > 0) { | |
if (!resources[0].exists()) { | |
throw new IllegalArgumentException("Could not find LDIF " + this.ldif); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
.../integration-test/java/org/springframework/security/ldap/server/UnboundIdContainerTests.java
Show resolved
Hide resolved
server.destroy(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test for the original issue.
The test should create an UnboundIdContainer
with an LDIF that does not exist, and ensure that an exception is thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @dratler.
I have left some more comments inline.
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
.../integration-test/java/org/springframework/security/ldap/server/UnboundIdContainerTests.java
Show resolved
Hide resolved
.../integration-test/java/org/springframework/security/ldap/server/UnboundIdContainerTests.java
Outdated
Show resolved
Hide resolved
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
Hi @eleftherias , |
@dratler It looks like the tests are still failing. Were you able to run the build on your local machine? |
Hi @eleftherias , |
Thanks @dratler. You can also check out the Travis build that ran for this PR https://travis-ci.org/github/spring-projects/spring-security/builds/691902029 |
Hi @eleftherias , |
Thanks for reaching out @dratler. The updated code To mitigate this, we do not need to get all resources, just the LDIFs that the user has specified with their pattern.
Then, if the resource they are asking for does not exist, we should throw an exception.
Let me know if this is unclear or if you have any questions. |
Hi @eleftherias , |
Hi @eleftherias , |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates @dratler.
I have left some more feedback inline.
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Show resolved
Hide resolved
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
ldap/src/integration-test/resources/applicationContext-security.xml
Outdated
Show resolved
Hide resolved
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
ldap/src/main/java/org/springframework/security/ldap/server/UnboundIdContainer.java
Outdated
Show resolved
Hide resolved
Hi @eleftherias , |
Hi @eleftherias
Thanks for all the aid here is a PR I have opened with tests that I understand is missing and once they will throw exceptions this PR will be completed.