Skip to content

Instantly share code, notes, and snippets.

@fanf
Created August 28, 2018 12:29
Show Gist options
  • Save fanf/83f0eab664e785fd2e2449178ec582aa to your computer and use it in GitHub Desktop.
Save fanf/83f0eab664e785fd2e2449178ec582aa to your computer and use it in GitHub Desktop.
How to load Rudder LDAP entries to validate #13256
package com.normation.rudder
import com.normation.ldap.sdk.LDAPEntry
import com.normation.ldap.sdk.RWPooledSimpleAuthConnectionProvider
import com.unboundid.ldap.sdk.Attribute
import com.unboundid.ldap.sdk.DN
/*
* See:
* https://www.rudder-project.org/redmine/issues/13256
*/
object LDAP {
val con =
new RWPooledSimpleAuthConnectionProvider(
host = "localhost",
port = 1389,
authDn = "cn=Manager,cn=rudder-configuration",
authPw = "secret",
poolSize = 2
)
val dn = new DN("cn=Nodes Configuration,ou=Rudder,cn=rudder-configuration")
}
object NodesConfigurationErrorMain {
def str(size: Int) = new String( Array.fill[Char](size)('x'))
def main(args: Array[String]): Unit = {
val entry = LDAPEntry(LDAP.dn)
entry += new Attribute("objectClass", "top", "nodeConfigurations")
entry += new Attribute("cn", "Nodes Configuration")
//here, with 454, we get:
//Failure(Can not save (add) 'cn=Nodes Configuration,ou=Rudder,cn=rudder-configuration': An error occurred while attempting to send the LDAP message to server localhost:1389: SocketException(message='Socket closed', trace='socketWrite(SocketOutputStream.java:118) / write(SocketOutputStream.java:155) / write(BufferedOutputStream.java:122) / write(ByteStringBuffer.java:1664) ....
val values = for(i <- 0 until 1024) yield i + "-"+str(1024*30)
entry += new Attribute("nodeConfig", values:_*)
println(for {
ldap <- LDAP.con
_ <- ldap.delete(LDAP.dn)
_ <- ldap.save(entry)
} yield {
"done"
})
}
}
object TryGetBig {
def main(args: Array[String]): Unit = {
//System.setProperty("com.unboundid.ldap.sdk.LDAPConnectionOptions.defaultMaxMessageSizeBytes", "500")
val res = for {
ldap <- LDAP.con
_ = ldap.backed.setConnectionOptions({
val opt = ldap.backed.getConnectionOptions
opt.setMaxMessageSize(10000)
opt
})
_ <- ldap.get(LDAP.dn)
} yield {
"done"
}
println(res)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment