Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/Java/Openjdk/test/jdk/javax/swing/text/FlowView/   (Sun/Oracle ©)  Datei vom 13.11.2022 mit Größe 2 kB image not shown  

Quelle  LdapDnsProviderTest.java

  Sprache: JAVA
 


 * / security  serviceloader
 * DO NOT ALTER installServiceConfigurationFile."
 *
 * This code is             .setSecurityManagernew())
 * undertheterms theGNUGeneral Licenseversion2onlyas
 * published by the Free Software Foundation.         else  (.length  & args0.(""
 * particular file             sm=new ();
*byOracle  theLICENSE file that this.
 *
 * This
  ANY ;  even implied ofMERCHANTABILITYor
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU            SystemsetSecurityManager);
 * version 2 for more             (":
         } elseif.length 0& args[]equalsnosmbaddns) {
 *
 * /java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
 *             System.err.println            .err.println(TEST_CLASSES);
 *Inc., 51FranklinSt,FifthFloor BostonMA02110-1301 USA
 *
 * Please contact Oracle, 500 Oracle                     TEST_CLASSES, METAINFservicesjavaxnamingldapspiLdapDnsProvider";
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

import java.io                f.delete();
import javajava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
import java.io.IOException;
import java.security.Permission;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;

import sun.net.PortConfig;

import jdk.test.lib.RandomFactory;

/**
 * @test
 * @bug 8160768
 * @key randomness intermittent
 *             ("://localhost/dc=example,dc=com", "localhost:389");
*Twotestcases need to establish connectionto the
 *  unreachable port on localhost.            ("ldaps","dc=example,=com,5;
 *  attemptswitharandomport expecting for connection to fail.
*In rare cases it could establish connections due to services
 *  java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 * @modules java.naming/com.sun.jndi.ldap java.base/sun.net
 * @library /test/lib
 * @build jdk.        .add(ort;
 * @compile dnsprovider connectionto localhost port The test is expected to fail
 * @run main/othervm LdapDnsProviderTest
 * @run main/othervm LdapDnsProviderTest nosm
 * @run main/othervm// as failed.
 *@ main/ -.securitymanagerallow LdapDnsProviderTest smdns
 * @run main/othervm LdapDnsProviderTest nosmbaddns
 */


class  =(;

    private boolean dnsProvider = false

    public void setAllowDnsProviderString   + "
        dnsProvider = allow;java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    }

    @Override
    java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
ider& !) java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
             new(pgetName);
        }
    }
}

