Skip to content
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.

Commit

Permalink
SUBMARINE-551. Add a test of user identity verification
Browse files Browse the repository at this point in the history
### What is this PR for?
To test the LDAP for user verification.
The user in this open LDAP server can be verified successfully.

### What type of PR is it?
Improvement

### Todos
* [ ] - Task

### What is the Jira issue?
https://issues.apache.org/jira/browse/SUBMARINE-551

### How should this be tested?
* First time? Setup Travis CI as described on https://submarine.apache.org/contribution/contributions.html#continuous-integration
* Strongly recommended: add automated unit tests for any new or changed behavior
* Outline any manual steps to test the PR here.
https://travis-ci.org/github/Eroschang/submarine/builds/703852786

### Screenshots (if appropriate)
![image](https://user-images.githubusercontent.com/43379142/86231254-d92fe400-bbc4-11ea-8000-ed12af7a2f3e.png)

### Questions:
* Does the licenses files need update? /No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Eroschang <sanchang274@gmail.com>

Closes #337 from Eroschang/SUBMARINE-551 and squashes the following commits:

ff78c95 [Eroschang] Add a test of user identity verification.
cbb9d28 [Eroschang] Add a test of user identity verification.
0fca95a [Eroschang] Add a test of user identity verification.
  • Loading branch information
Eroschang authored and xunliu committed Jul 4, 2020
1 parent 919d8c0 commit b85d409
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@
import org.zapodot.junit.ldap.EmbeddedLdapRule;
import org.zapodot.junit.ldap.EmbeddedLdapRuleBuilder;

import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.NameClassPair;
import javax.naming.NamingEnumeration;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.StringTokenizer;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -133,6 +136,36 @@ public void testList() throws Exception {
context.close();
}

@Test
public void testauth() throws Exception {
DirContext ctx = null;
Hashtable<String, String> HashEnv = new Hashtable<String, String>();

String loginId = "uid=curie,dc=example,dc=com";
String password = "password";

HashEnv.put(Context.SECURITY_AUTHENTICATION, "simple");
HashEnv.put(Context.SECURITY_PRINCIPAL, loginId);
HashEnv.put(Context.SECURITY_CREDENTIALS, password);
HashEnv.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
HashEnv.put("com.sun.jndi.ldap.connect.timeout", "3000");
HashEnv.put(Context.PROVIDER_URL, "ldap://ldap.forumsys.com:389");

try {
ctx = new InitialDirContext(HashEnv);
LOG.info("Pass");
}
catch (AuthenticationException e) {
LOG.error(e.getMessage(), e);
}
catch (javax.naming.CommunicationException e) {
LOG.error(e.getMessage(), e);
}
catch (Exception e) {
LOG.error(e.getMessage(), e);
}
}

@Test
public void testContextClose() throws Exception {
final Context context = embeddedLdapRule.context();
Expand Down

0 comments on commit b85d409

Please sign in to comment.