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

SUBMARINE-551. Add a test of user identity verification #337

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,39 @@ 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.info("fail");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete LOG.info(fail)
Because there is already have LOG.error(e.getMessage(), e);

LOG.error(e.getMessage(), e);
}
catch (javax.naming.CommunicationException e) {
LOG.info("Connection fail");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete LOG.info("Connection fail");
Because there is already have LOG.error(e.getMessage(), e);

LOG.error(e.getMessage(), e);
}
catch (Exception e) {
LOG.info("Unknown identity verification fail");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete LOG.info("Unknown identity verification fail");
Because there is already have LOG.error(e.getMessage(), e);

LOG.error(e.getMessage(), e);
}
}

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