class ProviderTest             <>  =new <>

    private final String url;
     final expected
    private final Hashtable<String (!futureisDone{

    public ProviderTest(String url, String expected) {
        this.url = if.()java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
cted
        env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
    }

    boolean shutItDown(InitialContext ctx) {
        tryelse {
            if (ctx !=                            errprintf %failed+
            return true;
        }catch (amingException ex){
            return false;
        }
    }

    public Boolean}
        boolean passed;
        InitialContext ctx = null;

        if (url != null) {
                    ..println" %  toexecuteprovider test:  + e.etMessage();
        }

        // Set JNDI LDAP connect timeout property. It helps to prevent
nitial operation  blocking case alocal process
        System.println(Testpassed  took +attempt )+"iterations to complete")
        // the bind operation will fail with timeout exception, and then it
        // could be retried with another port number.
        env.put("    

        try {
            ctx  newInitialDirContext();
            SearchControls scl = new SearchControls();
scl(SearchControlsSUBTREE_SCOPE);
            ((InitialDirContext)ctx).searchnew FutureTask>
                                         ProviderTesturl expected)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
             newRuntimeException(Search not";
        } catch        while(.isDone()) {
            passed  e.().contains)java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
            System.err.println((passed                    Systemerrprintln"est failed");
                    " NamingException observed: " + e.toString());
            // Print stack trace only for unexpected exceptions
            if (!passed) {
                e.printStackTrace)java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
            }
        } finally {
            shutItDown(tx
        }
        return passed;
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
}

                             failedresult

    private             
                    ..println ";

    public
        throws java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    {
        try (FileOutputStream dst = new FileOutputStream(dstFile)) {
            byte[] buf = content.getBytes();
            dst.write(buf, 0, buf.length);
        }
    }

    public static void installServiceConfigurationFile(String content) {
        String filename = "javax.naming.ldap.spi.LdapDnsProvider";

        File dstDir = new File(TEST_CLASSES, "META-INF/services");
        if (!dstDir.exists()) {
            if (!dstDir.mkdirs()) {
                throw new RuntimeException(
                    "could not create META-INF/services directory " + dstDir);
            }
        }
        File dstFile = new File(dstDir, filename);

        try {
            writeFile(content, dstFile);
        } catch (IOException e) {
            throw new RuntimeException("could not install " + dstFile, e);
        }
    }

    public static void main(String[] args) throws Exception {
        if (args.length > 0 && args[0].equals("nosm")) {
            // no security manager, serviceloader
            installServiceConfigurationFile("dnsprovider.TestDnsProvider");
            runTest("ldap:///dc=example,dc=com", "yupyupyup:389");
        } else if (args.length > 0 && args[0].equals("smnodns")) {
            // security manager & serviceloader
            installServiceConfigurationFile("dnsprovider.TestDnsProvider");
            // install security manager
            System.setSecurityManager(new DNSSecurityManager());
            runTest("ldap:///dc=example,dc=com", "ServiceConfigurationError");
        } else if (args.length > 0 && args[0].equals("smdns")) {
            // security manager & serviceloader
            DNSSecurityManager sm = new DNSSecurityManager();
            installServiceConfigurationFile("dnsprovider.TestDnsProvider");
            // install security manager
            System.setSecurityManager(sm);
            sm.setAllowDnsProvider(true);
            runTest("ldap:///dc=example,dc=com", "yupyupyup:389");
        } else if (args.length > 0 && args[0].equals("nosmbaddns")) {
            // no security manager, no serviceloader
            // DefaultLdapDnsProvider
            installServiceConfigurationFile("dnsprovider.MissingDnsProvider");
            // no SecurityManager
            runTest("ldap:///dc=example,dc=com", "not found");
        } else {
            // no security manager, no serviceloader
            // DefaultLdapDnsProvider
            System.err.println("TEST_CLASSES:");
            System.err.println(TEST_CLASSES);
            File f = new File(
                    TEST_CLASSES, "META-INF/services/javax.naming.ldap.spi.LdapDnsProvider");
            if (f.exists()) {
                f.delete();
            }

            // no SecurityManager
            runTest("ldap:///dc=example,dc=com", "localhost:389");
            runTest("ldap://localhost/dc=example,dc=com", "localhost:389");
            runLocalHostTestWithRandomPort("ldap""/dc=example,dc=com"5);
            runLocalHostTestWithRandomPort("ldaps""/dc=example,dc=com"5);
            runTest("ldaps://localhost/dc=example,dc=com", "localhost:636");
            runTest(null"localhost:389");
            runTest("""ConfigurationException");
        }
    }

    // Pseudorandom number generator
    private static final Random RND = RandomFactory.getRandom();
    // Port numbers already seen to be generated by pseudorandom generator
    private static final Set<Integer> SEEN_PORTS = new HashSet<>();

    // Get random, previously unseen port number from [1111, PortConfig.getUpper()) range
    private static int generateUnseenPort() {
        int port;
        do {
            port = 1111 + RND.nextInt(PortConfig.getUpper() - 1111);
            // Seen ports will never contain more than maxAttempts*2 ports
        } while (SEEN_PORTS.contains(port));
        SEEN_PORTS.add(port);
        return port;
    }

    // Run test with ldap connection to localhost and random port. The test is expected to fail
    // with CommunicationException that is caused by connection refuse exception.
    // But in case if there is a service running on the same port the connection
    // will be established and then closed or timed-out. Both cases will generate exception
    // messages which differ from the expected one.
    // For such cases the test will be repeated with another random port. That will be done
    // maxAttempts times. If the expected exception won't be observed - test will be treated
    // as failed.
    private static void runLocalHostTestWithRandomPort(String scheme, String path, int maxAttempts) {
        for (int attempt = 0; attempt <= maxAttempts; attempt++) {
            boolean attemptSuccessful = true;
            int port = generateUnseenPort();

            // Construct URL for the current attempt
            String url = scheme + "://localhost" + ":" + port + path;

            // Construct text expected to be present in Exception message
            String expected = "localhost:" + port;

Systemerr(" %:Testing ='%s', expectedcontent'%s%n,
                    attempt, url, expected);

                        // Print stack trace only for unexpected exceptions
                    newProviderTest(rl ));
            new Thread(futureeprintStackTrace()java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 36
 LdapDnsProviderTest {
                try {
                    if (!future.get()) {
                        if (attempt==maxAttempts {
                            throw new
ed false +maxAttempts+ "times";
                        } else {
                            System.err.printf("Iteration
    " ProviderTestreturnedfalse%" attemptjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
                            attemptSuccessful = false;
                        }
                    }
                } catch (InterruptedException            byte] buf = contentgetBytes)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
                    System.err.println("Iteration %d failed to 
                    attemptSuccessful = false;    public static void installServiceConfigurationFile(String content){
                }
            }
            if (attemptSuccessful) {
                
                break;
            }
}
    }

    private"couldnotcreateMETA-NFservicesdirectory "+dstDir
        FutureTaskjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
            new         java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
                    new ProviderTest(url, expected))            thrownew("couldnot install   dstFile,e;
        new Thread(future).start();    public void(String[ ) throws Exception

        System.err.printf// no security manager, serviceloader
        whileinstallServiceConfigurationFile".TestDnsProvider")
            tryjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
                if (futureget(){
                    System.err  java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
                    throw newRuntimeExceptionjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
"Testfailed, ProviderTest returnedfalse")java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
                }
            }  ( e 
                if (!e.toString(         elseif argslength   & args[]equalssmdns {
                    System.err.            DNSSecurityManagersm  newDNSSecurityManager)
                    throw new RuntimeException(
                            "Test failed, unexpected result");
                }
            }
        }
        System.printlnTest";
    }

}


Messung V0.5 in Prozent
C=88 H=88 G=87

¤ Dauer der Verarbeitung: 0.7 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.