From 77077b7b3b33b117384c7bcaf73d839777ae638c Mon Sep 17 00:00:00 2001
From: davidely <davidely@localhost>
Date: Thu, 03 May 2007 20:13:58 +0000
Subject: [PATCH] This is a checkin for Issue #311 "CRYPT Storage Scheme Support". This code was contributed externally by java.net user bdamm.
---
opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java | 67 +++++++++++++++++++++++++++++++++
1 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index 6c13eb8..8d6a286 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -45,6 +45,7 @@
import java.net.ServerSocket;
import java.net.InetSocketAddress;
import java.net.SocketException;
+import java.net.Socket;
import org.opends.server.backends.MemoryBackend;
import org.opends.server.backends.jeb.BackendImpl;
@@ -61,6 +62,12 @@
import org.opends.server.loggers.debug.DebugLogger;
import org.opends.server.plugins.InvocationCounterPlugin;
import org.opends.server.protocols.internal.InternalClientConnection;
+import org.opends.server.protocols.asn1.ASN1Reader;
+import org.opends.server.protocols.asn1.ASN1Writer;
+import org.opends.server.protocols.asn1.ASN1OctetString;
+import org.opends.server.protocols.ldap.BindRequestProtocolOp;
+import org.opends.server.protocols.ldap.LDAPMessage;
+import org.opends.server.protocols.ldap.BindResponseProtocolOp;
import org.opends.server.tools.LDAPModify;
import org.opends.server.types.DN;
import org.opends.server.types.FilePermission;
@@ -75,6 +82,7 @@
import org.opends.server.util.ModifyDNChangeRecordEntry;
import static org.testng.Assert.*;
+import static org.testng.Assert.assertEquals;
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
@@ -787,6 +795,40 @@
+ public static boolean canBind(String dn, String pw) throws Exception
+ {
+ // Check that the user can bind.
+ Socket s = null;
+ try {
+ s = new Socket("127.0.0.1", TestCaseUtils.getServerLdapPort());
+ ASN1Reader r = new ASN1Reader(s);
+ ASN1Writer w = new ASN1Writer(s);
+ r.setIOTimeout(3000);
+
+ BindRequestProtocolOp bindRequest =
+ new BindRequestProtocolOp(
+ new ASN1OctetString(dn),
+ 3,
+ new ASN1OctetString(pw));
+ LDAPMessage message = new LDAPMessage(1, bindRequest);
+ w.writeElement(message.encode());
+
+ message = LDAPMessage.decode(r.readElement().decodeAsSequence());
+ BindResponseProtocolOp bindResponse = message.getBindResponseProtocolOp();
+ if (bindResponse.getResultCode() == 0) {
+ return true;
+ }
+ } catch (Exception t) {
+ t.printStackTrace();
+ } finally {
+ if (s != null) {
+ s.close();
+ }
+ }
+ return false;
+ }
+
+
/**
* Adds the provided entry to the Directory Server using an internal
* operation.
@@ -889,6 +931,8 @@
+
+
/**
* Creates a temporary text file with the specified contents. It will be
* marked for automatic deletion when the JVM exits.
@@ -1044,6 +1088,29 @@
return new String(bytes);
}
+ /**
+ * Returns the contents of file as a List of the lines as defined by
+ * java.io.BufferedReader#readLine() (i.e. the line terminator is not
+ * included). An ArrayList is explicitly returned, so that callers know that
+ * random access is not expensive.
+ */
+ public static ArrayList<String> readFileToLines(File file)
+ throws IOException {
+ BufferedReader reader =
+ new BufferedReader(
+ new InputStreamReader(
+ new DataInputStream(
+ new FileInputStream(file))));
+
+ ArrayList<String> lines = new ArrayList<String>();
+ String line;
+ while ((line = reader.readLine()) != null) {
+ lines.add(line);
+ }
+
+ return lines;
+ }
+
/**
* Read the contents of a file and return it as a String.
--
Gitblit v1.10.0